|
9 | 9 |
|
10 | 10 |
|
11 | 11 | def test_none(): |
12 | | - def after_recipe(cu): |
13 | | - assert find_first(cu, Literal).type == JavaType.Primitive.None_ |
14 | | - |
15 | 12 | # language=python |
16 | | - rewrite_run(python("assert None", after_recipe=after_recipe)) |
| 13 | + rewrite_run(python("assert None", after_recipe=check_first_literal_type(JavaType.Primitive.None_))) |
17 | 14 |
|
18 | 15 |
|
19 | 16 | def test_boolean(): |
20 | | - def after_recipe(cu): |
21 | | - assert find_first(cu, Literal).type == JavaType.Primitive.Boolean |
22 | | - |
23 | 17 | # language=python |
24 | | - rewrite_run(python("assert True", after_recipe=after_recipe)) |
25 | | - rewrite_run(python("assert False", after_recipe=after_recipe)) |
| 18 | + rewrite_run(python("assert True", after_recipe=check_first_literal_type(JavaType.Primitive.Boolean))) |
| 19 | + rewrite_run(python("assert False", after_recipe=check_first_literal_type(JavaType.Primitive.Boolean))) |
26 | 20 |
|
27 | 21 |
|
28 | 22 | def test_dec_int(): |
29 | | - def after_recipe(cu): |
30 | | - assert find_first(cu, Literal).type == JavaType.Primitive.Int |
31 | | - |
32 | 23 | # language=python |
33 | | - rewrite_run(python("assert 0", after_recipe=after_recipe)) |
| 24 | + rewrite_run(python("assert 0", after_recipe=check_first_literal_type(JavaType.Primitive.Int))) |
34 | 25 |
|
35 | 26 |
|
36 | 27 | def test_hex_int(): |
37 | | - def after_recipe(cu): |
38 | | - assert find_first(cu, Literal).type == JavaType.Primitive.Int |
39 | | - |
40 | 28 | # language=python |
41 | | - rewrite_run(python("assert 0x1f", after_recipe=after_recipe)) |
| 29 | + rewrite_run(python("assert 0x1f", after_recipe=check_first_literal_type(JavaType.Primitive.Int))) |
42 | 30 |
|
43 | 31 |
|
44 | 32 | def test_fraction(): |
45 | | - def after_recipe(cu): |
46 | | - assert find_first(cu, Literal).type == JavaType.Primitive.Double |
47 | | - |
48 | 33 | # language=python |
49 | | - rewrite_run(python("assert 0.000", after_recipe=after_recipe)) |
| 34 | + rewrite_run(python("assert 0.000", after_recipe=check_first_literal_type(JavaType.Primitive.Double))) |
50 | 35 |
|
51 | 36 |
|
52 | 37 | def test_fraction_leading_dot(): |
53 | | - def after_recipe(cu): |
54 | | - assert find_first(cu, Literal).type == JavaType.Primitive.Double |
55 | | - |
56 | 38 | # language=python |
57 | | - rewrite_run(python("assert .0", after_recipe=after_recipe)) |
| 39 | + rewrite_run(python("assert .0", after_recipe=check_first_literal_type(JavaType.Primitive.Double))) |
58 | 40 |
|
59 | 41 |
|
60 | 42 | def test_large_int(): |
61 | | - def after_recipe(cu): |
62 | | - assert find_first(cu, Literal).type == JavaType.Primitive.Int |
63 | | - |
64 | 43 | # language=python |
65 | | - rewrite_run(python("assert 0xC03A0019", after_recipe=after_recipe)) |
| 44 | + rewrite_run(python("assert 0xC03A0019", after_recipe=check_first_literal_type(JavaType.Primitive.Int))) |
66 | 45 |
|
67 | 46 |
|
68 | 47 | def test_byte_string_concatenation(): |
69 | | - def after_recipe(cu): |
70 | | - assert find_first(cu, Literal).type == JavaType.Primitive.Double |
71 | | - |
72 | 48 | # language=python |
73 | | - rewrite_run(python("assert b'hello' b'world'", after_recipe=after_recipe)) |
| 49 | + rewrite_run(python("assert b'hello' b'world'", after_recipe=check_first_literal_type(JavaType.Primitive.String))) |
74 | 50 |
|
75 | 51 |
|
76 | 52 | def test_bigint(): |
77 | | - def after_recipe(cu): |
78 | | - assert find_first(cu, Literal).type == JavaType.Primitive.Int |
79 | | - |
80 | 53 | # language=python |
81 | | - rewrite_run(python("assert 9223372036854775808", after_recipe=after_recipe)) |
| 54 | + rewrite_run(python("assert 9223372036854775808", after_recipe=check_first_literal_type(JavaType.Primitive.Int))) |
82 | 55 |
|
83 | 56 |
|
84 | 57 | def test_single_quoted_string(): |
@@ -194,3 +167,9 @@ def visit(self, t: Tree, p: list[Tree]) -> Optional[Tree]: |
194 | 167 | found = [] |
195 | 168 | Find().visit(tree, found) |
196 | 169 | return found[0] |
| 170 | + |
| 171 | +def check_first_literal_type(expected_type): |
| 172 | + def after_recipe(cu): |
| 173 | + assert find_first(cu, Literal).type == expected_type |
| 174 | + return after_recipe |
| 175 | + |
0 commit comments