diff --git a/tests/fixtures/multiple-erb-in-one-line.js b/tests/fixtures/multiple-erb-in-one-line.js new file mode 100644 index 0000000..02adfbb --- /dev/null +++ b/tests/fixtures/multiple-erb-in-one-line.js @@ -0,0 +1 @@ +console.log ("Hi ");<%# This is a comment %>console.log('whatever');<% if true %> console.log('true');<% end %> \ No newline at end of file diff --git a/tests/fixtures/multiple-erb-in-one-line.pre.js b/tests/fixtures/multiple-erb-in-one-line.pre.js new file mode 100644 index 0000000..feda253 --- /dev/null +++ b/tests/fixtures/multiple-erb-in-one-line.pre.js @@ -0,0 +1 @@ +console.log ("Hi ");/* eslint-disable */{}/* eslint-enable */console.log('whatever');/* eslint-disable */{}/* eslint-enable */ console.log('true');/* eslint-disable */{}/* eslint-enable */ \ No newline at end of file diff --git a/tests/processor.js b/tests/processor.js index 241de4f..e3cc801 100644 --- a/tests/processor.js +++ b/tests/processor.js @@ -24,7 +24,13 @@ describe("preprocess", () => { assert.equal(res, "Hello, world!"); }); - const replaceStringFiles = ["one-liner", "common", "each-do", "multi-line"]; + const replaceStringFiles = [ + "one-liner", + "common", + "each-do", + "multi-line", + "multiple-erb-in-one-line", + ]; replaceStringFiles.forEach((name) => { it(`replaces ruby with dummy string in "${name}.js"`, () => { const text = fs.readFileSync(`tests/fixtures/${name}.js`, "utf-8"); @@ -108,6 +114,25 @@ describe("preprocess", () => { ]), }, }, + { + // This tests that column offsets are correctly calculated for multiple + // ERB tags on the same line. + name: "multiple-erb-in-one-line", + expected: { + lineOffsetLookup: new Map([ + [1, new Map([ + [61, { lineOffset: 0, columnOffset: -17 }], + [126, { lineOffset: 0, columnOffset: -45 }], + [188, { lineOffset: 0, columnOffset: -77 }], + ])], + ]), + offsetLookup: new Map([ + [61, { lineOffset: 0, columnOffset: -17 }], + [126, { lineOffset: 0, columnOffset: -45 }], + [188, { lineOffset: 0, columnOffset: -77 }], + ]), + }, + }, ]; offsets.forEach(({ name, expected }) => { it(`correctly constructs offset map for "${name}.js`, () => {