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 plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Jeremy Cherer (https://github.com/JavaLavaMT)",
"Rocky Warren (https://github.com/therockstorm)",
"Gerrit Birkeland (https://github.com/Gerrit0)",
"Sanjeev Penupala (https://github.com/spenpal)"
"Sanjeev Penupala (https://github.com/sanjeevpenupala)"
],
"scripts": {
"build": "tsc --noEmit && tsc --noEmit -p test.tsconfig.json && vitest run && biome ci && exportcase check src && stryker run && tsc",
Expand Down
37 changes: 36 additions & 1 deletion plugin/src/checkLegacySyntax.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
import { expect, test } from "vitest";
import { checkLegacySyntax } from "./checkLegacySyntax.js";

test("it should parse tag without file path", () => {
test("it should throw on legacy colon syntax with line range", () => {
expect(() => checkLegacySyntax("src/greet.example.ts:5-20")).toThrowError(
"BREAKING CHANGE: The colon syntax 'src/greet.example.ts:5-20' is no longer supported in v3.0.0+. Please migrate to the new bracket syntax: 'src/greet.example.ts[5:20]'. See documentation for the new bracket syntax.",
);
});

test("it should throw on legacy colon syntax with single line", () => {
expect(() => checkLegacySyntax("file.ts:15")).toThrowError("BREAKING CHANGE");
});

test("it should throw on legacy colon syntax with spaces in selector", () => {
expect(() => checkLegacySyntax("file.ts:5 - 20")).toThrowError(
"BREAKING CHANGE",
);
});

test("it should not throw when tag has no colon", () => {
expect(() => checkLegacySyntax("foo.example.ts")).not.toThrow();
});

test("it should not throw when colon is followed by non-numeric text", () => {
expect(() => checkLegacySyntax("file.ts:notdigits")).not.toThrow();
});

test("it should not throw when colon is followed by empty string", () => {
expect(() => checkLegacySyntax("file.ts:")).not.toThrow();
});

test("it should not throw when colon is followed by only whitespace", () => {
expect(() => checkLegacySyntax("file.ts: ")).not.toThrow();
});

test("it should throw on legacy syntax where colon is at index 1", () => {
expect(() => checkLegacySyntax("a:5")).toThrowError("BREAKING CHANGE");
});

test("it should not throw when colon is followed by mixed alphanumeric", () => {
expect(() => checkLegacySyntax("file.ts:123abc")).not.toThrow();
expect(() => checkLegacySyntax("file.ts:abc123")).not.toThrow();
});
75 changes: 75 additions & 0 deletions plugin/src/parseLineSelector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,81 @@ test("Should handle colon-only selector", () => {
expect(parseLineSelector(":")).toHaveLength(0);
});

test("Should handle whitespace-padded selector", () => {
const result = parseLineSelector(" 5 ");
expect(result).toHaveLength(1);
expect(result[0]).toEqual({
type: "single",
isExclusion: false,
line: 5,
});
});

test("Should handle spaces around comma-separated parts", () => {
const result = parseLineSelector("2:5, 10");
expect(result).toHaveLength(2);
expect(result[0]).toEqual({
type: "range",
isExclusion: false,
start: 2,
end: 5,
});
expect(result[1]).toEqual({
type: "single",
isExclusion: false,
line: 10,
});
});

test("Should skip empty parts from trailing comma", () => {
const result = parseLineSelector("2:5,");
expect(result).toHaveLength(1);
expect(result[0]).toEqual({
type: "range",
isExclusion: false,
start: 2,
end: 5,
});
});

test("Should skip empty parts from double comma", () => {
const result = parseLineSelector("2:5,,10");
expect(result).toHaveLength(2);
expect(result[1]).toEqual({
type: "single",
isExclusion: false,
line: 10,
});
});

test("Should detect old dash syntax with spaces around parts", () => {
expect(() => parseLineSelector("2-4 , 10")).toThrowError("BREAKING CHANGE");
});

test("Should handle whitespace around exclusion part", () => {
const result = parseLineSelector("1:10, !5");
expect(result).toHaveLength(2);
expect(result[1]).toEqual({
type: "single",
isExclusion: true,
line: 5,
});
});

test("Should handle negative number with trailing characters as old dash syntax", () => {
expect(() => parseLineSelector("-5-3")).toThrowError("BREAKING CHANGE");
});

test("Should not flag negative number with leading space as old dash syntax", () => {
const result = parseLineSelector("1, -5");
expect(result).toHaveLength(2);
expect(result[1]).toEqual({
type: "single",
isExclusion: false,
line: -5,
});
});

test("Should resolve basic range", () => {
const parsed = parseLineSelector("2:5");
const resolved = resolveLineSelections(parsed, 10);
Expand Down