Fork of daniellemaywood.uk/gleam — Wasm codegen work
Something went wrong. Try again.
3.6 kB · 286 lines
Rust
at wasm
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: 2025 The Gleam contributors
use crate::assert_source_map;
#[test]fn sourcemap_function_definition() { assert_source_map!( "/// my add functionpub fn add_2(x) { x + 2}" )}
#[test]fn sourcemap_function_definitions_with_unused() { assert_source_map!( "/// my add functionpub fn add_2(x) { x + 2}
fn unused(x) { x + 1}
pub fn add_3(x) { x + 3}" )}
#[test]fn sourcemap_function_definition_with_variable_assignment() { assert_source_map!( "/// my functionpub fn wibble() { let wibble = 1 wibble + 2}" )}
#[test]fn sourcemap_function_definition_with_string_with_newline_escaped() { assert_source_map!( "/// my functionpub fn wibble() { let wibble = \"hello\\nworld\" wibble <> \"!\"}" )}
#[test]fn sourcemap_function_definition_with_string_with_newline() { assert_source_map!( "/// my functionpub fn wibble() { let wibble = \"helloworld\" wibble <> \"!\"}" )}
#[test]fn sourcemap_custom_type_definition() { assert_source_map!( "/// my custom typepub type Wibble { /// Wibble Wibble /// Wobble Wobble(field: Int) /// Wabble Wabble(Wibble)}" )}
#[test]fn sourcemap_custom_type_definition_with_unused() { assert_source_map!( "/// my custom typepub type Wibble { /// Wibble Wibble}
type Unused { Unused}
pub type Wobble { Wobble(Wibble)}" )}
#[test]fn sourcemap_module_constant() { assert_source_map!( "/// my constantpub const wibble = 1/// wobbleconst wobble = 2/// wabblepub const wabble = 3" )}
#[test]fn sourcemap_assert() { assert_source_map!( "pub fn main() { let x = True assert x}" )}
#[test]fn sourcemap_let_assert() { assert_source_map!( "pub fn unwrap_or_panic(result) { let assert Ok(value) = result value}" )}
#[test]fn sourcemap_let_assert_that_always_succeeds() { assert_source_map!( "pub fn go(x) { let assert #(wibble, wobble) = x}" )}
#[test]fn sourcemap_case_destructure_assignment_statement() { assert_source_map!( "pub type Wibble { Wibble(Int, Int)}
pub fn go(x) { case Wibble(1, 2) { Wibble(wibble, wobble) -> wibble + wobble }}" )}
#[test]fn sourcemap_with_complex_case_expression() { assert_source_map!( "pub fn go(one, other) { case one, other { Ok(1), Error(_) -> 1 Ok(_), _ -> 2 Error(_), Ok(2) -> 3 _, _ -> 4 }}" )}
#[test]fn sourcemap_pipe() { assert_source_map!( "fn add_2(x) { x + 2}
pub fn go(x) { x |> add_2}" )}
#[test]fn sourcemap_use() { assert_source_map!( "fn add_3_to_result(i, f) { f(i) + 3}
pub fn go(x) { use a <- add_3_to_result(1) a + 2}" )}
#[test]fn sourcemap_with_list() { assert_source_map!( "pub fn go(x) { [1, 2, 3]}" )}
#[test]fn sourcemap_with_tuple() { assert_source_map!( "pub fn go(x) { #(1, 2, 3)}" )}
#[test]fn sourcemap_with_bitarray() { assert_source_map!( "pub fn go(x) { <<256:int>>}" )}
#[test]fn sourcemap_with_tail_recursive_functions() { assert_source_map!( "pub fn wibble(lon, acc) { case lon { [] -> 0 [n, ..rest] -> wibble(rest, acc + n) }}" )}
#[test]fn string_with_newlines() { assert_source_map!( r#"pub fn wibble(lon, acc) { let one = "one" let two = "one
two
three" let three = "three"}"# )}