Index: test/cctest/parsing/test-scanner-streams.cc |
diff --git a/test/cctest/parsing/test-scanner-streams.cc b/test/cctest/parsing/test-scanner-streams.cc |
index 1bd9dbc7cded7f16fb94ab92650df8f038446ce2..63a095e78d84fc5eff8576757e86f8afc0b4a760 100644 |
--- a/test/cctest/parsing/test-scanner-streams.cc |
+++ b/test/cctest/parsing/test-scanner-streams.cc |
@@ -109,6 +109,49 @@ TEST(Utf8StreamAsciiOnly) { |
} while (c != v8::internal::Utf16CharacterStream::kEndOfInput); |
} |
+TEST(Utf8StreamBOM) { |
+ // Construct test string w/ UTF-8 BOM (byte order mark) |
+ char data[3 + arraysize(unicode_utf8)] = {"\xef\xbb\xbf"}; |
+ strncpy(data + 3, unicode_utf8, arraysize(unicode_utf8)); |
+ |
+ const char* chunks[] = {data, "\0"}; |
+ ChunkSource chunk_source(chunks); |
+ std::unique_ptr<v8::internal::Utf16CharacterStream> stream( |
+ v8::internal::ScannerStream::For( |
+ &chunk_source, v8::ScriptCompiler::StreamedSource::UTF8)); |
+ |
+ // Read the data without tripping over the BOM. |
+ for (size_t i = 0; unicode_ucs2[i]; i++) { |
+ CHECK_EQ(unicode_ucs2[i], stream->Advance()); |
+ } |
+ CHECK_EQ(v8::internal::Utf16CharacterStream::kEndOfInput, stream->Advance()); |
+ |
+ // Make sure seek works. |
+ stream->Seek(0); |
+ CHECK_EQ(unicode_ucs2[0], stream->Advance()); |
+ |
+ stream->Seek(5); |
+ CHECK_EQ(unicode_ucs2[5], stream->Advance()); |
+} |
+ |
+TEST(Utf8SplitBOM) { |
+ // Construct chunks with a BOM split into two chunks. |
+ char partial_bom[] = "\xef\xbb"; |
+ char data[1 + arraysize(unicode_utf8)] = {"\xbf"}; |
marja
2016/09/20 18:52:30
... how paranoid do we want to be, should there al
vogelheim
2016/09/21 07:50:54
Done.
|
+ strncpy(data + 1, unicode_utf8, arraysize(unicode_utf8)); |
+ |
+ const char* chunks[] = {partial_bom, data, "\0"}; |
+ ChunkSource chunk_source(chunks); |
+ std::unique_ptr<v8::internal::Utf16CharacterStream> stream( |
+ v8::internal::ScannerStream::For( |
+ &chunk_source, v8::ScriptCompiler::StreamedSource::UTF8)); |
+ |
+ // Read the data without tripping over the BOM. |
+ for (size_t i = 0; unicode_ucs2[i]; i++) { |
+ CHECK_EQ(unicode_ucs2[i], stream->Advance()); |
+ } |
+} |
+ |
TEST(Utf8ChunkBoundaries) { |
// Test utf-8 parsing at chunk boundaries. |