GitNexus/gitnexus/test/unit/kotlin-grammar.test.ts
gitnexus-release-bot[bot] 24d3de239d
chore(vendor): update tree-sitter-kotlin to 0.4.0-gd6af96d (#3801)
* chore(vendor): update tree-sitter-kotlin to 0.4.0-gd6af96d

* fix(kotlin): enable C11 Windows builds

MSVS ignores cflags_c, leaving _Static_assert in legacy C mode.
Assert parser behavior so stale prebuilds fail the vendor update.

Refs #3801

* fix(kotlin): scope MSVC standards by language

Use MSBuild language properties and remove Node headers raw C++20 flag.
Preserve inherited C++ exception handling while compiling scanner C as C11.

* chore(vendor): rebuild native prebuilds (tree-sitter-kotlin)

Built by https://github.com/abhigyanpatwari/GitNexus/actions/runs/41414632633

* chore(vendor): rebuild native prebuilds (tree-sitter-kotlin)

Built by https://github.com/abhigyanpatwari/GitNexus/actions/runs/41418217222

* chore(vendor): rebuild native prebuilds (tree-sitter-kotlin)

Built by https://github.com/abhigyanpatwari/GitNexus/actions/runs/41433953854

---------

Co-authored-by: gitnexus-release-bot[bot] <gitnexus-release-bot[bot]@users.noreply.github.com>
Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
Co-authored-by: Gergő Magyar <gergomagyar@icloud.com>
2026-11-03 08:04:52 +00:00

63 lines
2.5 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import Parser from 'tree-sitter';
import { requireVendoredGrammar } from '../../src/core/tree-sitter/vendored-grammars.js';
const Kotlin = requireVendoredGrammar('tree-sitter-kotlin');
describe('vendored Kotlin grammar', () => {
it.each(['\n', '\n// comment\n', '\n/* comment */\n'])(
'preserves inheritance after trivia %j',
(trivia) => {
const parser = new Parser();
parser.setLanguage(Kotlin);
const tree = parser.parse(`class Child${trivia}: Parent() {}`);
expect(tree.rootNode.hasError).toBe(false);
expect(tree.rootNode.namedChildren.map((node) => node.type)).toEqual(['class_declaration']);
expect(
tree.rootNode.descendantsOfType('delegation_specifier').map((node) => node.text),
).toEqual(['Parent()']);
},
);
it.each(['\n', '\n// comment\n', '\n/* comment */\n'])(
'starts a callable reference statement after trivia %j',
(trivia) => {
const parser = new Parser();
parser.setLanguage(Kotlin);
const tree = parser.parse(`fun f() { foo()${trivia}::bar\n}`);
expect(tree.rootNode.hasError).toBe(false);
const statements = tree.rootNode.descendantsOfType('statements')[0];
expect(
statements.namedChildren
.filter((node) => !node.type.endsWith('_comment'))
.map((node) => [node.type, node.text]),
).toEqual([
['call_expression', 'foo()'],
['callable_reference', '::bar'],
]);
},
);
it('attaches a labeled trailing lambda across a newline', () => {
const parser = new Parser();
parser.setLanguage(Kotlin);
const tree = parser.parse('fun f() { foo()\nlabel@ { bar() }\n}');
expect(tree.rootNode.hasError).toBe(false);
const statements = tree.rootNode.descendantsOfType('statements')[0];
expect(statements.namedChildren.map((node) => node.type)).toEqual(['call_expression']);
expect(statements.namedChildren[0].text).toBe('foo()\nlabel@ { bar() }');
});
it('ends a line comment at a bare carriage return without losing the declaration', () => {
const parser = new Parser();
parser.setLanguage(Kotlin);
const tree = parser.parse('fun f() {\n// comment\rval x = 1\n}');
expect(tree.rootNode.hasError).toBe(false);
expect(tree.rootNode.descendantsOfType('line_comment').map((node) => node.text)).toEqual([
'// comment',
]);
expect(
tree.rootNode.descendantsOfType('property_declaration').map((node) => node.text),
).toEqual(['val x = 1']);
});
});