Skip to content

Commit 40c4f05

Browse files
authored
Merge pull request #104 from embroider-build/nvp/character-offest-repro
Character offset repro
2 parents 6559f58 + f72707c commit 40c4f05

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

test/node/parse.test.js

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ describe(`parse`, function () {
138138
p.process(
139139
`const thing = "face";
140140
<template>Hi`,
141-
{ filename: "path/to/my/component.gjs" }
141+
{ filename: "path/to/my/component.gjs" },
142142
);
143143
}).to.throw(`Parse Error at path/to/my/component.gjs:2:15: 2:15`);
144144
});
145145

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

151151
expect(output).to.eql([
@@ -165,4 +165,48 @@ describe(`parse`, function () {
165165
},
166166
]);
167167
});
168+
169+
it("has correct character ranges", function () {
170+
let file = [
171+
"const one = <template>💩💩💩💩💩💩💩</template>;" +
172+
"" +
173+
"const two = <template>💩</template>;",
174+
].join("\n");
175+
176+
let output = p.parse(file);
177+
178+
let one = output[0];
179+
let two = output[1];
180+
let arr = Array.from(file);
181+
182+
const slice = (start, end) => arr.slice(start, end).join("");
183+
184+
{
185+
let { range, startRange, endRange, contentRange } = one;
186+
187+
expect(slice(range.startChar, range.endChar)).to.eql(
188+
`<template>💩💩💩💩💩💩💩</template>`,
189+
);
190+
expect(slice(startRange.startChar, startRange.endChar)).to.eql(
191+
`<template>`,
192+
);
193+
expect(slice(endRange.startChar, endRange.endChar)).to.eql(`</template>`);
194+
expect(slice(contentRange.startChar, contentRange.endChar)).to.eql(
195+
`💩💩💩💩💩💩💩`,
196+
);
197+
}
198+
199+
{
200+
let { range, startRange, endRange, contentRange } = two;
201+
202+
expect(slice(range.startChar, range.endChar)).to.eql(
203+
`<template>💩</template>`,
204+
);
205+
expect(slice(startRange.startChar, startRange.endChar)).to.eql(
206+
`<template>`,
207+
);
208+
expect(slice(endRange.startChar, endRange.endChar)).to.eql(`</template>`);
209+
expect(slice(contentRange.startChar, contentRange.endChar)).to.eql(`💩`);
210+
}
211+
});
168212
});

0 commit comments

Comments
 (0)