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

test: add grammar test #3861

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions extensions/vscode/tests/__snapshots__/grammar.spec.ts.snap
@@ -0,0 +1,11 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`grammar > basic.vue 1`] = `
"><div></div>
#^ source.vue punctuation.definition.tag.begin.html.vue
# ^^^ source.vue entity.name.tag.div.html.vue
# ^ source.vue meta.tag-stuff punctuation.definition.tag.end.html.vue
# ^^ source.vue punctuation.definition.tag.begin.html.vue
# ^^^ source.vue entity.name.tag.div.html.vue
# ^ source.vue punctuation.definition.tag.end.html.vue"
`;
21 changes: 21 additions & 0 deletions extensions/vscode/tests/grammar.spec.ts
@@ -0,0 +1,21 @@
import * as path from 'path';
import * as _fg from 'fast-glob';
import { describe, expect, it } from 'vitest';
import { createGrammarSnapshot } from 'vscode-tmlanguage-snapshot';

const fg: typeof _fg = (_fg as any).default;
const fixturesDir = path.resolve(__dirname, '../../../test-workspace/grammar');
const packageJsonPath = path.resolve(__dirname, '../package.json');

describe('grammar', async () => {
const snapshot = await createGrammarSnapshot(packageJsonPath);
const cases = await fg(path.join(fixturesDir, "**").replace(/\\/g, "/"));

for (const kase of cases) {
it(path.relative(fixturesDir, kase).replace(/\\/g, "/"), async () => {
const result = await snapshot(kase);

expect(result).toMatchSnapshot();
});
}
});
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -20,8 +20,10 @@
"@lerna-lite/cli": "latest",
"@lerna-lite/publish": "latest",
"@volar/language-service": "~2.1.0",
"fast-glob": "^3.3.2",
"typescript": "latest",
"vite": "latest",
"vitest": "latest"
"vitest": "latest",
"vscode-tmlanguage-snapshot": "^0.1.3"
}
}
21 changes: 21 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test-workspace/grammar/basic.vue
@@ -0,0 +1 @@
<div></div>