Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fsFixture: ignore empty lines in fixtures #9423

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/core/test-utils/src/fsFixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ const TOKEN_TYPES = [
// with the exception of the `indent` and `path` groups, which
// capture patterns that should be subsequently matched on `TOKEN_TYPES`.
const COMPOUND_TYPES = [
// Matches empty lines that are meant to be ignored.
/^(?<empty> *)\n/,
// Matches are captured as `indent` and`path` groups,
// which can then be matched to `TOKEN_TYPES`.
/^(?<indent>(?: {2})*)(?<path>[^:>\n]+\b) *(?:\n|$)/,
Expand Down Expand Up @@ -207,6 +209,8 @@ export class FixtureTokenizer {

// Additional tokens that aren't captured by `indent` and `path`.
for (let type in groups) {
// Ignore empty lines.
if (type === 'empty') continue;
// If the value is multiline, dedent each line.
let value = groups[type]
.trim()
Expand Down
31 changes: 31 additions & 0 deletions packages/core/test-utils/test/fsFixture.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,37 @@ describe('FixtureTokenizer', () => {
{type: 'link', value: 'foo/bar/bat'},
]);
});
it('ignores empty lines after dirnames', () => {
let tokens = new FixtureTokenizer(`lib\n \n \n nested`).tokenize();

assert.deepEqual(tokens, [
{type: 'dirname', value: 'lib'},
{type: 'nest', value: ''},
{type: 'dirname', value: 'nested'},
]);
});

it('ignores empty lines after links', () => {
let tokens = new FixtureTokenizer(`lib -> ./lib2\n \nlib2`).tokenize();

assert.deepEqual(tokens, [
{type: 'filename', value: 'lib'},
{type: 'link', value: './lib2'},
{type: 'dirname', value: 'lib2'},
]);
});

it('ignores empty lines after file content', () => {
let tokens = new FixtureTokenizer(
`file:\n \n content\n\n \ndir`,
).tokenize();

assert.deepEqual(tokens, [
{type: 'filename', value: 'file'},
{type: 'content', value: 'content'},
{type: 'dirname', value: 'dir'},
]);
});
});

describe('FixtureParser', () => {
Expand Down
Loading