Skip to content

Commit 292c10a

Browse files
authored
Fix stripIndents and add regression tests (#129)
1 parent f81559f commit 292c10a

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
wow such indent gone
2+
3+
very amaze

src/stripIndent/stripIndent.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ test('maintains deeper indentation', async (t) => {
3333
t.is(actual, expected)
3434
})
3535

36+
test('maintains empty lines', async (t) => {
37+
const expected = await readFromFixture(__dirname, 'maintainEmptyLines')
38+
const actual = stripIndent`
39+
wow such indent gone
40+
41+
very ${val}
42+
`
43+
t.is(actual, expected)
44+
})
45+
3646
test('does nothing if there are no indents', async (t) => {
3747
const expected = 'wow such doge'
3848
const actual = stripIndent`wow such doge`

src/stripIndentTransformer/stripIndentTransformer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const stripIndentTransformer = (type = 'initial') => ({
1919
endResult = indent > 0 ? endResult.replace(regexp, '') : endResult
2020
} else if (type === 'all') {
2121
// remove all indentation from each line
22-
endResult = endResult.replace(/(?:\n\s*)/g, '\n')
22+
endResult = endResult.replace(/(?:\n[^\S\n]*)/g, '\n')
2323
} else {
2424
throw new Error(`Unknown type: ${type}`)
2525
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
wow such indent gone
2+
very amaze
3+
4+
foo bar baz

src/stripIndents/stripIndents.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,14 @@ test('strips all indentation', async (t) => {
1515
`
1616
t.is(actual, expected)
1717
})
18+
19+
test('maintains empty lines', async (t) => {
20+
const expected = await readFromFixture(__dirname, 'maintainEmptyLines')
21+
const actual = stripIndents`
22+
wow such indent gone
23+
very ${val}
24+
25+
foo bar baz
26+
`
27+
t.is(actual, expected)
28+
})

0 commit comments

Comments
 (0)