Skip to content

Add tests for parser escape-sequence and error-case contract#21317

Open
johanrd wants to merge 2 commits intoemberjs:mainfrom
johanrd:tests/parser-contract
Open

Add tests for parser escape-sequence and error-case contract#21317
johanrd wants to merge 2 commits intoemberjs:mainfrom
johanrd:tests/parser-contract

Conversation

@johanrd
Copy link
Copy Markdown
Contributor

@johanrd johanrd commented Apr 16, 2026

Adds regression tests for parser behaviors that downstream tools (prettier, ember-cli) rely on — escape sequences (\{{, \\{{, \\\{{), error cases ({{}}, {{~}}, {{@}}), whitespace control, and standalone stripping.

Found by hitting real prettier smoke-test failures while exploring the parser (index-based & single-pass index-based). No behavior change; tests pass against current Jison parser.

Why upstream these if the prettier smoke test already catches them?

The prettier smoke test catches these — but only after cloning prettier, installing deps, and running jest (~2 min). These tests catch the same regressions in the normal qunit suite with specific AST assertions — faster feedback, clearer failure messages, and no external dependency.

Prettier fixtures that caught the regressions

Error cases (different error message text):

Escape-handling (different AST shape → different formatted output):

@johanrd johanrd changed the title test: parser escape-sequence and error-case contract tests [TEST] parser escape-sequence and error-case contract tests Apr 16, 2026
@johanrd johanrd changed the title [TEST] parser escape-sequence and error-case contract tests [CLEANUP] Parser escape-sequence and error-case contract tests Apr 16, 2026
@NullVoxPopuli
Copy link
Copy Markdown
Contributor

thanks for doing this! lemme know when it's ready for review

@johanrd johanrd changed the title [CLEANUP] Parser escape-sequence and error-case contract tests Add tests for parser escape-sequence and error-case contract Apr 16, 2026
@johanrd johanrd marked this pull request as ready for review April 16, 2026 21:20
@johanrd
Copy link
Copy Markdown
Contributor Author

johanrd commented Apr 16, 2026

i think now!

astEqual('\\\\{{foo}}', b.template([b.text('\\'), b.mustache(b.path('foo'))]));
});

// k=3: \\\{{ → real mustache, TWO literal backslashes emitted as TextNode.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kinda surprised this is how it works today 🙈

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the modules here be regular qunit modules spit in to multiple files? we shouldn't do this for the existing modules, but for new modules, I'd like the new tests to be less weird then their predecessors

NullVoxPopuli
NullVoxPopuli previously approved these changes Apr 16, 2026

const { test } = QUnit;

QUnit.module('[glimmer-syntax] Parser - parse error regression fixtures');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean lilke:

module('module name', function() {
tests here
});

…ract tests

Split into three files by concern:

- parser-escape-test.ts: backslash escape sequences (\{{, \\{{, \\\{{)
  in top-level text, elements, attributes, and unclosed cases.
- parser-whitespace-test.ts: tilde stripping and standalone detection.
- parser-error-test.ts: inputs that must be rejected ({{}}}, {{~}}, {{@}}, etc).

parser-node-test.ts is unchanged.
@johanrd johanrd force-pushed the tests/parser-contract branch from 5989442 to e3e3ab3 Compare April 17, 2026 05:12
@johanrd johanrd requested a review from NullVoxPopuli April 17, 2026 05:13
johanrd added a commit to johanrd/ember.js that referenced this pull request Apr 17, 2026
…rate files)

With emberjs#21317 merged, the escape-sequence, whitespace-control, and error
tests live in their own files. Remove the 259 lines that were ported
into parser-node-test.ts before the split.
johanrd added a commit to johanrd/ember.js that referenced this pull request Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants