@@ -34,6 +34,48 @@ def test_unexpected_value(self):
34
34
35
35
36
36
class Test_DoctypeTransformer :
37
+ @pytest .mark .parametrize (
38
+ "doctype" ,
39
+ [
40
+ "((float))" ,
41
+ "(float,)" ,
42
+ "(, )" ,
43
+ "..." ,
44
+ "(..., ...)" ,
45
+ "{}" ,
46
+ "{:}" ,
47
+ "{a:}" ,
48
+ "{:b}" ,
49
+ "{'a',}" ,
50
+ "a or (b or c)" ,
51
+ ",, optional" ,
52
+ ],
53
+ )
54
+ def test_edge_case_errors (self , doctype ):
55
+ transformer = DoctypeTransformer ()
56
+ with pytest .raises (lark .exceptions .UnexpectedInput ):
57
+ transformer .doctype_to_annotation (doctype )
58
+
59
+ @pytest .mark .parametrize ("doctype" , DoctypeTransformer .blacklisted_qualnames )
60
+ def test_reserved_keywords (self , doctype ):
61
+ assert DoctypeTransformer .blacklisted_qualnames
62
+
63
+ transformer = DoctypeTransformer ()
64
+ with pytest .raises (lark .exceptions .VisitError ):
65
+ transformer .doctype_to_annotation (doctype )
66
+
67
+ @pytest .mark .parametrize (
68
+ ("doctype" , "expected" ),
69
+ [
70
+ ("int or float" , "int | float" ),
71
+ ("int or float or str" , "int | float | str" ),
72
+ ],
73
+ )
74
+ def test_natlang_union (self , doctype , expected ):
75
+ transformer = DoctypeTransformer ()
76
+ annotation , _ = transformer .doctype_to_annotation (doctype )
77
+ assert annotation .value == expected
78
+
37
79
@pytest .mark .parametrize (
38
80
("doctype" , "expected" ),
39
81
[
@@ -91,7 +133,7 @@ def test_natlang_container(self, doctype, expected):
91
133
"doctype" ,
92
134
[
93
135
"list of int (s)" ,
94
- "list of (float)" ,
136
+ "list of (( float) )" ,
95
137
"list of (float,)" ,
96
138
"list of (, )" ,
97
139
"list of ..." ,
0 commit comments