aboutsummaryrefslogtreecommitdiffhomepage
path: root/js/binary
diff options
context:
space:
mode:
authorGravatar Wojciech Mandrysz <tetek1@gmail.com>2016-10-03 01:42:58 +0200
committerGravatar Wojciech Mandrysz <tetek1@gmail.com>2016-10-03 01:44:15 +0200
commitfe1d0a1f5a32fe144ee125eb0058927d7a359926 (patch)
tree55ed9ed20b6ba2f4c84f204147ebcc05d3d92648 /js/binary
parent23f108d471ec6488efbef1a5b96d7a2abbf785c2 (diff)
JS: Added string encoding/decoding tests for UTF-8
Diffstat (limited to 'js/binary')
-rw-r--r--js/binary/decoder_test.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/js/binary/decoder_test.js b/js/binary/decoder_test.js
index ac312648..12da72a7 100644
--- a/js/binary/decoder_test.js
+++ b/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.