@@ -26,7 +26,7 @@ public class PatternParserTest {
2626 static {
2727 TestRegistration .register ();
2828 }
29-
29+
3030 private <T > void assertEqualsOptional (T expected , Optional <? extends T > actual ) {
3131 assertTrue (actual .filter (expected ::equals ).isPresent ());
3232 }
@@ -45,147 +45,147 @@ public void testParsePattern() {
4545
4646 // Nested optionals
4747 assertEqualsOptional (
48- new OptionalGroup (
49- new CompoundElement (
50- new TextElement ("nested " ),
51- new OptionalGroup (new TextElement ("optional" ))
52- )
53- ),
54- parsePattern ("[nested [optional]]" , logger )
48+ new OptionalGroup (
49+ new CompoundElement (
50+ new TextElement ("nested " ),
51+ new OptionalGroup (new TextElement ("optional" ))
52+ )
53+ ),
54+ parsePattern ("[nested [optional]]" , logger )
5555 );
5656
5757 // Choice groups with parse marks
5858 assertEqualsOptional (
59- new ChoiceGroup (
60- new ChoiceElement (new TextElement ("single choice" ), null )
61- ),
62- parsePattern ("(single choice)" , logger )
59+ new ChoiceGroup (
60+ new ChoiceElement (new TextElement ("single choice" ), null )
61+ ),
62+ parsePattern ("(single choice)" , logger )
6363 );
6464 assertEqualsOptional (
65- new ChoiceGroup (
66- new ChoiceElement (new TextElement ("parse mark" ), "1" )
67- ),
68- parsePattern ("(1:parse mark)" , logger )
65+ new ChoiceGroup (
66+ new ChoiceElement (new TextElement ("parse mark" ), "1" )
67+ ),
68+ parsePattern ("(1:parse mark)" , logger )
6969 );
7070 assertEqualsOptional (
71- new ChoiceGroup (
72- new ChoiceElement (
73- new CompoundElement (
74- new TextElement ("simplified " ),
75- new OptionalGroup (
76- new TextElement ("mark" )
77- )
78- ),
79- "simplified"
71+ new ChoiceGroup (
72+ new ChoiceElement (
73+ new CompoundElement (
74+ new TextElement ("simplified " ),
75+ new OptionalGroup (
76+ new TextElement ("mark" )
8077 )
81- ),
82- parsePattern ("(:simplified [mark])" , logger )
78+ ),
79+ "simplified"
80+ )
81+ ),
82+ parsePattern ("(:simplified [mark])" , logger )
8383 );
8484 assertEqualsOptional (
85- new ChoiceGroup (
86- new ChoiceElement (new TextElement ("first choice" ), null ),
87- new ChoiceElement (new TextElement ("second choice" ), null )
88- ),
89- parsePattern ("(first choice|second choice)" , logger )
85+ new ChoiceGroup (
86+ new ChoiceElement (new TextElement ("first choice" ), null ),
87+ new ChoiceElement (new TextElement ("second choice" ), null )
88+ ),
89+ parsePattern ("(first choice|second choice)" , logger )
9090 );
9191 assertEqualsOptional (
92- new ChoiceGroup (
93- new ChoiceElement (new TextElement ("first mark" ), null ),
94- new ChoiceElement (new TextElement ("second mark" ), "1" )
95- ),
96- parsePattern ("(first mark|1:second mark)" , logger )
92+ new ChoiceGroup (
93+ new ChoiceElement (new TextElement ("first mark" ), null ),
94+ new ChoiceElement (new TextElement ("second mark" ), "1" )
95+ ),
96+ parsePattern ("(first mark|1:second mark)" , logger )
9797 );
9898 assertEqualsOptional (
99- new ChoiceGroup (
100- new ChoiceElement (new TextElement ("first choice " ), "first choice" ),
101- new ChoiceElement (new TextElement ("second choice" ), "second choice" )
102- ),
103- parsePattern (":(first choice |second choice)" , logger )
99+ new ChoiceGroup (
100+ new ChoiceElement (new TextElement ("first choice " ), "first choice" ),
101+ new ChoiceElement (new TextElement ("second choice" ), "second choice" )
102+ ),
103+ parsePattern (":(first choice |second choice)" , logger )
104104 );
105105 assertEqualsOptional (
106- new ChoiceGroup (
107- new ChoiceElement (new TextElement ("first mark" ), null ),
108- new ChoiceElement (new TextElement ("second mark" ), "second mark" )
109- ),
110- parsePattern ("(first mark|:second mark)" , logger )
106+ new ChoiceGroup (
107+ new ChoiceElement (new TextElement ("first mark" ), null ),
108+ new ChoiceElement (new TextElement ("second mark" ), "second mark" )
109+ ),
110+ parsePattern ("(first mark|:second mark)" , logger )
111111 );
112112 assertEqualsOptional (
113- new ChoiceGroup (
114- new ChoiceElement (new TextElement ("first mark" ), null ),
115- new ChoiceElement (new TextElement ("second mark" ), "second mark" ),
116- new ChoiceElement (new TextElement ("third custom mark" ), "custom" ),
117- new ChoiceElement (new TextElement ("fourth mark" ), null )
118- ),
119- parsePattern ("(first mark|:second mark|custom:third custom mark|fourth mark)" , logger )
113+ new ChoiceGroup (
114+ new ChoiceElement (new TextElement ("first mark" ), null ),
115+ new ChoiceElement (new TextElement ("second mark" ), "second mark" ),
116+ new ChoiceElement (new TextElement ("third custom mark" ), "custom" ),
117+ new ChoiceElement (new TextElement ("fourth mark" ), null )
118+ ),
119+ parsePattern ("(first mark|:second mark|custom:third custom mark|fourth mark)" , logger )
120120 );
121121
122122 // Optional choice group (syntax sugar)
123123 assertEqualsOptional (
124- new OptionalGroup (
125- new ChoiceGroup (
126- new ChoiceElement (new TextElement ("one" ), "one" ),
127- new ChoiceElement (new TextElement (" two" ), "two" ),
128- new ChoiceElement (new TextElement ("three" ), "four" )
129- )
130- ),
131- parsePattern (":[one| two|four:three]" , logger )
124+ new OptionalGroup (
125+ new ChoiceGroup (
126+ new ChoiceElement (new TextElement ("one" ), "one" ),
127+ new ChoiceElement (new TextElement (" two" ), "two" ),
128+ new ChoiceElement (new TextElement ("three" ), "four" )
129+ )
130+ ),
131+ parsePattern (":[one| two|four:three]" , logger )
132132 );
133133
134134 // Optional with nested group with parse marks
135135 assertEqualsOptional (
136- new OptionalGroup (
137- new ChoiceGroup (
138- new ChoiceElement (
139- new CompoundElement (
140- new TextElement ("optional " ),
141- new ChoiceGroup (
142- new ChoiceElement (new TextElement ("first choice" ), null ),
143- new ChoiceElement (new TextElement ("second choice" ), "second" )
144- )
145- ),
146- "optional"
147- )
148- )
149- ),
150- parsePattern ("[:optional (first choice|second:second choice)]" , logger )
136+ new OptionalGroup (
137+ new ChoiceGroup (
138+ new ChoiceElement (
139+ new CompoundElement (
140+ new TextElement ("optional " ),
141+ new ChoiceGroup (
142+ new ChoiceElement (new TextElement ("first choice" ), null ),
143+ new ChoiceElement (new TextElement ("second choice" ), "second" )
144+ )
145+ ),
146+ "optional"
147+ )
148+ )
149+ ),
150+ parsePattern ("[:optional (first choice|second:second choice)]" , logger )
151151 );
152152
153153 // Regex group
154154 assertEqualsOptional (
155- new RegexGroup (Pattern .compile (".+" )),
156- parsePattern ("<.+>" , logger )
155+ new RegexGroup (Pattern .compile (".+" )),
156+ parsePattern ("<.+>" , logger )
157157 );
158158 assertEqualsOptional (
159- new RegexGroup (Pattern .compile ("(\\ d*1)st|(\\ d*2)nd|(\\ d*3)rd|(\\ d*[4-90])th" )),
160- parsePattern ("<(\\ d*1)st|(\\ d*2)nd|(\\ d*3)rd|(\\ d*[4-90])th>" , logger )
159+ new RegexGroup (Pattern .compile ("(\\ d*1)st|(\\ d*2)nd|(\\ d*3)rd|(\\ d*[4-90])th" )),
160+ parsePattern ("<(\\ d*1)st|(\\ d*2)nd|(\\ d*3)rd|(\\ d*[4-90])th>" , logger )
161161 );
162162
163163 // Expression elements
164164 assertEqualsOptional (
165- new ExpressionElement (
166- Collections .singletonList (TypeManager .getPatternType ("number" ).orElseThrow (AssertionError ::new )),
167- ExpressionElement .Acceptance .ALL ,
168- false ,
169- false
170- ),
171- parsePattern ("%number%" , logger )
165+ new ExpressionElement (
166+ Collections .singletonList (TypeManager .getPatternType ("number" ).orElseThrow (AssertionError ::new )),
167+ ExpressionElement .Acceptance .ALL ,
168+ false ,
169+ false
170+ ),
171+ parsePattern ("%number%" , logger )
172172 );
173173 assertEqualsOptional (
174- new ExpressionElement (
175- Arrays .asList (
176- TypeManager .getPatternType ("number" ).orElseThrow (AssertionError ::new ),
177- TypeManager .getPatternType ("strings" ).orElseThrow (AssertionError ::new )
178- ),
179- ExpressionElement .Acceptance .LITERALS_ONLY ,
180- true ,
181- false
174+ new ExpressionElement (
175+ Arrays .asList (
176+ TypeManager .getPatternType ("number" ).orElseThrow (AssertionError ::new ),
177+ TypeManager .getPatternType ("strings" ).orElseThrow (AssertionError ::new )
182178 ),
183- parsePattern ("%*number/strings%" , logger )
179+ ExpressionElement .Acceptance .LITERALS_ONLY ,
180+ true ,
181+ false
182+ ),
183+ parsePattern ("%*number/strings%" , logger )
184184 );
185185
186186 // Failing patterns
187187 assertOptionalEmpty (parsePattern ("(unclosed" , logger ));
188188 assertOptionalEmpty (parsePattern ("%unfinished type" , logger ));
189189 }
190190
191- }
191+ }
0 commit comments