Skip to content

Commit

Permalink
FIX: don't show not valid LABEL in OUTLINE (#439)
Browse files Browse the repository at this point in the history
* fix label's regex

* add tests
  • Loading branch information
kyklish authored May 24, 2024
1 parent 6efd95c commit ced2c5f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/parser/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,39 @@ suite('Parser', () => {
});
});

suite('getLabelByLine', () => {
// List of test data
const dataList = [
// {
// in: // input test string
// rs: // expected result - label name or undefined
// },
{
in: 'ValidLabel:',
rs: 'ValidLabel',
},
{
in: 'NotValidLabel :',
rs: undefined,
},
];
dataList.forEach((data) => {
test("'" + data.in + "' => '" + data.rs + "'", async () => {
const document = await vscode.workspace.openTextDocument({
language: 'ahk',
content: data.in,
});
// Use array access for the private members
const label = Parser['getLabelByLine'](document, 0);
if (label === undefined) {
assert.equal(label, data.rs);
} else {
assert.strictEqual(label.name, data.rs);
}
});
});
});

suite('getRemarkByLine', () => {
// List of test data
const dataList = [
Expand Down
2 changes: 1 addition & 1 deletion src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class Parser {
private static getLabelByLine(document: vscode.TextDocument, line: number) {
const text = CodeUtil.purify(document.lineAt(line).text);
// [\u4e00-\u9fa5] Chinese unicode characters
const label = /^[ \t]*([\u4e00-\u9fa5_a-zA-Z0-9]+) *:{1}(?!(:|=))/.exec(
const label = /^[ \t]*([\u4e00-\u9fa5_a-zA-Z0-9]+):{1}(?!(:|=))/.exec(
text,
);
if (label) {
Expand Down

0 comments on commit ced2c5f

Please sign in to comment.