diff --git a/lsp/src/typescript-blocks.test.ts b/lsp/src/typescript-blocks.test.ts index 63698670..29901206 100644 --- a/lsp/src/typescript-blocks.test.ts +++ b/lsp/src/typescript-blocks.test.ts @@ -169,6 +169,29 @@ describe("extractTypeScriptBlocks", () => { ).toEqual([]); }); + it("matches tag names in any ASCII case, as an HTML parser does", () => { + const html = + ''; + expect(extractTypeScriptBlocks(html).map((block) => block.content)).toEqual( + ["let a = 1;", "let c = 1;"], + ); + }); + + it("places a block after text whose lowercase is longer, such as a dotted capital I", () => { + // "İ".toLowerCase() is two characters: offsets taken from a lowercased copy of the page land past the block. + const before = "
İstanbul İzmir
\n"; + const html = `${before}`; + const [block] = extractTypeScriptBlocks(html); + expect(block.content).toBe('const city: string = "x";'); + expect( + html.slice(block.contentStart, block.contentStart + block.content.length), + ).toBe(block.content); + const [script] = extractPageScopeScripts( + html.replace("text/typescript", "text/javascript"), + ); + expect(script.content).toBe('const city: string = "x";'); + }); + it("skips the scan when the file never mentions text/typescript", () => { expect(mayHaveTypeScriptBlocks("")).toBe(false); expect(mayHaveTypeScriptBlocks('