Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions test/node/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ describe(`parse`, function () {
p.process(
`const thing = "face";
<template>Hi`,
{ filename: "path/to/my/component.gjs" }
{ filename: "path/to/my/component.gjs" },
);
}).to.throw(`Parse Error at path/to/my/component.gjs:2:15: 2:15`);
});

it("handles multibyte characters", function () {
let output = p.parse(
"const prefix = '熊';\nconst tpl = <template>Hello!</template>"
"const prefix = '熊';\nconst tpl = <template>Hello!</template>",
);

expect(output).to.eql([
Expand All @@ -165,4 +165,48 @@ describe(`parse`, function () {
},
]);
});

it("has correct character ranges", function () {
let file = [
"const one = <template>💩💩💩💩💩💩💩</template>;" +
"" +
"const two = <template>💩</template>;",
].join("\n");

let output = p.parse(file);

let one = output[0];
let two = output[1];
let arr = Array.from(file);

const slice = (start, end) => arr.slice(start, end).join("");

{
let { range, startRange, endRange, contentRange } = one;

expect(slice(range.startChar, range.endChar)).to.eql(
`<template>💩💩💩💩💩💩💩</template>`,
);
expect(slice(startRange.startChar, startRange.endChar)).to.eql(
`<template>`,
);
expect(slice(endRange.startChar, endRange.endChar)).to.eql(`</template>`);
expect(slice(contentRange.startChar, contentRange.endChar)).to.eql(
`💩💩💩💩💩💩💩`,
);
}

{
let { range, startRange, endRange, contentRange } = two;

expect(slice(range.startChar, range.endChar)).to.eql(
`<template>💩</template>`,
);
expect(slice(startRange.startChar, startRange.endChar)).to.eql(
`<template>`,
);
expect(slice(endRange.startChar, endRange.endChar)).to.eql(`</template>`);
expect(slice(contentRange.startChar, contentRange.endChar)).to.eql(`💩`);
}
});
});