Skip to content

Commit b02295b

Browse files
authored
Merge pull request #165 from declandewet/introduce-smart-trimming
Breaking: Introduce smart trimming
2 parents dc8577a + 1b42a87 commit b02295b

File tree

13 files changed

+56
-19
lines changed

13 files changed

+56
-19
lines changed

src/oneLine/oneLine.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { readFromFixture } from '../testUtils';
44
const val = 'amaze';
55

66
test('reduces text to one line, replacing newlines with spaces', () => {
7-
const expected = readFromFixture(__dirname, 'oneLine');
7+
const expected = readFromFixture(__dirname, 'oneLine').trim();
88
const actual = oneLine`
99
wow such doge
1010
is very ${val}
@@ -15,7 +15,7 @@ test('reduces text to one line, replacing newlines with spaces', () => {
1515
});
1616

1717
test('reduces text to one line, replacing newlines with spaces (no indentation)', () => {
18-
const expected = readFromFixture(__dirname, 'oneLine');
18+
const expected = readFromFixture(__dirname, 'oneLine').trim();
1919
const actual = oneLine`
2020
wow such doge
2121
is very ${val}
@@ -27,7 +27,7 @@ from multiline
2727
});
2828

2929
test('preserves whitespace within input lines, replacing only newlines', () => {
30-
const expected = readFromFixture(__dirname, 'oneLine-sentence');
30+
const expected = readFromFixture(__dirname, 'oneLine-sentence').trim();
3131
const actual = oneLine`
3232
Sentences also work. Double
3333
spacing is preserved.

src/oneLineCommaLists/oneLineCommaLists.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const val = 'amaze';
55

66
test('includes arrays as comma-separated list on one line', () => {
77
const fruits = ['apple', 'banana', 'kiwi'];
8-
const expected = readFromFixture(__dirname, 'oneLineCommaLists');
8+
const expected = readFromFixture(__dirname, 'oneLineCommaLists').trim();
99
const actual = oneLineCommaLists`
1010
Doge <3's these fruits: ${fruits}
1111
they are ${val}

src/oneLineCommaListsAnd/oneLineCommaListsAnd.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const val = 'amaze';
55

66
test('includes arrays as comma-separated list on one line with "and"', () => {
77
const fruits = ['apple', 'banana', 'kiwi'];
8-
const expected = readFromFixture(__dirname, 'oneLineCommaListsAnd');
8+
const expected = readFromFixture(__dirname, 'oneLineCommaListsAnd').trim();
99
const actual = oneLineCommaListsAnd`
1010
Doge <3's these fruits: ${fruits}
1111
they are ${val}
@@ -15,7 +15,10 @@ test('includes arrays as comma-separated list on one line with "and"', () => {
1515

1616
test('only returns the first item of a single element array', () => {
1717
const fruits = ['apple'];
18-
const expected = readFromFixture(__dirname, 'oneLineCommaListsAndSingleItem');
18+
const expected = readFromFixture(
19+
__dirname,
20+
'oneLineCommaListsAndSingleItem',
21+
).trim();
1922
const actual = oneLineCommaListsAnd`
2023
Doge <3's these fruits: ${fruits}
2124
they are ${val}

src/oneLineCommaListsOr/oneLineCommaListsOr.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const val = 'amaze';
55

66
test('includes arrays as comma-separated list on one line with "or"', () => {
77
const fruits = ['apple', 'banana', 'kiwi'];
8-
const expected = readFromFixture(__dirname, 'oneLineCommaListsOr');
8+
const expected = readFromFixture(__dirname, 'oneLineCommaListsOr').trim();
99
const actual = oneLineCommaListsOr`
1010
Doge <3's these fruits: ${fruits}
1111
they are ${val}
@@ -15,7 +15,10 @@ test('includes arrays as comma-separated list on one line with "or"', () => {
1515

1616
test('only returns the first item of a single element array', () => {
1717
const fruits = ['apple'];
18-
const expected = readFromFixture(__dirname, 'oneLineCommaListsOrSingleItem');
18+
const expected = readFromFixture(
19+
__dirname,
20+
'oneLineCommaListsOrSingleItem',
21+
).trim();
1922
const actual = oneLineCommaListsOr`
2023
Doge <3's these fruits: ${fruits}
2124
they are ${val}

src/oneLineInlineLists/oneLineInlineLists.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const val = 'amaze';
55

66
test('includes arrays as inline list on one line', () => {
77
const fruits = ['apple', 'banana', 'kiwi'];
8-
const expected = readFromFixture(__dirname, 'oneLineInlineLists');
8+
const expected = readFromFixture(__dirname, 'oneLineInlineLists').trim();
99
const actual = oneLineInlineLists`
1010
Doge <3's these fruits: ${fruits}
1111
they are ${val}

src/oneLineTrim/oneLineTrim.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { readFromFixture } from '../testUtils';
44
const val = 'amaze';
55

66
test('reduces to one line while trimming newlines', () => {
7-
const expected = readFromFixture(__dirname, 'oneLineTrim');
7+
const expected = readFromFixture(__dirname, 'oneLineTrim').trim();
88
const actual = oneLineTrim`
99
wow such reduction
1010
very absence of space
@@ -14,7 +14,7 @@ test('reduces to one line while trimming newlines', () => {
1414
});
1515

1616
test('reduces to one line while trimming newlines (no indentation)', () => {
17-
const expected = readFromFixture(__dirname, 'oneLineTrim');
17+
const expected = readFromFixture(__dirname, 'oneLineTrim').trim();
1818
const actual = oneLineTrim`
1919
wow such reduction
2020
very absence of space

src/stripIndent/stripIndent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import trimResultTransformer from '../trimResultTransformer';
44

55
const stripIndent = createTag(
66
stripIndentTransformer(),
7-
trimResultTransformer(),
7+
trimResultTransformer('smart'),
88
);
99

1010
export default stripIndent;

src/stripIndentTransformer/stripIndentTransformer.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { readFromFixture } from '../testUtils';
66
test('default behaviour removes the leading indent, but preserves the rest', () => {
77
const stripIndent = createTag(
88
stripIndentTransformer(),
9-
trimResultTransformer(),
9+
trimResultTransformer('smart'),
1010
);
1111
const expected = readFromFixture(__dirname, 'stripIndent');
1212
const actual = stripIndent`
@@ -21,7 +21,7 @@ test('default behaviour removes the leading indent, but preserves the rest', ()
2121
test('type "initial" does not remove indents if there is no need to do so', () => {
2222
const stripIndent = createTag(
2323
stripIndentTransformer(),
24-
trimResultTransformer(),
24+
trimResultTransformer('smart'),
2525
);
2626
expect(stripIndent``).toBe('');
2727
expect(stripIndent`foo`).toBe('foo');
@@ -31,7 +31,7 @@ test('type "initial" does not remove indents if there is no need to do so', () =
3131
test('removes all indents if type is "all"', () => {
3232
const stripIndents = createTag(
3333
stripIndentTransformer('all'),
34-
trimResultTransformer(),
34+
trimResultTransformer('smart'),
3535
);
3636
const expected = readFromFixture(__dirname, 'stripIndents');
3737
const actual = stripIndents`

src/stripIndents/stripIndents.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import trimResultTransformer from '../trimResultTransformer';
44

55
const stripIndents = createTag(
66
stripIndentTransformer('all'),
7-
trimResultTransformer(),
7+
trimResultTransformer('smart'),
88
);
99

1010
export default stripIndents;

src/testUtils/readFromFixture/readFromFixture.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ export default function readFromFixture(dirname, name) {
1212
path.join(dirname, `fixtures/${name}.txt`),
1313
'utf8',
1414
);
15-
return contents.replace(/\r\n/g, '\n').trim();
15+
return contents.replace(/\r\n/g, '\n');
1616
}

0 commit comments

Comments
 (0)