|
1 |
| -import { Lang as LangNapi } from '@ast-grep/napi' |
2 |
| -import test, { describe } from 'node:test' |
3 |
| -import { Lang } from './langs.js' |
| 1 | +import { parse, registerDynamicLanguage } from '@ast-grep/napi' |
| 2 | +import { before, describe, test } from 'node:test' |
| 3 | +import { Lang } from './lang.js' |
| 4 | +import { langs } from './langs.js' |
4 | 5 |
|
5 |
| -/** Languages supported in `@ast-grep/napi@~0.33.1`. */ |
6 |
| -const previous = Object.freeze({ |
7 |
| - Html: 'Html', |
8 |
| - JavaScript: 'JavaScript', |
9 |
| - Tsx: 'Tsx', |
10 |
| - Css: 'Css', |
11 |
| - TypeScript: 'TypeScript', |
12 |
| - Bash: 'Bash', |
13 |
| - C: 'C', |
14 |
| - Cpp: 'Cpp', |
15 |
| - CSharp: 'CSharp', |
16 |
| - Go: 'Go', |
17 |
| - Elixir: 'Elixir', |
18 |
| - Haskell: 'Haskell', |
19 |
| - Java: 'Java', |
20 |
| - Json: 'Json', |
21 |
| - Kotlin: 'Kotlin', |
22 |
| - Lua: 'Lua', |
23 |
| - Php: 'Php', |
24 |
| - Python: 'Python', |
25 |
| - Ruby: 'Ruby', |
26 |
| - Rust: 'Rust', |
27 |
| - Scala: 'Scala', |
28 |
| - Sql: 'Sql', |
29 |
| - Swift: 'Swift', |
30 |
| -}) |
| 6 | +describe('langs', () => { |
| 7 | + before(() => registerDynamicLanguage(langs)) |
| 8 | + |
| 9 | + // A newly supported language |
| 10 | + test(Lang.Dart, ({ assert }) => { |
| 11 | + const sg = parse(Lang.Dart, 'var x = "Hello, world!";"') |
| 12 | + const kind = sg.root().kind() |
| 13 | + assert.equal(kind, 'program') |
| 14 | + }) |
31 | 15 |
|
32 |
| -describe('Lang', () => { |
33 |
| - test('The new language enum is compatible with the old one', ({ assert }) => { |
34 |
| - for (const lang of Object.values(previous)) assert.equal(Lang[lang], lang) |
| 16 | + // A previously supported language |
| 17 | + test(Lang.Go, ({ assert }) => { |
| 18 | + const sg = parse(Lang.Dart, 'x := "Hello, world!"') |
| 19 | + const kind = sg.root().kind() |
| 20 | + assert.equal(kind, 'program') |
35 | 21 | })
|
36 | 22 |
|
37 |
| - test('The new language enum is compatible with the built-in ones', ({ |
38 |
| - assert, |
39 |
| - }) => { |
40 |
| - for (const lang of Object.values(LangNapi)) assert.equal(Lang[lang], lang) |
| 23 | + // A built-in language |
| 24 | + test(Lang.TypeScript, ({ assert }) => { |
| 25 | + const sg = parse(Lang.TypeScript, 'const x = "Hello, world!"') |
| 26 | + const kind = sg.root().kind() |
| 27 | + assert.equal(kind, 'program') |
41 | 28 | })
|
42 | 29 | })
|
0 commit comments