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 / javascript / tests / tuples.rs
1.9 kB 150 lines
1// SPDX-License-Identifier: Apache-2.0 2// SPDX-FileCopyrightText: 2021 The Gleam contributors 3 4use crate::{assert_js, assert_ts_def}; 5 6#[test] 7fn tuple() { 8 assert_js!( 9 r#" 10pub fn go() { 11 #("1", "2", "3") 12} 13"#, 14 ); 15} 16 17#[test] 18fn tuple1() { 19 assert_js!( 20 r#" 21pub fn go() { 22 #( 23 "1111111111111111111111111111111", 24 #("1111111111111111111111111111111", "2", "3"), 25 "3", 26 ) 27} 28"#, 29 ); 30} 31 32#[test] 33fn tuple_typescript() { 34 assert_ts_def!( 35 r#" 36pub fn go() { 37 #("1", "2", "3") 38} 39"#, 40 ); 41} 42 43#[test] 44fn tuple_access() { 45 assert_js!( 46 r#" 47pub fn go() { 48 #(1, 2).0 49} 50"#, 51 ) 52} 53 54#[test] 55fn tuple_with_block_element() { 56 assert_js!( 57 r#" 58pub fn go() { 59 #( 60 "1", 61 { 62 "2" 63 "3" 64 }, 65 ) 66} 67"#, 68 ); 69} 70 71#[test] 72fn tuple_with_block_element1() { 73 assert_js!( 74 r#" 75pub fn go() { 76 #( 77 "1111111111111111111111111111111", 78 #("1111111111111111111111111111111", "2", "3"), 79 "3", 80 ) 81} 82"#, 83 ); 84} 85 86#[test] 87fn constant_tuples() { 88 assert_js!( 89 r#" 90pub const a = "Hello" 91pub const b = 1 92pub const c = 2.0 93pub const e = #("bob", "dug") 94 "#, 95 ); 96} 97 98#[test] 99fn constant_tuples1() { 100 assert_js!( 101 r#" 102pub const e = #( 103 "loooooooooooooong", "loooooooooooong", "loooooooooooooong", 104 "loooooooooooooong", "loooooooooooong", "loooooooooooooong", 105) 106"# 107 ); 108} 109 110#[test] 111fn tuple_formatting_typescript() { 112 assert_ts_def!( 113 r#" 114pub const e = #( 115 "a", "a", "a", "a", "a", "a", "a", 116 "a", "a", "a", "a", "a", "a", "a", 117 "a", "a", "a", "a", "a", "a", "a", 118) 119"# 120 ); 121} 122 123#[test] 124fn case() { 125 assert_js!( 126 r#" 127pub fn go(a) { 128 case a { 129 #(2, a) -> a 130 #(1, 1) -> 1 131 #(a, b) -> a + b 132 } 133} 134"# 135 ); 136} 137 138#[test] 139fn nested_pattern() { 140 assert_js!( 141 r#" 142pub fn go(x) { 143 case x { 144 #(2, #(a, b)) -> a + b 145 _ -> 1 146 } 147} 148"# 149 ); 150}