Fork of daniellemaywood.uk/gleam — Wasm codegen work
923 B
59 lines
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2022 The Gleam contributors
3
4use crate::assert_ts_def;
5
6#[test]
7fn fn_generics_typescript() {
8 assert_ts_def!(
9 r#"pub fn identity(a) -> a {
10 a
11}
12"#,
13 );
14}
15
16#[test]
17fn record_generics_typescript() {
18 assert_ts_def!(
19 r#"pub type Animal(t) {
20 Cat(type_: t)
21 Dog(type_: t)
22}
23
24pub fn main() {
25 Cat(type_: 6)
26}
27"#,
28 );
29}
30
31#[test]
32fn tuple_generics_typescript() {
33 assert_ts_def!(
34 r#"pub fn make_tuple(x: t) -> #(Int, t, Int) {
35 #(0, x, 1)
36}
37"#,
38 );
39}
40
41#[test]
42fn result_typescript() {
43 assert_ts_def!(
44 r#"pub fn map(result, fun) {
45 case result {
46 Ok(a) -> Ok(fun(a))
47 Error(e) -> Error(e)
48 }
49 }"#,
50 );
51}
52
53#[test]
54fn task_typescript() {
55 assert_ts_def!(
56 r#"pub type Promise(value)
57 pub type Task(a) = fn() -> Promise(a)"#,
58 );
59}