@@ -800,7 +800,7 @@ make_parser!(
800
800
mod tests {
801
801
use super :: * ;
802
802
use ast:: * ;
803
- use combine:: { State , Parser } ;
803
+ use combine:: { State , Parser , many , value } ;
804
804
805
805
use std:: collections:: HashMap ;
806
806
@@ -838,10 +838,17 @@ mod tests {
838
838
assert_successful_parse ! ( NameParser , "Zasd" , String :: from( "Zasd" ) ) ;
839
839
}
840
840
841
+ #[ test]
842
+ fn test_parse_ignore ( ) {
843
+ assert_successful_parse ! ( value( ( ) ) . skip( ignore_parser!( ) ) , "# hello world\r \n \r \n " , ( ) ) ;
844
+ }
845
+
841
846
// ===========================================================================
842
847
// 2.2 Document Tests
843
848
// ===========================================================================
844
849
850
+ // TODO
851
+
845
852
// ===========================================================================
846
853
// 2.3 Operation Tests
847
854
// ===========================================================================
@@ -1154,13 +1161,51 @@ mod tests {
1154
1161
}
1155
1162
1156
1163
#[ test]
1157
- fn test_parse_const_listvalue ( ) {
1158
- assert_successful_parse ! ( ListValue :: new( & true ) ,
1159
- "[null]" ,
1160
- Value :: List ( vec![ Value :: Null ] ) ) ;
1161
- assert_successful_parse ! ( ListValue :: new( & true ) ,
1162
- "[null true false]" ,
1163
- Value :: List ( vec![ Value :: Null , Value :: Boolean ( true ) , Value :: Boolean ( false ) ] ) ) ;
1164
+ fn test_parse_booleanvalue ( ) {
1165
+ assert_successful_parse ! ( BooleanValue , "true" , Value :: Boolean ( true ) ) ;
1166
+ assert_successful_parse ! ( BooleanValue , "false" , Value :: Boolean ( false ) ) ;
1167
+ }
1168
+
1169
+
1170
+ #[ test]
1171
+ fn test_parse_string_unicodeescape ( ) {
1172
+ // unicode string
1173
+ assert_successful_parse ! ( StringValue , r#""\u0025""# , Value :: String ( String :: from( "%" ) ) ) ;
1174
+ assert_successful_parse ! ( StringValue , r#""\u0040""# , Value :: String ( String :: from( "@" ) ) ) ;
1175
+ }
1176
+
1177
+ #[ test]
1178
+ fn test_parse_string_escaped ( ) {
1179
+ assert_successful_parse ! ( StringValue , r#""\"""# , Value :: String ( String :: from( "\" " ) ) ) ;
1180
+ assert_successful_parse ! ( StringValue , r#""\\""# , Value :: String ( String :: from( "\\ " ) ) ) ;
1181
+ assert_successful_parse ! ( StringValue , r#""\/""# , Value :: String ( String :: from( "/" ) ) ) ;
1182
+ assert_successful_parse ! ( StringValue , r#""\b""# , Value :: String ( String :: from( "\x08 " ) ) ) ;
1183
+ assert_successful_parse ! ( StringValue , r#""\f""# , Value :: String ( String :: from( "\x0C " ) ) ) ;
1184
+ assert_successful_parse ! ( StringValue , r#""\n""# , Value :: String ( String :: from( "\n " ) ) ) ;
1185
+ assert_successful_parse ! ( StringValue , r#""\r""# , Value :: String ( String :: from( "\r " ) ) ) ;
1186
+ assert_successful_parse ! ( StringValue , r#""\t""# , Value :: String ( String :: from( "\t " ) ) ) ;
1187
+ }
1188
+
1189
+ #[ test]
1190
+ fn test_parse_stringvalue ( ) {
1191
+ // empty string
1192
+ assert_successful_parse ! ( StringValue , r#""""# , Value :: String ( String :: from( "" ) ) ) ;
1193
+
1194
+ // strings with random stuff in it
1195
+ assert_successful_parse ! ( StringValue ,
1196
+ r#""hello world""# ,
1197
+ Value :: String ( String :: from( "hello world" ) ) ) ;
1198
+ assert_successful_parse ! ( StringValue ,
1199
+ r#""hello \u0025""# ,
1200
+ Value :: String ( String :: from( "hello %" ) ) ) ;
1201
+ assert_successful_parse ! ( StringValue ,
1202
+ r#""hello\n\u0025""# ,
1203
+ Value :: String ( String :: from( "hello\n %" ) ) ) ;
1204
+ }
1205
+
1206
+ #[ test]
1207
+ fn test_parse_nullvalue ( ) {
1208
+ assert_successful_parse ! ( NullValue , "null" , Value :: Null ) ;
1164
1209
}
1165
1210
1166
1211
#[ test]
@@ -1202,6 +1247,16 @@ mod tests {
1202
1247
}
1203
1248
}
1204
1249
1250
+ #[ test]
1251
+ fn test_parse_listvalue ( ) {
1252
+ assert_successful_parse ! ( ListValue :: new( & true ) ,
1253
+ "[null]" ,
1254
+ Value :: List ( vec![ Value :: Null ] ) ) ;
1255
+ assert_successful_parse ! ( ListValue :: new( & true ) ,
1256
+ "[null true false]" ,
1257
+ Value :: List ( vec![ Value :: Null , Value :: Boolean ( true ) , Value :: Boolean ( false ) ] ) ) ;
1258
+ }
1259
+
1205
1260
#[ test]
1206
1261
fn test_parse_enumvalue_successful ( ) {
1207
1262
assert_successful_parse ! ( EnumValue , "test" , Value :: Enum ( String :: from( "test" ) ) ) ;
@@ -1221,47 +1276,16 @@ mod tests {
1221
1276
assert_successful_parse ! ( ObjectValue :: new( & true ) , "{ x : 1 }" , value) ;
1222
1277
}
1223
1278
1224
- #[ test]
1225
- fn test_parse_string_unicodeescape ( ) {
1226
- // unicode string
1227
- assert_successful_parse ! ( StringValue , r#""\u0025""# , Value :: String ( String :: from( "%" ) ) ) ;
1228
- assert_successful_parse ! ( StringValue , r#""\u0040""# , Value :: String ( String :: from( "@" ) ) ) ;
1229
- }
1230
-
1231
- #[ test]
1232
- fn test_parse_string_escaped ( ) {
1233
- assert_successful_parse ! ( StringValue , r#""\"""# , Value :: String ( String :: from( "\" " ) ) ) ;
1234
- assert_successful_parse ! ( StringValue , r#""\\""# , Value :: String ( String :: from( "\\ " ) ) ) ;
1235
- assert_successful_parse ! ( StringValue , r#""\/""# , Value :: String ( String :: from( "/" ) ) ) ;
1236
- assert_successful_parse ! ( StringValue , r#""\b""# , Value :: String ( String :: from( "\x08 " ) ) ) ;
1237
- assert_successful_parse ! ( StringValue , r#""\f""# , Value :: String ( String :: from( "\x0C " ) ) ) ;
1238
- assert_successful_parse ! ( StringValue , r#""\n""# , Value :: String ( String :: from( "\n " ) ) ) ;
1239
- assert_successful_parse ! ( StringValue , r#""\r""# , Value :: String ( String :: from( "\r " ) ) ) ;
1240
- assert_successful_parse ! ( StringValue , r#""\t""# , Value :: String ( String :: from( "\t " ) ) ) ;
1241
- }
1242
-
1243
- #[ test]
1244
- fn test_parse_stringvalue ( ) {
1245
- // empty string
1246
- assert_successful_parse ! ( StringValue , r#""""# , Value :: String ( String :: from( "" ) ) ) ;
1247
-
1248
- // strings with random stuff in it
1249
- assert_successful_parse ! ( StringValue ,
1250
- r#""hello world""# ,
1251
- Value :: String ( String :: from( "hello world" ) ) ) ;
1252
- assert_successful_parse ! ( StringValue ,
1253
- r#""hello \u0025""# ,
1254
- Value :: String ( String :: from( "hello %" ) ) ) ;
1255
- assert_successful_parse ! ( StringValue ,
1256
- r#""hello\n\u0025""# ,
1257
- Value :: String ( String :: from( "hello\n %" ) ) ) ;
1258
- }
1259
-
1260
1279
// ===========================================================================
1261
1280
// 2.10 Variables Tests
1262
1281
// ===========================================================================
1263
1282
#[ test]
1264
- fn test_parse_variabledefinition_nodefaultvalue ( ) {
1283
+ fn test_parse_variable ( ) {
1284
+ assert_successful_parse ! ( ValueParser :: new( & false ) , "$var" , Value :: Variable ( String :: from( "var" ) ) ) ;
1285
+ }
1286
+
1287
+ #[ test]
1288
+ fn test_parse_variabledefinition ( ) {
1265
1289
assert_successful_parse ! ( VariableDefinitionParser ,
1266
1290
"$devicePicSize: Int" ,
1267
1291
VariableDefinition :: new( String :: from( "devicePicSize" ) ,
@@ -1284,6 +1308,8 @@ mod tests {
1284
1308
Some ( Value :: Float ( 1.0 ) ) ) ) ;
1285
1309
}
1286
1310
1311
+ // TODO variable definitions
1312
+
1287
1313
// ===========================================================================
1288
1314
// 2.11 Type Tests
1289
1315
// ===========================================================================
0 commit comments