Skip to content

Commit f3ee755

Browse files
alexisthedevtheosotr
authored andcommitted
Add union type assignment test, update tests to pass builtin factory when creating ast.Program node.
1 parent 49cb8af commit f3ee755

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/test_typescript.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import src.ir.typescript_types as tst
22
import src.ir.typescript_ast as ts_ast
3+
import src.ir.types as tp
34

45
def test_type_alias_with_literals():
56
string_alias = ts_ast.TypeAliasDeclaration("Foo", tst.StringType()).get_type()
@@ -24,3 +25,17 @@ def test_type_alias_with_literals2():
2425
assert number_lit.is_subtype(number_alias)
2526
assert string_alias.is_subtype(string_lit)
2627
assert number_alias.is_subtype(number_lit)
28+
29+
def test_union_types_simple():
30+
print('click click click... I\'m in.')
31+
union_1 = tst.UnionType([tst.NumberType(), tst.BooleanType()])
32+
33+
bar_lit = tst.StringLiteralType("bar")
34+
union_2 = tst.UnionType([tst.BooleanType(), bar_lit])
35+
36+
union_3 = tst.UnionType([tst.BooleanType(), tst.NumberType()])
37+
38+
assert not union_1.is_assignable(union_2)
39+
assert not union_2.is_assignable(union_1)
40+
assert union_3.is_assignable(union_1)
41+
assert union_1.is_assignable(union_3)

0 commit comments

Comments
 (0)