Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/converter/comments/blockLexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ function* lexBlockComment2(
if (lookahead !== pos + 1) {
while (
lookahead < end &&
/[a-z0-9]/i.test(file[lookahead])
/[a-z0-9-]/i.test(file[lookahead])
) {
lookahead++;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/comments/lineLexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function* lexLineComments2(
if (lookahead !== pos + 1) {
while (
lookahead < end &&
/[a-z0-9]/i.test(file[lookahead])
/[a-z0-9-]/i.test(file[lookahead])
) {
lookahead++;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/comments/rawLexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function* lexCommentString2(
if (lookahead !== pos + 1) {
while (
lookahead < end &&
/[a-z0-9]/i.test(file[lookahead])
/[a-z0-9-]/i.test(file[lookahead])
) {
lookahead++;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils-common/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@ export function optional<T extends Schema>(x: T): Optional<T> {
}

export function isTagString(x: unknown): x is `@${string}` {
return typeof x === "string" && /^@[a-zA-Z][a-zA-Z0-9]*$/.test(x);
return typeof x === "string" && /^@[a-z][a-z0-9-]*$/i.test(x);
}
12 changes: 8 additions & 4 deletions src/test/comments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,16 @@ describe("Block Comment Lexer", () => {
});

it("Should recognize tags", () => {
const tokens = lex("/* @tag @a @abc234 */");
const tokens = lex("/* @tag @a @abc234 @abc-234 */");

equal(tokens, [
{ kind: TokenSyntaxKind.Tag, text: "@tag", pos: 3 },
{ kind: TokenSyntaxKind.Text, text: " ", pos: 7 },
{ kind: TokenSyntaxKind.Tag, text: "@a", pos: 8 },
{ kind: TokenSyntaxKind.Text, text: " ", pos: 10 },
{ kind: TokenSyntaxKind.Tag, text: "@abc234", pos: 11 },
{ kind: TokenSyntaxKind.Text, text: " ", pos: 18 },
{ kind: TokenSyntaxKind.Tag, text: "@abc-234", pos: 19 },
]);
});

Expand Down Expand Up @@ -641,14 +643,16 @@ describe("Line Comment Lexer", () => {
});

it("Should recognize tags", () => {
const tokens = lex("// @tag @a @abc234");
const tokens = lex("// @tag @a @abc234 @abc-234");

equal(tokens, [
{ kind: TokenSyntaxKind.Tag, text: "@tag", pos: 3 },
{ kind: TokenSyntaxKind.Text, text: " ", pos: 7 },
{ kind: TokenSyntaxKind.Tag, text: "@a", pos: 8 },
{ kind: TokenSyntaxKind.Text, text: " ", pos: 10 },
{ kind: TokenSyntaxKind.Tag, text: "@abc234", pos: 11 },
{ kind: TokenSyntaxKind.Text, text: " ", pos: 18 },
{ kind: TokenSyntaxKind.Tag, text: "@abc-234", pos: 19 },
]);
});

Expand Down Expand Up @@ -993,12 +997,12 @@ describe("Raw Lexer", () => {
});

it("Should not recognize tags", () => {
const tokens = lex("@123 @@ @ @tag @a @abc234");
const tokens = lex("@123 @@ @ @tag @a @abc234 @abc-234");

equal(tokens, [
{
kind: TokenSyntaxKind.Text,
text: "@123 @@ @ @tag @a @abc234",
text: "@123 @@ @ @tag @a @abc234 @abc-234",
pos: 0,
},
]);
Expand Down
6 changes: 5 additions & 1 deletion src/test/utils/options/default-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,15 @@ describe("Default Options", () => {

describe("blockTags", () => {
it("Should disallow non-tags", () => {
throws(() => opts.setValue("blockTags", ["@bad-non-tag"]));
throws(() => opts.setValue("blockTags", ["@bad_tag"]));
throws(() => opts.setValue("blockTags", ["@2bad"]));
});

it("Should allow tags", () => {
doesNotThrow(() => opts.setValue("blockTags", ["@good"]));
doesNotThrow(() => opts.setValue("blockTags", ["@good2"]));
doesNotThrow(() => opts.setValue("blockTags", ["@Good"]));
doesNotThrow(() => opts.setValue("blockTags", ["@good-tag"]));
});
});

Expand Down