forked from TheLartians/TypeScript2Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdicts.test.ts
More file actions
61 lines (56 loc) 路 1.31 KB
/
Copy pathdicts.test.ts
File metadata and controls
61 lines (56 loc) 路 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { transpileString } from "./utils";
describe("transpiling dictionaries types", () => {
it("can transpile dicts", async () => {
const result = await transpileString(`export type A = {
foo: string,
bar: number,
}`);
expect(result).toContain(`class A(TypedDict):\n foo: str\n bar: float`);
});
it("keeps docstrings", async () => {
const result = await transpileString(`
/** This is A */
export type A = {
/** this is foo */
foo: string,
/** this is bar */
bar: number,
}
`);
expect(result).toContain(
`class A(TypedDict):
"""
This is A
"""
foo: str
"""
this is foo
"""
bar: float
"""
this is bar
"""`,
);
});
it("can transpile nested dicts", async () => {
const result = await transpileString(`export type A = {
outer: {
inner: string
},
extra: number,
}`);
expect(result).toContain(
`class Ts2PyHelperType1(TypedDict):
inner: str
class A(TypedDict):
outer: Ts2PyHelperType1
extra: float`,
);
});
it("can transpile intersections", async () => {
const result = await transpileString(
`export type A = { foo: string } & { bar: number }`,
);
expect(result).toContain(`class A(TypedDict):\n foo: str\n bar: float`);
});
});