Fork of daniellemaywood.uk/gleam — Wasm codegen work
1.5 kB
105 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 qualified_ok() {
8 assert_js!(
9 r#"import gleam
10pub fn go() { gleam.Ok(1) }
11"#,
12 );
13}
14
15#[test]
16fn qualified_ok_typescript() {
17 assert_ts_def!(
18 r#"import gleam
19pub fn go() { gleam.Ok(1) }
20"#,
21 );
22}
23
24#[test]
25fn qualified_error() {
26 assert_js!(
27 r#"import gleam
28pub fn go() { gleam.Error(1) }
29"#,
30 );
31}
32
33#[test]
34fn qualified_nil() {
35 assert_js!(
36 r#"import gleam
37pub fn go() { gleam.Nil }
38"#,
39 );
40}
41
42#[test]
43fn qualified_nil_typescript() {
44 assert_ts_def!(
45 r#"import gleam
46pub fn go() { gleam.Nil }
47"#,
48 );
49}
50
51// https://github.com/gleam-lang/gleam/issues/4756
52#[test]
53fn qualified_prelude_value_does_not_conflict_with_local_value() {
54 assert_js!(
55 "
56import gleam
57
58pub type Result(a, e) {
59 Ok(a)
60 Error(e)
61}
62
63pub fn main() {
64 gleam.Ok(10)
65}
66",
67 );
68}
69
70#[test]
71fn qualified_prelude_value_does_not_conflict_with_local_value_constant() {
72 assert_js!(
73 r#"
74import gleam
75
76pub type Result(a, e) {
77 Ok(a)
78 Error(e)
79}
80
81pub const error = gleam.Error("Bad")
82"#,
83 );
84}
85
86#[test]
87fn qualified_prelude_value_does_not_conflict_with_local_value_pattern() {
88 assert_js!(
89 r#"
90import gleam
91
92pub type Result(a, e) {
93 Ok(a)
94 Error(e)
95}
96
97pub fn go(x) {
98 case x {
99 gleam.Ok(x) -> x
100 gleam.Error(_) -> 0
101 }
102}
103"#,
104 );
105}