diff options
Diffstat (limited to 'progs/tests')
| -rw-r--r-- | progs/tests/func/wrong_params.sy | 2 | ||||
| -rw-r--r-- | progs/tests/nullable_types.sy | 33 | ||||
| -rw-r--r-- | progs/tests/tuple/sub.sy | 3 | ||||
| -rw-r--r-- | progs/tests/union_types_simple.sy | 36 | ||||
| -rw-r--r-- | progs/tests/union_types_simple_faulty.sy | 25 |
5 files changed, 97 insertions, 2 deletions
diff --git a/progs/tests/func/wrong_params.sy b/progs/tests/func/wrong_params.sy index e49e89b..0082a3a 100644 --- a/progs/tests/func/wrong_params.sy +++ b/progs/tests/func/wrong_params.sy @@ -4,4 +4,4 @@ start :: fn { f } -// errors: [ErrorKind::TypeMismatch(_, _), ErrorKind::TypeMismatch(Type::Void, Type::Int)] +// errors: [ErrorKind::TypeMismatch(_, _), ErrorKind::TypeMismatch(Type::Int, Type::Void)] diff --git a/progs/tests/nullable_types.sy b/progs/tests/nullable_types.sy new file mode 100644 index 0000000..2088c53 --- /dev/null +++ b/progs/tests/nullable_types.sy @@ -0,0 +1,33 @@ +test001 :: fn -> int { + a : int? = nil + a = 2 + ret a +} + +test002 :: fn b:bool -> int? { + if b { + ret nil + } else { + ret 0 + } +} + +// TODO(ed): Introduce type type! +test003 :: fn { + a := test002! false + a += 1 + a <=> 1 +} + + +start :: fn { + test001! + nil <=> test002! true + 0 <=> test002! false + q : bool? = true + q <=> true + q = nil + q <=> nil + test003! +} + diff --git a/progs/tests/tuple/sub.sy b/progs/tests/tuple/sub.sy index e5d60f2..cca4f2c 100644 --- a/progs/tests/tuple/sub.sy +++ b/progs/tests/tuple/sub.sy @@ -1,3 +1,4 @@ start :: fn { - (1, -2, 3, -4) - (4, 3, -2, -1) <=> (-3, 1, 1, -5) + print (1, -2, 3, -4) - (4, 3, -2, -1) + (1, -2, 3, -4) - (4, 3, -2, -1) <=> (-3, -5, 5, -3) } diff --git a/progs/tests/union_types_simple.sy b/progs/tests/union_types_simple.sy new file mode 100644 index 0000000..f6cf622 --- /dev/null +++ b/progs/tests/union_types_simple.sy @@ -0,0 +1,36 @@ +f :: fn a:bool -> int | str | void { + if a { + ret 1 + } else { + ret + } +} + +g :: fn a:bool -> int | (bool, bool) { + if a { + ret 1 + } else { + ret (true, true) + } +} + +h :: fn a:bool -> int | fn -> int { + if a { + f :: fn -> int { ret 1 } + ret f + } else { + ret 1 + } +} + +start :: fn { + 1 <=> f! true + nil <=> f! false + (true, true) <=> g! false + 1 <=> g! true + f(true) <=> g(true) + + 1 <=> h! false + q :: h! true + 1 <=> q() +} diff --git a/progs/tests/union_types_simple_faulty.sy b/progs/tests/union_types_simple_faulty.sy new file mode 100644 index 0000000..b742054 --- /dev/null +++ b/progs/tests/union_types_simple_faulty.sy @@ -0,0 +1,25 @@ +f :: fn a:bool -> int | void { + if a { + ret 1 + } else { + ret "hello!" + } +} + +g :: fn a:bool -> int | (bool, bool) { + if a { + ret 1 + } else { + ret (true, 1.0) + } +} + +start :: fn { + 0 <=> f! true + 0.0 <=> f! false + ("hello!", "there") <=> g! false + 1 <=> g! true + f(true) <=> g(true) +} + +// errors: [ ErrorKind::TypeMismatch(_, _), ErrorKind::TypeMismatch(_, _), ErrorKind::TypeError(_, _), ErrorKind::TypeError(_, _) ] |
