Пример #1
0
 def test_all_not_inlined(self):
     store = TSTypeStore()
     F = Named(Union[str, int])
     G = Named(Optional[Union[str, int, float]])
     store.add_type(F)
     store.add_type(G)
     res = 'type F = string | number /*int*/;\ntype G = string | number /*int*/ | number /*float*/ | undefined;'
     self.assertEqual(store.get_all_not_inlined(), res)
Пример #2
0
 def test_generic_array(self):
     u = Named(Union[int, str])
     a = List[u]
     store = TSTypeStore()
     res = '(u)[]'
     print('extended name should be u', get_extended_name(u))
     self.assertEqual(store.get_repr(a), res)
Пример #3
0
    def test_generic(self):
        store = TSTypeStore(export_all=True)
        T = TypeVar('T')

        @dataclass
        class jeb(Generic[T]):
            p: T

        impl = Named(List[jeb[int]])

        res = 'export type impl = (jeb<number /*int*/>)[];'
        self.assertEqual(store.get_full_repr(impl), res)
Пример #4
0
 def test_named_Union(self):
     store = TSTypeStore(export_all=True)
     K = Named(Optional[Union[int, str]])
     res = 'export type K = number /*int*/ | string | undefined;'
     self.assertEqual(store.get_full_repr(K), res)
     self.assertEqual(store.get_repr(K), 'K')
Пример #5
0
 def test_named_literal(self):
     store = TSTypeStore(export_all=True)
     B = Named(Literal[1, 2, 'test_string'])
     res = 'export type B = 1 | 2 | "test_string";'
     self.assertEqual(store.get_full_repr(B), res)
     self.assertEqual(store.get_repr(B), 'B')
Пример #6
0
 def test_named_list(self):
     store = TSTypeStore()
     a = Named(List[int])
     self.assertEqual(store.get_full_repr(a),
                      'type a = (number /*int*/)[];')
Пример #7
0
 def test_named_mapping(self):
     store = TSTypeStore()
     a = Named(Dict[int, str])
     self.assertEqual(store.get_full_repr(a),
                      'type a = { [key: number /*int*/]: string }')
Пример #8
0
 def test_export_one(self):
     store = TSTypeStore()
     a = Named(Union[int, str])
     self.assertEqual(store.get_full_repr(a, exported=True),
                      'export type a = number /*int*/ | string;')
Пример #9
0
 def test_named_tuple(self):
     store = TSTypeStore()
     C = Named(Tuple[int, str])
     D = Named(Optional[Tuple[C, Tuple[str, str]]])
     res = 'type D = [C, [string, string]] | undefined;'
     self.assertEqual(store.get_full_repr(D), res)