1717#[ cfg( test) ]
1818mod tests_and {
1919 use celma_v0_ast:: syntax:: ASTParsec :: {
20- PBind , PChoice , PCode , PMap , POptional , PRepeat , PSequence ,
20+ PBind , PChoice , PCode , PEpsilon , PMap , POptional , PRepeat , PSequence ,
2121 } ;
2222 use celma_v0_core:: parser:: response:: Response :: Success ;
2323 use celma_v0_core:: parser:: specs:: Parse ;
@@ -30,7 +30,7 @@ mod tests_and {
3030
3131 match response {
3232 Success ( ast, _, _) => assert_eq ! ( ast, PCode ( String :: from( "char(\' a\' )" ) ) ) ,
33- _ => assert_eq ! ( true , false ) ,
33+ _ => panic ! ( ) ,
3434 } ;
3535 }
3636
@@ -42,11 +42,11 @@ mod tests_and {
4242 Success ( ast, _, _) => assert_eq ! (
4343 ast,
4444 PSequence (
45- Box :: new ( PCode ( String :: from( "char(\' a\' )" ) ) ) ,
46- Box :: new ( PCode ( String :: from( "char(\' b\' )" ) ) ) ,
45+ PCode ( String :: from( "char(\' a\' )" ) ) . wrap ( ) ,
46+ PCode ( String :: from( "char(\' b\' )" ) ) . wrap ( ) ,
4747 )
4848 ) ,
49- _ => assert_eq ! ( true , false ) ,
49+ _ => panic ! ( ) ,
5050 } ;
5151 }
5252
@@ -58,11 +58,11 @@ mod tests_and {
5858 Success ( ast, _, _) => assert_eq ! (
5959 ast,
6060 PChoice (
61- Box :: new ( PCode ( String :: from( "char(\' a\' )" ) ) ) ,
62- Box :: new ( PCode ( String :: from( "char(\' b\' )" ) ) ) ,
61+ PCode ( String :: from( "char(\' a\' )" ) ) . wrap ( ) ,
62+ PCode ( String :: from( "char(\' b\' )" ) ) . wrap ( ) ,
6363 )
6464 ) ,
65- _ => assert_eq ! ( true , false ) ,
65+ _ => panic ! ( ) ,
6666 } ;
6767 }
6868
@@ -73,12 +73,9 @@ mod tests_and {
7373 match response {
7474 Success ( ast, _, _) => assert_eq ! (
7575 ast,
76- PBind (
77- String :: from( "c" ) ,
78- Box :: new( PCode ( String :: from( "char(\' a\' )" ) ) ) ,
79- )
76+ PBind ( String :: from( "c" ) , PCode ( String :: from( "char(\' a\' )" ) ) . wrap( ) , )
8077 ) ,
81- _ => assert_eq ! ( true , false ) ,
78+ _ => panic ! ( ) ,
8279 } ;
8380 }
8481
@@ -91,10 +88,10 @@ mod tests_and {
9188 ast,
9289 PBind (
9390 String :: from( "c" ) ,
94- Box :: new ( POptional ( Box :: new ( PCode ( String :: from( "char(\' a\' )" ) ) ) ) ) ,
91+ POptional ( PCode ( String :: from( "char(\' a\' )" ) ) . wrap ( ) ) . wrap ( ) ,
9592 )
9693 ) ,
97- _ => assert_eq ! ( true , false ) ,
94+ _ => panic ! ( ) ,
9895 } ;
9996 }
10097
@@ -107,10 +104,10 @@ mod tests_and {
107104 ast,
108105 PBind (
109106 String :: from( "c" ) ,
110- Box :: new ( PRepeat ( true , Box :: new ( PCode ( String :: from( "char(\' a\' )" ) ) ) ) ) ,
107+ PRepeat ( true , PCode ( String :: from( "char(\' a\' )" ) ) . wrap ( ) ) . wrap ( ) ,
111108 )
112109 ) ,
113- _ => assert_eq ! ( true , false ) ,
110+ _ => panic ! ( ) ,
114111 } ;
115112 }
116113
@@ -123,10 +120,10 @@ mod tests_and {
123120 ast,
124121 PBind (
125122 String :: from( "c" ) ,
126- Box :: new ( PRepeat ( false , Box :: new ( PCode ( String :: from( "char(\' a\' )" ) ) ) ) ) ,
123+ PRepeat ( false , PCode ( String :: from( "char(\' a\' )" ) ) . wrap ( ) ) . wrap ( ) ,
127124 )
128125 ) ,
129- _ => assert_eq ! ( true , false ) ,
126+ _ => panic ! ( ) ,
130127 } ;
131128 }
132129
@@ -138,17 +135,19 @@ mod tests_and {
138135 Success ( ast, _, _) => assert_eq ! (
139136 ast,
140137 PSequence (
141- Box :: new ( PBind (
138+ PBind (
142139 String :: from( "a" ) ,
143- Box :: new( PRepeat ( false , Box :: new( PCode ( String :: from( "char(\' a\' )" ) ) ) ) ) ,
144- ) ) ,
145- Box :: new( PBind (
140+ PRepeat ( false , PCode ( String :: from( "char(\' a\' )" ) ) . wrap( ) ) . wrap( ) ,
141+ )
142+ . wrap( ) ,
143+ PBind (
146144 String :: from( "b" ) ,
147- Box :: new( PRepeat ( false , Box :: new( PCode ( String :: from( "char(\' b\' )" ) ) ) ) ) ,
148- ) ) ,
145+ PRepeat ( false , PCode ( String :: from( "char(\' b\' )" ) ) . wrap( ) ) . wrap( ) ,
146+ )
147+ . wrap( ) ,
149148 )
150149 ) ,
151- _ => assert_eq ! ( true , false ) ,
150+ _ => panic ! ( ) ,
152151 } ;
153152 }
154153
@@ -160,17 +159,19 @@ mod tests_and {
160159 Success ( ast, _, _) => assert_eq ! (
161160 ast,
162161 PChoice (
163- Box :: new ( PBind (
162+ PBind (
164163 String :: from( "a" ) ,
165- Box :: new( PRepeat ( false , Box :: new( PCode ( String :: from( "char(\' a\' )" ) ) ) ) ) ,
166- ) ) ,
167- Box :: new( PBind (
164+ PRepeat ( false , PCode ( String :: from( "char(\' a\' )" ) ) . wrap( ) ) . wrap( ) ,
165+ )
166+ . wrap( ) ,
167+ PBind (
168168 String :: from( "b" ) ,
169- Box :: new( PRepeat ( false , Box :: new( PCode ( String :: from( "char(\' b\' )" ) ) ) ) ) ,
170- ) ) ,
169+ PRepeat ( false , PCode ( String :: from( "char(\' b\' )" ) ) . wrap( ) ) . wrap( ) ,
170+ )
171+ . wrap( ) ,
171172 )
172173 ) ,
173- _ => assert_eq ! ( true , false ) ,
174+ _ => panic ! ( ) ,
174175 } ;
175176 }
176177
@@ -182,14 +183,11 @@ mod tests_and {
182183 Success ( ast, _, _) => assert_eq ! (
183184 ast,
184185 PMap (
185- Box :: new( PBind (
186- String :: from( "a" ) ,
187- Box :: new( PCode ( String :: from( "char(\' a\' )" ) ) ) ,
188- ) ) ,
186+ PBind ( String :: from( "a" ) , PCode ( String :: from( "char(\' a\' )" ) ) . wrap( ) , ) . wrap( ) ,
189187 String :: from( " Result(a) " ) ,
190188 )
191189 ) ,
192- _ => assert_eq ! ( true , false ) ,
190+ _ => panic ! ( ) ,
193191 } ;
194192 }
195193
@@ -203,17 +201,39 @@ mod tests_and {
203201 Success ( ast, _, _) => assert_eq ! (
204202 ast,
205203 PMap (
206- Box :: new ( PBind (
204+ PBind (
207205 String :: from( "a" ) ,
208- Box :: new ( PMap (
209- Box :: new ( PCode ( String :: from( "char(\' a\' )" ) ) ) ,
206+ PMap (
207+ PCode ( String :: from( "char(\' a\' )" ) ) . wrap ( ) ,
210208 String :: from( " 'a' " )
211- ) ) ,
212- ) ) ,
209+ )
210+ . wrap( ) ,
211+ )
212+ . wrap( ) ,
213213 String :: from( " Result(a) " ) ,
214214 )
215215 ) ,
216- _ => assert_eq ! ( true , false ) ,
216+ _ => panic ! ( ) ,
217+ } ;
218+ }
219+
220+ #[ test]
221+ fn it_parse_epsilon ( ) {
222+ let response = celma_parsec ( ) . parse ( CharStream :: new ( "()" ) ) ;
223+
224+ match response {
225+ Success ( ast, _, _) => assert_eq ! ( ast, PEpsilon ( ) , ) ,
226+ _ => panic ! ( ) ,
227+ } ;
228+ }
229+
230+ #[ test]
231+ fn it_parse_binded_epsilon ( ) {
232+ let response = celma_parsec ( ) . parse ( CharStream :: new ( "a=()" ) ) ;
233+
234+ match response {
235+ Success ( ast, _, _) => assert_eq ! ( ast, PBind ( String :: from( "a" ) , PEpsilon ( ) . wrap( ) ) , ) ,
236+ _ => panic ! ( ) ,
217237 } ;
218238 }
219239}
0 commit comments