-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] manage comment formats and improve test code using a looku…
…p table
- Loading branch information
1 parent
a3c370f
commit 00e512f
Showing
3 changed files
with
112 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,39 @@ | ||
import assert from "assert"; | ||
import { generateFileNameComment } from "../../utils/generateFileNameComment"; | ||
|
||
describe("generateFileNameComment()", () => { | ||
it("should generate correct comment for JavaScript", () => { | ||
const result = generateFileNameComment("javascript", "example.js"); | ||
assert.strictEqual(result, "// example.js"); | ||
}); | ||
|
||
it("should generate correct comment for Python", () => { | ||
const result = generateFileNameComment("python", "example.py"); | ||
assert.strictEqual(result, "# example.py"); | ||
}); | ||
|
||
it("should generate correct comment for C++", () => { | ||
const result = generateFileNameComment("cpp", "example.cpp"); | ||
assert.strictEqual(result, "// example.cpp"); | ||
}); | ||
|
||
it("should generate correct comment for HTML", () => { | ||
const result = generateFileNameComment("html", "example.html"); | ||
assert.strictEqual(result, "<!-- example.html -->"); | ||
}); | ||
|
||
it("should generate correct comment for CSS", () => { | ||
const result = generateFileNameComment("css", "example.css"); | ||
assert.strictEqual(result, "/* example.css */"); | ||
}); | ||
|
||
it("should handle plaintext without comment syntax", () => { | ||
const result = generateFileNameComment("plaintext", "example.txt"); | ||
assert.strictEqual(result, "example.txt"); | ||
}); | ||
|
||
it("should generate correct comment for SQL", () => { | ||
const result = generateFileNameComment("sql", "example.sql"); | ||
assert.strictEqual(result, "-- example.sql"); | ||
}); | ||
|
||
it("should generate correct comment for Bat scripts", () => { | ||
const result = generateFileNameComment("bat", "example.bat"); | ||
assert.strictEqual(result, "REM example.bat"); | ||
}); | ||
|
||
it("should return default comment for unsupported language", () => { | ||
const result = generateFileNameComment("unsupported-language", "example.unknown"); | ||
assert.strictEqual(result, "// example.unknown"); | ||
}); | ||
|
||
it("should generate correct comment for JSONC", () => { | ||
const result = generateFileNameComment("jsonc", "example.jsonc"); | ||
assert.strictEqual(result, "// example.jsonc"); | ||
describe("generateFileNameComment", function () { | ||
const testCases: Record< | ||
string, | ||
{ languageId: string; fileIdentifier: string; expectedComment: string } | ||
> = { | ||
javascript: { | ||
languageId: "javascript", | ||
fileIdentifier: "example.js", | ||
expectedComment: "// example.js", | ||
}, | ||
python: { languageId: "python", fileIdentifier: "example.py", expectedComment: "# example.py" }, | ||
html: { | ||
languageId: "html", | ||
fileIdentifier: "example.html", | ||
expectedComment: "<!-- example.html -->", | ||
}, | ||
css: { languageId: "css", fileIdentifier: "example.css", expectedComment: "/* example.css */" }, | ||
latex: { languageId: "latex", fileIdentifier: "example.tex", expectedComment: "% example.tex" }, | ||
plaintext: { | ||
languageId: "plaintext", | ||
fileIdentifier: "example.txt", | ||
expectedComment: "example.txt", | ||
}, | ||
unrecognized: { | ||
languageId: "nonexistent-language", | ||
fileIdentifier: "example.unknown", | ||
expectedComment: "// example.unknown", | ||
}, | ||
}; | ||
|
||
Object.values(testCases).forEach(({ languageId, fileIdentifier, expectedComment }) => { | ||
it(`should return correct comment format for ${languageId}`, function () { | ||
assert.strictEqual(generateFileNameComment(languageId, fileIdentifier), expectedComment); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters