From 684acffd19dba9d70fd063408e62da01dcdd562d Mon Sep 17 00:00:00 2001 From: Tingan Ho Date: Mon, 27 Jul 2015 19:52:25 +0800 Subject: [PATCH] Adds JSON with comments and trailing comma tests --- .../jsonWithCommentsAndTrailingCommas.ts | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/cases/unittests/jsonWithCommentsAndTrailingCommas.ts diff --git a/tests/cases/unittests/jsonWithCommentsAndTrailingCommas.ts b/tests/cases/unittests/jsonWithCommentsAndTrailingCommas.ts new file mode 100644 index 00000000000..2a3304e9bab --- /dev/null +++ b/tests/cases/unittests/jsonWithCommentsAndTrailingCommas.ts @@ -0,0 +1,72 @@ +/// +/// + +module ts { + describe("JSON with comments and trailing commas", () => { + it("should parse JSON with single line comments @jsonWithCommentsAndTrailingCommas", () => { + let json = +`{ + "a": { + // comment + "b": true + } +}`; + expect(parseConfigFileText("file.ts", json).config).to.be.deep.equal({ + a: { b: true } + }); + }); + + + it("should parse JSON with multiline line comments @jsonWithCommentsAndTrailingCommas", () => { + let json = +`{ + "a": { + /* + * comment + */ + "b": true + } +}`; + expect(parseConfigFileText("file.ts", json).config).to.be.deep.equal({ + a: { b: true } + }); + }); + + it("should parse JSON with trailing commas in an object @jsonWithCommentsAndTrailingCommas", () => { + let json = +`{ + "a": { + "b": true, + } +}`; + expect(parseConfigFileText("file.ts", json).config).to.be.deep.equal({ + a: { b: true } + }); + }); + + it("should parse JSON with trailing commas in an array @jsonWithCommentsAndTrailingCommas", () => { + let json = +`{ + "a": [ + "b", + ] +}`; + expect(parseConfigFileText("file.ts", json).config).to.be.deep.equal({ + a: [ "b" ] + }); + }); + + it("should parse JSON with escape characters @jsonWithCommentsAndTrailingCommas", () => { + let json = +`{ + "a": [ + "b\\\"\\\\", + ] +}`; + expect(parseConfigFileText("file.ts", json).config).to.be.deep.equal({ + a: [ "b\"\\" ] + }); + }); + }); +} +