@@ -5,40 +5,55 @@ class BertTest < Test::Unit::TestCase
55 setup do
66 time = Time . at ( 1254976067 )
77 @ruby = t [ :user , { :name => 'TPW' } , [ /cat/i , 9.9 ] , time , nil , true , false , :true , :false ]
8- @bert = "\x84 h\t d\x00 \x04 userh\x03 d\x00 \x04 bertd\x00 \x04 dictl\x00 \x00 \x00 \x01 h\x02 d\x00 \x04 namem\x00 \x00 \x00 \x03 TPWm\x00 \x00 \x00 \x05 UTF-8jl\x00 \x00 \x00 \x02 h\x04 d\x00 \x04 bertd\x00 \x05 regexm\x00 \x00 \x00 \x03 catm\x00 \x00 \x00 \b US-ASCIIl\x00 \x00 \x00 \x01 d\x00 \b caselessjc9.900000000000000e+00\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 jh\x05 d\x00 \x04 bertd\x00 \x04 timeb\x00 \x00 \x04 \xE6 b\x00 \x0E \xE4 \xC3 a\x00 h\x02 d\x00 \x04 bertd\x00 \x03 nilh\x02 d\x00 \x04 bertd\x00 \x04 trueh\x02 d\x00 \x04 bertd\x00 \x05 falsed\x00 \x04 trued\x00 \x05 false" . b
98 @bert_old = "\203 h\t d\000 \004 userh\003 d\000 \004 bertd\000 \004 dictl\000 \000 \000 \001 h\002 d\000 \004 namem\000 \000 \000 \003 TPWjl\000 \000 \000 \002 h\004 d\000 \004 bertd\000 \005 regexm\000 \000 \000 \003 catl\000 \000 \000 \001 d\000 \b caselessjc9.900000000000000e+00\000 \000 \000 \000 \000 \000 \000 \000 \000 \000 jh\005 d\000 \004 bertd\000 \004 timeb\000 \000 \004 \346 b\000 \016 \344 \303 a\000 h\002 d\000 \004 bertd\000 \003 nilh\002 d\000 \004 bertd\000 \004 trueh\002 d\000 \004 bertd\000 \005 falsed\000 \004 trued\000 \005 false" . b
10- @ebin = "<<132,104,9,100,0,4,117,115,101,114,104,3,100,0,4,98,101,114,116,100,0,4,100,105,99,116,108,0,0,0,1,104,2,100,0,4,110,97,109,101,109,0,0,0,3,84,80,87,109,0,0,0,5,85,84,70,45,56,106,108,0,0,0,2,104,4,100,0,4,98,101,114,116,100,0,5,114,101,103,101,120,109,0,0,0,3,99,97,116,109,0,0,0,8,85,83,45,65,83,67,73,73,108,0,0,0,1,100,0,8,99,97,115,101,108,101,115,115,106,99,57,46,57,48,48,48,48,48,48,48,48,48,48,48,48,48,48,101,43,48,48,0,0,0,0,0,0,0,0,0,0,106,104,5,100,0,4,98,101,114,116,100,0,4,116,105,109,101,98,0,0,4,230,98,0,14,228,195,97,0,104,2,100,0,4,98,101,114,116,100,0,3,110,105,108,104,2,100,0,4,98,101,114,116,100,0,4,116,114,117,101,104,2,100,0,4,98,101,114,116,100,0,5,102,97,108,115,101,100,0,4,116,114,117,101,100,0,5,102,97,108,115,101>>"
119 @ebin_old = "<<131,104,9,100,0,4,117,115,101,114,104,3,100,0,4,98,101,114,116,100,0,4,100,105,99,116,108,0,0,0,1,104,2,100,0,4,110,97,109,101,109,0,0,0,3,84,80,87,106,108,0,0,0,2,104,4,100,0,4,98,101,114,116,100,0,5,114,101,103,101,120,109,0,0,0,3,99,97,116,108,0,0,0,1,100,0,8,99,97,115,101,108,101,115,115,106,99,57,46,57,48,48,48,48,48,48,48,48,48,48,48,48,48,48,101,43,48,48,0,0,0,0,0,0,0,0,0,0,106,104,5,100,0,4,98,101,114,116,100,0,4,116,105,109,101,98,0,0,4,230,98,0,14,228,195,97,0,104,2,100,0,4,98,101,114,116,100,0,3,110,105,108,104,2,100,0,4,98,101,114,116,100,0,4,116,114,117,101,104,2,100,0,4,98,101,114,116,100,0,5,102,97,108,115,101,100,0,4,116,114,117,101,100,0,5,102,97,108,115,101>>"
1210 end
1311
14- should "decode the old format" do
15- assert_equal @ruby , BERT . decode ( @bert_old )
16- end
12+ context "v2 encoder" do
13+ setup do
14+ @old_version = BERT ::Encode . version
15+ BERT ::Encode . version = :v2
16+ @bert = "\x84 h\t d\x00 \x04 userh\x03 d\x00 \x04 bertd\x00 \x04 dictl\x00 \x00 \x00 \x01 h\x02 d\x00 \x04 namem\x00 \x00 \x00 \x03 TPWm\x00 \x00 \x00 \x05 UTF-8jl\x00 \x00 \x00 \x02 h\x04 d\x00 \x04 bertd\x00 \x05 regexm\x00 \x00 \x00 \x03 catm\x00 \x00 \x00 \b US-ASCIIl\x00 \x00 \x00 \x01 d\x00 \b caselessjc9.900000000000000e+00\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 jh\x05 d\x00 \x04 bertd\x00 \x04 timeb\x00 \x00 \x04 \xE6 b\x00 \x0E \xE4 \xC3 a\x00 h\x02 d\x00 \x04 bertd\x00 \x03 nilh\x02 d\x00 \x04 bertd\x00 \x04 trueh\x02 d\x00 \x04 bertd\x00 \x05 falsed\x00 \x04 trued\x00 \x05 false" . b
17+ @ebin = "<<132,104,9,100,0,4,117,115,101,114,104,3,100,0,4,98,101,114,116,100,0,4,100,105,99,116,108,0,0,0,1,104,2,100,0,4,110,97,109,101,109,0,0,0,3,84,80,87,109,0,0,0,5,85,84,70,45,56,106,108,0,0,0,2,104,4,100,0,4,98,101,114,116,100,0,5,114,101,103,101,120,109,0,0,0,3,99,97,116,109,0,0,0,8,85,83,45,65,83,67,73,73,108,0,0,0,1,100,0,8,99,97,115,101,108,101,115,115,106,99,57,46,57,48,48,48,48,48,48,48,48,48,48,48,48,48,48,101,43,48,48,0,0,0,0,0,0,0,0,0,0,106,104,5,100,0,4,98,101,114,116,100,0,4,116,105,109,101,98,0,0,4,230,98,0,14,228,195,97,0,104,2,100,0,4,98,101,114,116,100,0,3,110,105,108,104,2,100,0,4,98,101,114,116,100,0,4,116,114,117,101,104,2,100,0,4,98,101,114,116,100,0,5,102,97,108,115,101,100,0,4,116,114,117,101,100,0,5,102,97,108,115,101>>"
18+ end
1719
18- should "roundtrip string and maintain encoding" do
19- str = "日本語" . encode 'EUC-JP'
20- round = BERT . decode ( BERT . encode ( str ) )
21- assert_equal str , round
22- assert_equal str . encoding , round . encoding
23- end
20+ teardown do
21+ BERT ::Encode . version = @old_version
22+ end
2423
25- should "roundtrip binary string" do
26- str = "日本語" . b
27- round = BERT . decode ( BERT . encode ( str ) )
28- assert_equal str , round
29- assert_equal str . encoding , round . encoding
30- end
24+ should "decode new format" do
25+ assert_equal @ruby , BERT . decode ( @bert )
26+ end
3127
32- should "encode" do
33- assert_equal @bert , BERT . encode ( @ruby )
28+ should "roundtrip string and maintain encoding" do
29+ str = "日本語" . encode 'EUC-JP'
30+ round = BERT . decode ( BERT . encode ( str ) )
31+ assert_equal str , round
32+ assert_equal str . encoding , round . encoding
33+ end
34+
35+ should "roundtrip binary string" do
36+ str = "日本語" . b
37+ round = BERT . decode ( BERT . encode ( str ) )
38+ assert_equal str , round
39+ assert_equal str . encoding , round . encoding
40+ end
41+
42+ should "encode" do
43+ assert_equal @bert , BERT . encode ( @ruby )
44+ end
45+
46+ should "ebin" do
47+ assert_equal @ebin , BERT . ebin ( @bert )
48+ end
3449 end
3550
36- should "decode" do
37- assert_equal @ruby , BERT . decode ( @bert )
51+ should "decode the old format " do
52+ assert_equal @ruby , BERT . decode ( @bert_old )
3853 end
3954
4055 should "ebin" do
41- assert_equal @ebin , BERT . ebin ( @bert )
56+ assert_equal @ebin_old , BERT . ebin ( @bert_old )
4257 end
4358
4459 should "do roundtrips" do
0 commit comments