JS: Added string encoding/decoding tests for UTF-8

pull/1907/head
Wojciech Mandrysz 8 years ago
parent 23f108d471
commit fe1d0a1f5a
  1. 23
      js/binary/decoder_test.js

@ -209,7 +209,30 @@ describe('binaryDecoderTest', function() {
assertEquals(hashC, 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.

Loading…
Cancel
Save