Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

gleam / compiler-core / src / erlang / tests / echo.rs
2.5 kB 197 lines
1// SPDX-License-Identifier: Apache-2.0 2// SPDX-FileCopyrightText: 2024 The Gleam contributors 3 4use crate::assert_erl; 5 6#[test] 7pub fn echo_with_a_simple_expression() { 8 assert_erl!( 9 r#" 10pub fn main() { 11 echo 1 12} 13"# 14 ); 15} 16 17#[test] 18pub fn echo_with_a_simple_expression_and_a_message() { 19 assert_erl!( 20 r#" 21pub fn main() { 22 echo 1 as "hello!" 23} 24"# 25 ); 26} 27 28#[test] 29pub fn echo_with_complex_expression_as_a_message() { 30 assert_erl!( 31 r#" 32pub fn main() { 33 echo 1 as case name() { 34 "Giacomo" -> "hello Jak!" 35 _ -> "hello!" 36 } 37} 38 39fn name() { "Giacomo" } 40"# 41 ); 42} 43 44#[test] 45pub fn multiple_echos_inside_expression() { 46 assert_erl!( 47 r#" 48pub fn main() { 49 echo 1 50 echo 2 51} 52"# 53 ); 54} 55 56#[test] 57pub fn echo_with_a_case_expression() { 58 assert_erl!( 59 r#" 60pub fn main() { 61 echo case 1 { 62 _ -> 2 63 } 64} 65"# 66 ); 67} 68 69#[test] 70pub fn echo_with_a_panic() { 71 assert_erl!( 72 r#" 73pub fn main() { 74 echo panic 75} 76"# 77 ); 78} 79 80#[test] 81pub fn echo_with_a_function_call() { 82 assert_erl!( 83 r#" 84pub fn main() { 85 echo wibble(1, 2) 86} 87 88fn wibble(n: Int, m: Int) { n + m } 89"# 90 ); 91} 92 93#[test] 94pub fn echo_with_a_function_call_and_a_message() { 95 assert_erl!( 96 r#" 97pub fn main() { 98 echo wibble(1, 2) as message() 99} 100 101fn wibble(n: Int, m: Int) { n + m } 102fn message() { "Hello!" } 103"# 104 ); 105} 106 107#[test] 108pub fn echo_with_a_block() { 109 assert_erl!( 110 r#" 111pub fn main() { 112 echo { 113 Nil 114 1 115 } 116} 117"# 118 ); 119} 120 121#[test] 122pub fn echo_in_a_pipeline() { 123 assert_erl!( 124 r#" 125pub fn main() { 126 [1, 2, 3] 127 |> echo 128 |> wibble 129} 130 131pub fn wibble(n) { n } 132"# 133 ) 134} 135 136#[test] 137pub fn echo_in_a_pipeline_with_message() { 138 assert_erl!( 139 r#" 140pub fn main() { 141 [1, 2, 3] 142 |> echo as "message!!" 143 |> wibble 144} 145 146pub fn wibble(n) { n } 147"# 148 ) 149} 150 151#[test] 152pub fn multiple_echos_in_a_pipeline() { 153 assert_erl!( 154 r#" 155pub fn main() { 156 [1, 2, 3] 157 |> echo 158 |> wibble 159 |> echo 160 |> wibble 161 |> echo 162} 163 164pub fn wibble(n) { n } 165"# 166 ) 167} 168 169#[test] 170pub fn pipeline_printed_by_echo_is_wrapped_in_begin_end_block() { 171 assert_erl!( 172 r#" 173pub fn main() { 174 echo 175 123 176 |> wibble 177 |> wibble 178} 179 180pub fn wibble(n) { n } 181"# 182 ) 183} 184 185#[test] 186pub fn record_update_printed_by_echo_is_wrapped_in_begin_end_block() { 187 assert_erl!( 188 r#" 189pub type Wobble { Wobble(id: Int, name: String) } 190 191pub fn main() { 192 let wobble = Wobble(1, "wobble") 193 echo Wobble(..wobble, id: 1) 194} 195"# 196 ) 197}