-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support to BOM at the beginning of the stream
- Loading branch information
1 parent
cda44fb
commit a4e71c6
Showing
7 changed files
with
240 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import JSONParser from "../src/jsonparser.js"; | ||
import { runJSONParserTest } from "./utils/testRunner.js"; | ||
|
||
describe("BOM", () => { | ||
test("should support UTF-8 BOM", () => { | ||
runJSONParserTest( | ||
new JSONParser(), | ||
new Uint8Array([0xef, 0xbb, 0xbf, 0x31]), | ||
({ value }) => expect(value).toBe(1), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import JSONParser from "../src/jsonparser.js"; | ||
import { runJSONParserTest } from "./utils/testRunner.js"; | ||
|
||
describe("BOM", () => { | ||
test("should support UTF-8 BOM", () => { | ||
runJSONParserTest( | ||
new JSONParser(), | ||
new Uint8Array([0xef, 0xbb, 0xbf, 0x31]), | ||
({ value }) => expect(value).toBe(1), | ||
); | ||
}); | ||
|
||
test("should support UTF-16 BE BOM", () => { | ||
runJSONParserTest( | ||
new JSONParser(), | ||
new Uint16Array([0xfeff, 0x3131]), | ||
({ value }) => expect(value).toBe(11), | ||
); | ||
}); | ||
|
||
test("should support UTF-16 LE BOM", () => { | ||
runJSONParserTest( | ||
new JSONParser(), | ||
new Uint16Array([0xfffe, 0x3131]), | ||
({ value }) => expect(value).toBe(11), | ||
); | ||
}); | ||
|
||
test("should support UTF-32 BE BOM", () => { | ||
runJSONParserTest( | ||
new JSONParser(), | ||
new Uint32Array([0x0000feff, 0x31313131]), | ||
({ value }) => expect(value).toBe(1111), | ||
); | ||
}); | ||
|
||
test("should support UTF-32 LE BOM", () => { | ||
runJSONParserTest( | ||
new JSONParser(), | ||
new Uint32Array([0xfffe0000, 0x31313131]), | ||
({ value }) => expect(value).toBe(1111), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import JSONParser from "../src/jsonparser.js"; | ||
import { runJSONParserTest } from "./utils/testRunner.js"; | ||
|
||
describe("BOM", () => { | ||
test("should support UTF-8 BOM", () => { | ||
runJSONParserTest( | ||
new JSONParser(), | ||
new Uint8Array([0xef, 0xbb, 0xbf, 0x31]), | ||
({ value }) => expect(value).toBe(1), | ||
); | ||
}); | ||
|
||
test("should support UTF-16 BE BOM", () => { | ||
runJSONParserTest( | ||
new JSONParser(), | ||
new Uint16Array([0xfeff, 0x3131]), | ||
({ value }) => expect(value).toBe(11), | ||
); | ||
}); | ||
|
||
test("should support UTF-16 LE BOM", () => { | ||
runJSONParserTest( | ||
new JSONParser(), | ||
new Uint16Array([0xfffe, 0x3131]), | ||
({ value }) => expect(value).toBe(11), | ||
); | ||
}); | ||
|
||
// test("should support UTF-32 BE BOM", () => { | ||
// runJSONParserTest( | ||
// new JSONParser(), | ||
// new Uint32Array([0x0000feff, 0x31313131]), | ||
// ({ value }) => expect(value).toBe(1111), | ||
// ); | ||
// }); | ||
|
||
// test("should support UTF-32 LE BOM", () => { | ||
// runJSONParserTest( | ||
// new JSONParser(), | ||
// new Uint32Array([0xfffe0000, 0x31313131]), | ||
// ({ value }) => expect(value).toBe(1111), | ||
// ); | ||
// }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters