test: reformat

This commit is contained in:
Mara 2025-02-09 18:27:56 +01:00
parent 55a180c79d
commit 2cfd04a50e
2 changed files with 15 additions and 16 deletions

View file

@ -14,7 +14,7 @@ const mockTranslation = ((key: string, options?: any) => {
}) as Translation;
const columnNames: ColumnName = { term: "Term", synonyms: "Synonyms" };
describe("getThesaurus", () => {
it("should parse a valid CSV content", () => {
it("passing", () => {
const csvContent = "Term,Synonyms\nword1,synonym1\nword2,synonym2";
const separator: Separator = ",";
const thesaurus = getThesaurus(csvContent, separator, mockTranslation, columnNames);
@ -25,7 +25,7 @@ describe("getThesaurus", () => {
});
});
describe("error handling", () => {
it("should throw an error for invalid column names", () => {
it("invalid column names", () => {
const csvContent = "Invalid,Header\nword1,synonym1";
const separator: Separator = ",";
expect(() =>
@ -33,7 +33,7 @@ describe("error handling", () => {
).toThrow("Invalid column names");
});
it("should throw an error for invalid separator", () => {
it("invalid separator", () => {
const csvContent = "Term;Synonyms\nword1;synonym1";
const separator: Separator = ",";
expect(() =>
@ -41,7 +41,7 @@ describe("error handling", () => {
).toThrow("Invalid separator: ;");
});
it("should throw an error for invalid header length", () => {
it("invalid header length", () => {
const csvContent = "Term,Synonyms,Extra\nword1,synonym1";
const separator: Separator = ",";
expect(() =>
@ -49,7 +49,7 @@ describe("error handling", () => {
).toThrow("Invalid header length: 3");
});
it("should throw an error for malformed line", () => {
it("malformed line", () => {
const csvContent = "Term,Synonyms\nword1,synonym1\nword2";
const separator: Separator = ",";
expect(() =>
@ -58,7 +58,7 @@ describe("error handling", () => {
});
});
describe("duplicate terms and synonyms", () => {
it("should not have duplicate terms in the result", () => {
it("terms", () => {
const csvContent = "Term,Synonyms\nword1,synonym1\nword1,synonym2";
const separator: Separator = ",";
const thesaurus = getThesaurus(csvContent, separator, mockTranslation, columnNames);
@ -66,7 +66,7 @@ describe("duplicate terms and synonyms", () => {
expect(thesaurus["word1"]).toEqual(new Set(["synonym1", "synonym2"]));
});
it("should not have duplicate synonyms in the result", () => {
it("synonyms", () => {
const csvContent = "Term,Synonyms\nword1,synonym1\nword1,synonym1";
const separator: Separator = ",";
const thesaurus = getThesaurus(csvContent, separator, mockTranslation, columnNames);
@ -74,7 +74,7 @@ describe("duplicate terms and synonyms", () => {
expect(thesaurus["word1"]).toEqual(new Set(["synonym1"]));
});
it("should not have duplicate terms and synonyms in the result", () => {
it("terms and synonyms", () => {
const csvContent = "Term,Synonyms\nword1,synonym1\nword2,synonym1";
const separator: Separator = ",";
const thesaurus = getThesaurus(csvContent, separator, mockTranslation, columnNames);
@ -84,7 +84,7 @@ describe("duplicate terms and synonyms", () => {
});
});
describe("markdown table", () => {
it("header should be two even with markdown table", () => {
it("validate header", () => {
const csvContent =
"| Term | Synonyms |\n| --- | --- |\n| word1 | synonym1\nword2 | synonym2 |";
const separator: Separator = "|";
@ -92,7 +92,7 @@ describe("markdown table", () => {
const header = getHeader(fileContent, separator, mockTranslation);
expect(header).toEqual(["Term", "Synonyms"]);
});
it("should parse a valid markdown table", () => {
it("passing", () => {
const csvContent =
"| Term | Synonyms |\n" +
"| ----- | -------- |\n" +
@ -105,7 +105,7 @@ describe("markdown table", () => {
word2: new Set(["synonym2"]),
});
});
it("should throw an error for too much columns in a markdown table", () => {
it("too much column", () => {
const csvContent =
"| Tag | Synonyme |Extra|\n" +
"| ----- | -------- |--|\n" +

View file

@ -3,7 +3,7 @@ import type { Thesaurus } from "../src/interfaces";
import { getTags } from "../src/utils";
describe("should return tags", () => {
it("should return tags if synonyms are found in the content", () => {
it("passing test", () => {
const content = "This content contains synonym1 and synonym4.";
const thesaurus: Thesaurus = {
tag1: new Set(["synonym1", "synonym2"]),
@ -14,7 +14,7 @@ describe("should return tags", () => {
expect(result).toEqual(["tag1", "tag2"]);
});
it("should handle case insensitive matches", () => {
it("case insensitive", () => {
const content = "This content contains Synonym1 and SYNONYM4.";
const thesaurus: Thesaurus = {
tag1: new Set(["synonym1", "synonym2"]),
@ -24,7 +24,7 @@ describe("should return tags", () => {
const result = getTags(content, thesaurus);
expect(result).toEqual(["tag1", "tag2"]);
});
it("should return the two tags related to the synonyms", () => {
it("synonym on the same tags", () => {
const content = "This content contains synonym4.";
const thesaurus: Thesaurus = {
tag1: new Set(["synonym1", "synonym4"]),
@ -35,13 +35,12 @@ describe("should return tags", () => {
expect(result).toEqual(["tag1", "tag2"]);
});
it("should return the tags if the synonyms is equal to the tag", () => {
it("synonym = tag", () => {
const content = "This content contains tag1.";
const thesaurus: Thesaurus = {
tag1: new Set(["tag1", "synonym1"]),
tag2: new Set(["synonym3", "synonym4"]),
};
const result = getTags(content, thesaurus);
expect(result).toEqual(["tag1"]);
});