-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util: Move indent() function into an indenter object
Some test depend on overriding the function, which will no longer work when we move to ESM (where imports are always read-only). Prepare for that by moving the function into an "indenter" object, where it can still be modified after the ESM port.
- Loading branch information
Showing
8 changed files
with
30 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,3 +232,4 @@ globals: | |
printerr: readonly | ||
parserOptions: | ||
ecmaVersion: 2020 | ||
sourceType: module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
/* exported indent */ | ||
/* exported indenter */ | ||
|
||
function indent(str, spaces) { | ||
return str.split('\n').map(line => { | ||
if (line === '') | ||
return line; | ||
return ' '.repeat(spaces) + line; | ||
}).join('\n'); | ||
} | ||
var indenter = { | ||
indent(str, spaces) { | ||
return str.split('\n').map(line => { | ||
if (line === '') | ||
return line; | ||
return ' '.repeat(spaces) + line; | ||
}).join('\n'); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
/* global jasmineImporter */ | ||
|
||
const Utils = jasmineImporter.utils; | ||
const {indenter} = jasmineImporter.utils; | ||
|
||
describe('Indent', function () { | ||
it('prepends spaces to a string', function () { | ||
expect(Utils.indent('foo', 4)).toEqual(' foo'); | ||
expect(indenter.indent('foo', 4)).toEqual(' foo'); | ||
}); | ||
|
||
it('prepends spaces to each line in a string', function () { | ||
expect(Utils.indent('a\nb\nc', 4)).toEqual(' a\n b\n c'); | ||
expect(indenter.indent('a\nb\nc', 4)).toEqual(' a\n b\n c'); | ||
}); | ||
|
||
it('does not indent an extra blank line at the end of the string', function () { | ||
expect(Utils.indent('a\nb\n', 4)).toEqual(' a\n b\n'); | ||
expect(indenter.indent('a\nb\n', 4)).toEqual(' a\n b\n'); | ||
}); | ||
|
||
it('handles zero spaces', function () { | ||
expect(Utils.indent('foo', 0)).toEqual('foo'); | ||
expect(Utils.indent('a\nb\nc', 0)).toEqual('a\nb\nc'); | ||
expect(indenter.indent('foo', 0)).toEqual('foo'); | ||
expect(indenter.indent('a\nb\nc', 0)).toEqual('a\nb\nc'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters