Permalink
Browse files

Add a lot more JSYNC tests

  • Loading branch information...
1 parent afe3086 commit 30e2c2d60f66d4e970f550c04be5008afaddcb42 @sorear committed Nov 15, 2010
Showing with 72 additions and 8 deletions.
  1. +61 −0 t/jsync.data
  2. +11 −8 t/jsync.t
View
@@ -49,4 +49,65 @@
,["WHT008","\u180E[]","","U+180E MONGOLIAN VOWEL SEPARATOR is not space"]
,["WHT009","\u2000[]","","U+2000 EN QUAD is not space"]
,["WHT010","\u3000[]","","U+3000 IDEOGRAPHIC SPACE is not space"]
+,["KWD000","[true]","[\"&A0\",true]","true round trips"]
+,["KWD001","[false]","[\"&A0\",false]","false round trips"]
+,["KWD002","[null]","[\"&A0\",null]","null round trips"]
+,["KWD003","[undef]","","undef is not a keyword"]
+,["KWD004","[fails]","","misspelling keyword after first character caught"]
+,["STR000","[\"\"]","[\"&A0\",\"\"]","empty string is legal"]
+,["STR001","[\"aA0+~\"]","[\"&A0\",\"aA0+~\"]","printable ASCII chars need no escape"]
+,["STR002","[\"\u3081\"]","[\"&A0\",\"\u3081\"]","printable non-ASCII chars not escaped"]
+,["STR003","[\"\uFFFE\"]","[\"&A0\",\"\uFFFE\"]","nonprintable characters above 256 also raw"]
+,["STR004","[\"\\uFFFE\"]","[\"&A0\",\"\uFFFE\"]","\\u escape can encode Unicode chars"]
+,["STR005","[\"\\u000A\"]","[\"&A0\",\"\\n\"]","000A returns as n"]
+,["STR006","[\"\\u000D\"]","[\"&A0\",\"\\r\"]","000D returns as r"]
+,["STR007","[\"\\u0008\"]","[\"&A0\",\"\\b\"]","0008 returns as b"]
+,["STR008","[\"\\u000C\"]","[\"&A0\",\"\\f\"]","000C returns as f"]
+,["STR009","[\"\\u0009\"]","[\"&A0\",\"\\t\"]","0009 returns as t"]
+,["STR010","[\"\\u0022\"]","[\"&A0\",\"\\\"\"]","0022 returns as \\\""]
+,["STR011","[\"\\u005C\"]","[\"&A0\",\"\\\\\"]","005C returns as \\\\"]
+,["STR012","[\"\\u0019\"]","[\"&A0\",\"\\u0019\"]","Other C0 return as Unicode escape"]
+,["STR013","[\"\\u0099\"]","[\"&A0\",\"\\u0099\"]","Other C1 return as Unicode escape"]
+,["STR014","[\"\\u0041\"]","[\"&A0\",\"A\"]","Printables return verbatim"]
+,["STR015","[\"\\b\"]","[\"&A0\",\"\\b\"]","\\b round trips"]
+,["STR016","[\"\\f\"]","[\"&A0\",\"\\f\"]","\\f round trips"]
+,["STR017","[\"\\n\"]","[\"&A0\",\"\\n\"]","\\n round trips"]
+,["STR018","[\"\\r\"]","[\"&A0\",\"\\r\"]","\\r round trips"]
+,["STR020","[\"\\t\"]","[\"&A0\",\"\\t\"]","\\t round trips"]
+,["STR021","[\"\\\\\"]","[\"&A0\",\"\\\\\"]","\\\\ round trips"]
+,["STR022","[\"\\\"\"]","[\"&A0\",\"\\\"\"]","\\\" round trips"]
+,["STR023","[\"\\/\"]","[\"&A0\",\"/\"]","\\/ returns as verbatim char"]
+,["STR024","[\".&\"]","[\"&A0\",\".&\"]",".& stuffing round trip"]
+,["STR025","[\".*\"]","[\"&A0\",\".*\"]",".* stuffing round trip"]
+,["STR026","[\".!\"]","[\"&A0\",\".!\"]",".! stuffing round trip"]
+,["STR027","[\".%\"]","[\"&A0\",\".%\"]",".% stuffing round trip"]
+,["STR028","[\"..&\"]","[\"&A0\",\"..&\"]","..& stuffing round trip"]
+,["STR029","[\"..*\"]","[\"&A0\",\"..*\"]","..* stuffing round trip"]
+,["STR030","[\"..!\"]","[\"&A0\",\"..!\"]","..! stuffing round trip"]
+,["STR031","[\"..%\"]","[\"&A0\",\"..%\"]","..% stuffing round trip"]
+,["STR032","[\".1\"]","[\"&A0\",\".1\"]",".1 non-stuffing round trip"]
+,["STR033","[\".@\"]","[\"&A0\",\".@\"]",".@ non-stuffing round trip"]
+,["SEQ000","[]","[\"&A0\"]","Array with no elements is legal"]
+,["SEQ001","[ ]","[\"&A0\"]","Can put whitespace inside"]
+,["SEQ002","[1]","[\"&A0\",1]","One element works"]
+,["SEQ003","[1,2,3]","[\"&A0\",1,2,3]","Multiple elements work"]
+,["SEQ004","[1,2,3,]","","Trailing comma illegal"]
+,["SEQ005","[,]","","Comma in empty list illegal"]
+,["SEQ006","[\"&A99\"]","[\"&A0\"]","Custom anchors supported"]
+,["SEQ007","[\"&Flue\"]","[\"&A0\"]","Anchors can have any letter form"]
+,["SEQ008","[\"&A-B\"]","","Punctuated anchors illegal"]
+,["SEQ009","[[1,2],[3,4]]","[\"&A0\",[\"&A1\",1,2],[\"&A2\",3,4]]","Nested arrays legal"]
+,["ANC000","[[\"&A\",1,2],\"*A\"]","[\"&A0\",[\"&A1\",1,2],\"*A1\"]","Anchors may be used for substructure"]
+,["ANC001","[[\"&A\",1,2],\"*A\",\"*A\"]","[\"&A0\",[\"&A1\",1,2],\"*A1\",\"*A1\"]","Anchors may be used for substructure more than once"]
+,["ANC002","[\"*B\",[\"&B\",1,2]]","[\"&A0\",[\"&A1\",1,2],\"*A1\"]","Anchors may be used before definition"]
+,["ANC003","[\"*Moo\"]","","Undefined anchors may not be used"]
+,["ANC004","[\"&A\",\"*A\"]","[\"&A0\",\"*A0\"]","Arrays may be recursive"]
+,["ANC005","[\"&A\",\"*a\"]","","Anchors are case sensitive"]
+,["ANC006","{\"&\":\"A\",\"r\":\"*A\"}","{\"&\":\"A0\",\"r\":\"*A0\"}","Hashes may be recursive"]
+,["ANC007","{\"r\":\"*A\",\"&\":\"A\"}","{\"&\":\"A0\",\"r\":\"*A0\"}","Hashes may be recursive even if anchor at end"]
+,["MAP000","{}","{\"&\":\"A0\"}","Empty map is legal"]
+,["MAP001","{\"a\",\"b\"}","",", cannot substitute for :"]
+,["MAP002","{\"a\":1,\"b\":2}","{\"&\":\"A0\",\"a\":1,\"b\":2}","Non-empty maps legal"]
+,["MAP003","{\"a\":\"b\",}","","Trailing commas in maps not legal"]
+,["MAP004","{\"&\":\"Foo bar\"}","","Map anchors may not have spaces"]
]
View
@@ -8,13 +8,16 @@ class Bob { has $.abc; has $.def };
# Test set 1: proper rendering of native data types
-sub t1($obj,$jsync,$name) {
- my $r = to-jsync($obj);
- if $r ne $jsync {
- say "# got : $r";
- say "# want: $jsync";
+sub myis($a,$b,$name) {
+ if $a ne $b {
+ say "# got : $a";
+ say "# want: $b";
}
- is $r, $jsync, $name;
+ is $a, $b, $name;
+}
+
+sub t1($obj,$jsync,$name) {
+ myis to-jsync($obj), $jsync, $name;
}
sub t2($obj,$jsync,$name) { t1($obj, '[{"%JSYNC":"1.0"},' ~ $jsync ~ ']', $name) }
@@ -68,11 +71,11 @@ for @$data -> $vector {
my $result = "";
try { $result = to-jsync(from-jsync($text)) }
- if $result eq "" {
+ if $result eq "" && $canon ne "" {
say "# $!";
}
- is $result, $canon, "($id) $comment";
+ myis $result, $canon, "($id) $comment";
}
done-testing;

0 comments on commit 30e2c2d

Please sign in to comment.