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 / pipes.rs
1.9 kB 154 lines
1// SPDX-License-Identifier: Apache-2.0 2// SPDX-FileCopyrightText: 2021 The Gleam contributors 3 4use crate::assert_erl; 5 6#[test] 7fn clever_pipe_rewriting() { 8 // a |> b 9 assert_erl!( 10 r#" 11pub fn apply(f: fn(a) -> b, a: a) { a |> f } 12"# 13 ); 14} 15 16#[test] 17fn clever_pipe_rewriting1() { 18 // a |> b(c) 19 assert_erl!( 20 r#" 21pub fn apply(f: fn(a, Int) -> b, a: a) { a |> f(1) } 22"# 23 ); 24} 25 26// https://github.com/gleam-lang/gleam/issues/952 27#[test] 28fn block_expr_into_pipe() { 29 assert_erl!( 30 r#"fn id(a) { a } 31pub fn main() { 32 { 33 let x = 1 34 x 35 } 36 |> id 37}"# 38 ); 39} 40 41#[test] 42fn pipe_in_list() { 43 assert_erl!( 44 "pub fn x(f) { 45 [ 46 1 |> f 47 ] 48}" 49 ); 50} 51 52#[test] 53fn pipe_in_tuple() { 54 assert_erl!( 55 "pub fn x(f) { 56 #( 57 1 |> f 58 ) 59}" 60 ); 61} 62 63#[test] 64fn pipe_in_case_subject() { 65 assert_erl!( 66 "pub fn x(f) { 67 case 1 |> f { 68 x -> x 69 } 70}" 71 ); 72} 73 74// https://github.com/gleam-lang/gleam/issues/1379 75#[test] 76fn pipe_in_record_update() { 77 assert_erl!( 78 "pub type X { 79 X(a: Int, b: Int) 80} 81 82fn id(x) { 83 x 84} 85 86pub fn main(x) { 87 X(..x, a: 1 |> id) 88}" 89 ); 90} 91 92// https://github.com/gleam-lang/gleam/issues/1385 93#[test] 94fn pipe_in_eq() { 95 assert_erl!( 96 "fn id(x) { 97 x 98} 99 100pub fn main() { 101 1 == 1 |> id 102}" 103 ); 104} 105 106// https://github.com/gleam-lang/gleam/issues/1863 107#[test] 108fn call_pipeline_result() { 109 assert_erl!( 110 r#" 111pub fn main() { 112 { 1 |> add }(1) 113} 114 115pub fn add(x) { 116 fn(y) { x + y } 117} 118"# 119 ); 120} 121 122// https://github.com/gleam-lang/gleam/issues/1931 123#[test] 124fn pipe_in_call() { 125 assert_erl!( 126 r#" 127pub fn main() { 128 123 129 |> two( 130 1 |> two(2), 131 _, 132 ) 133} 134 135pub fn two(a, b) { 136 a 137} 138"# 139 ); 140} 141 142#[test] 143fn multiple_pipes() { 144 assert_erl!( 145 " 146pub fn main() { 147 1 |> x |> x 148 2 |> x |> x 149} 150 151fn x(x) { x } 152" 153 ); 154}