|
|
@ -210,6 +210,29 @@ describe('binaryDecoderTest', function() { |
|
|
|
assertEquals(hashD, decoder.readFixedHash64()); |
|
|
|
assertEquals(hashD, decoder.readFixedHash64()); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Test encoding and decoding utf-8. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
it('testUtf8', function() { |
|
|
|
|
|
|
|
var encoder = new jspb.BinaryEncoder(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ascii = "ASCII should work in 3, 2, 1..." |
|
|
|
|
|
|
|
var utf8_two_bytes = "©"; |
|
|
|
|
|
|
|
var utf8_tree_bytes = "❄"; |
|
|
|
|
|
|
|
var utf8_four_bytes = "😁"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
encoder.writeString(ascii); |
|
|
|
|
|
|
|
encoder.writeString(utf8_two_bytes); |
|
|
|
|
|
|
|
encoder.writeString(utf8_tree_bytes); |
|
|
|
|
|
|
|
encoder.writeString(utf8_four_bytes); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var decoder = jspb.BinaryDecoder.alloc(encoder.end()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(ascii, decoder.readString(ascii.length)); |
|
|
|
|
|
|
|
assertEquals(utf8_two_bytes, decoder.readString(utf8_two_bytes.length)); |
|
|
|
|
|
|
|
assertEquals(utf8_tree_bytes, decoder.readString(utf8_tree_bytes.length)); |
|
|
|
|
|
|
|
assertEquals(utf8_four_bytes, decoder.readString(utf8_four_bytes.length)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Verifies that misuse of the decoder class triggers assertions. |
|
|
|
* Verifies that misuse of the decoder class triggers assertions. |
|
|
|