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 / bools.rs
2.5 kB 215 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 expressions() { 8 assert_js!( 9 r#" 10pub fn go() { 11 True 12 False 13 Nil 14} 15"# 16 ); 17} 18 19#[test] 20fn constants() { 21 assert_js!( 22 r#" 23pub const a = True 24pub const b = False 25pub const c = Nil 26"#, 27 ); 28} 29 30#[test] 31fn constants_typescript() { 32 assert_ts_def!( 33 r#" 34pub const a = True 35pub const b = False 36pub const c = Nil 37"#, 38 ); 39} 40 41#[test] 42fn operators() { 43 assert_js!( 44 r#" 45pub fn go() { 46 True && True 47 False || False 48} 49"#, 50 ); 51} 52 53#[test] 54fn assigning() { 55 assert_js!( 56 r#" 57pub fn go(x, y) { 58 let assert True = x 59 let assert False = x 60 let assert Nil = y 61} 62"#, 63 ); 64} 65 66// https://github.com/gleam-lang/gleam/issues/1112 67// differentiate between prelude constructors and custom type constructors 68#[test] 69fn shadowed_bools_and_nil() { 70 assert_js!( 71 r#" 72pub type True { True False Nil } 73pub fn go(x, y) { 74 let assert True = x 75 let assert False = x 76 let assert Nil = y 77} 78"#, 79 ); 80} 81 82#[test] 83fn shadowed_bools_and_nil_typescript() { 84 assert_ts_def!( 85 r#" 86pub type True { True False Nil } 87pub fn go(x, y) { 88 let assert True = x 89 let assert False = x 90 let assert Nil = y 91} 92"#, 93 ); 94} 95 96#[test] 97fn equality() { 98 assert_js!( 99 r#" 100pub fn go(a, b) { 101 a == True 102 a != True 103 a == False 104 a != False 105 a == a 106 a != a 107 b == Nil 108 b != Nil 109 b == b 110} 111"#, 112 ); 113} 114 115#[test] 116fn case() { 117 assert_js!( 118 r#" 119pub fn go(a) { 120 case a { 121 True -> 1 122 False -> 0 123 } 124} 125"#, 126 ); 127} 128 129#[test] 130fn nil_case() { 131 assert_js!( 132 r#" 133pub fn go(a) { 134 case a { 135 Nil -> 0 136 } 137} 138"#, 139 ); 140} 141 142#[test] 143fn negation() { 144 assert_js!( 145 "pub fn negate(x) { 146 !x 147}" 148 ); 149} 150 151#[test] 152fn negation_block() { 153 assert_js!( 154 "pub fn negate(x) { 155 !{ 156 123 157 x 158 } 159}" 160 ); 161} 162 163#[test] 164fn binop_panic_right() { 165 assert_js!( 166 "pub fn negate(x) { 167 x && panic 168}" 169 ); 170} 171 172#[test] 173fn binop_panic_left() { 174 assert_js!( 175 "pub fn negate(x) { 176 panic && x 177}" 178 ); 179} 180 181#[test] 182fn binop_todo_right() { 183 assert_js!( 184 "pub fn negate(x) { 185 x && todo 186}" 187 ); 188} 189 190#[test] 191fn binop_todo_left() { 192 assert_js!( 193 "pub fn negate(x) { 194 todo && x 195}" 196 ); 197} 198 199#[test] 200fn negate_panic() { 201 assert_js!( 202 "pub fn negate(x) { 203 !panic 204}" 205 ); 206} 207 208#[test] 209fn negate_todo() { 210 assert_js!( 211 "pub fn negate(x) { 212 !todo 213}" 214 ); 215}