| 
33 | 33 |   context "numbers" do  | 
34 | 34 |     # Sample based  | 
35 | 35 |     {  | 
36 |  | -      0           => "\x02\x01\x00",   | 
37 |  | -      1           => "\x02\x01\x01",   | 
38 |  | -      127         => "\x02\x01\x7F",   | 
39 |  | -      128         => "\x02\x01\x80",   | 
40 |  | -      255         => "\x02\x01\xFF",   | 
41 |  | -      256         => "\x02\x02\x01\x00",   | 
42 |  | -      65535       => "\x02\x02\xFF\xFF",   | 
43 |  | -      65536       => "\x02\x03\x01\x00\x00",   | 
44 |  | -      16_777_215  => "\x02\x03\xFF\xFF\xFF",   | 
45 |  | -      0x01000000  => "\x02\x04\x01\x00\x00\x00",   | 
46 |  | -      0x3FFFFFFF  => "\x02\x04\x3F\xFF\xFF\xFF",   | 
47 |  | -      0x4FFFFFFF  => "\x02\x04\x4F\xFF\xFF\xFF",   | 
48 |  | -        | 
 | 36 | +      0           => raw_string("\x02\x01\x00"),  | 
 | 37 | +      1           => raw_string("\x02\x01\x01"),  | 
 | 38 | +      127         => raw_string("\x02\x01\x7F"),  | 
 | 39 | +      128         => raw_string("\x02\x01\x80"),  | 
 | 40 | +      255         => raw_string("\x02\x01\xFF"),  | 
 | 41 | +      256         => raw_string("\x02\x02\x01\x00"),  | 
 | 42 | +      65535       => raw_string("\x02\x02\xFF\xFF"),  | 
 | 43 | +      65536       => raw_string("\x02\x03\x01\x00\x00"),  | 
 | 44 | +      16_777_215  => raw_string("\x02\x03\xFF\xFF\xFF"),  | 
 | 45 | +      0x01000000  => raw_string("\x02\x04\x01\x00\x00\x00"),  | 
 | 46 | +      0x3FFFFFFF  => raw_string("\x02\x04\x3F\xFF\xFF\xFF"),  | 
 | 47 | +      0x4FFFFFFF  => raw_string("\x02\x04\x4F\xFF\xFF\xFF"),  | 
 | 48 | + | 
49 | 49 |       # Some odd samples...  | 
50 |  | -      5           => "\002\001\005",   | 
51 |  | -      500         => "\002\002\001\364",   | 
52 |  | -      50_000      => "\x02\x02\xC3P",   | 
53 |  | -      5_000_000_000  => "\002\005\001*\005\362\000"  | 
54 |  | -    }.each do |number, expected_encoding|   | 
 | 50 | +      5           => raw_string("\002\001\005"),  | 
 | 51 | +      500         => raw_string("\002\002\001\364"),  | 
 | 52 | +      50_000      => raw_string("\x02\x02\xC3P"),  | 
 | 53 | +      5_000_000_000  => raw_string("\002\005\001*\005\362\000")  | 
 | 54 | +    }.each do |number, expected_encoding|  | 
55 | 55 |       it "should encode #{number} as #{expected_encoding.inspect}" do  | 
56 | 56 |         number.to_ber.should == expected_encoding  | 
57 |  | -      end   | 
 | 57 | +      end  | 
58 | 58 |     end  | 
59 | 59 | 
 
  | 
60 | 60 |     # Round-trip encoding: This is mostly to be sure to cover Bignums well.  | 
 | 
79 | 79 |     context "strings" do  | 
80 | 80 |       it "should properly encode UTF-8 strings" do  | 
81 | 81 |         "\u00e5".force_encoding("UTF-8").to_ber.should ==  | 
82 |  | -          "\x04\x02\xC3\xA5"  | 
 | 82 | +          raw_string("\x04\x02\xC3\xA5")  | 
83 | 83 |       end  | 
84 | 84 |       it "should properly encode strings encodable as UTF-8" do  | 
85 | 85 |         "teststring".encode("US-ASCII").to_ber.should == "\x04\nteststring"  | 
86 | 86 |       end  | 
87 | 87 | 			it "should properly encode binary data strings using to_ber_bin" do  | 
88 | 88 | 				# This is used for searching for GUIDs in Active Directory  | 
89 | 89 | 				["6a31b4a12aa27a41aca9603f27dd5116"].pack("H*").to_ber_bin.should ==   | 
90 |  | -					"\x04\x10" + "j1\xB4\xA1*\xA2zA\xAC\xA9`?'\xDDQ\x16"  | 
 | 90 | +					raw_string("\x04\x10" + "j1\xB4\xA1*\xA2zA\xAC\xA9`?'\xDDQ\x16")  | 
91 | 91 | 			end  | 
92 | 92 |       it "should not fail on strings that can not be converted to UTF-8" do  | 
93 | 93 |         error = Encoding::UndefinedConversionError  | 
 | 
0 commit comments