Skip to content

Commit

Permalink
Add test for multiple ERB tags in one line
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Nov 23, 2023
1 parent 67d6db7 commit df66445
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/fixtures/multiple-erb-in-one-line.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/fixtures/multiple-erb-in-one-line.pre.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion tests/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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`, () => {
Expand Down

0 comments on commit df66445

Please sign in to comment.