File size: 2,178 Bytes
72e7de2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | import { describe, expect, it } from "bun:test";
import {
getQuestionLanguageErrors,
isLikelyIndonesianContent,
getTargetLanguage,
getExplanationLanguageErrors,
} from "../language-rules";
describe("language-rules", () => {
it("detects Indonesian question text for JLPT", () => {
const errors = getQuestionLanguageErrors(
{
questionText: "Menurut paragraf tersebut, apakah pernyataan berikut benar?",
options: [
{ key: "A", text: "ใฏใใๆญฃใใใงใ" },
{ key: "B", text: "ใใใใ้ใใพใ" },
],
},
"JLPT",
);
expect(errors.some((e) => e.includes("questionText"))).toBe(true);
});
it("accepts Japanese question text for JLPT", () => {
const errors = getQuestionLanguageErrors(
{
questionText: "ใใฎๆ็ซ ใซใใใจใ็ญ่
ใฎไธปๅผตใจใใฆๆญฃใใใใฎใฏใฉใใใ",
options: [
{ key: "A", text: "็ฐๅขๅ้กใฏๆทฑๅปๅใใฆใใ" },
{ key: "B", text: "็ตๆธๆ้ทใ ใใ้่ฆใ " },
],
},
"JLPT",
);
expect(errors).toHaveLength(0);
});
it("flags Indonesian options", () => {
expect(isLikelyIndonesianContent("Pilihan yang benar menurut teks")).toBe(true);
});
it("returns Japanese for JLPT", () => {
expect(getTargetLanguage("JLPT")).toBe("Japanese");
});
it("accepts mixed Indonesian + Japanese in explanation", () => {
const errors = getExplanationLanguageErrors(
"Jawaban A benar karena kata ็ฐๅข(ใใใใใ) di paragraf kedua merujuk pada lingkungan hidup.",
);
expect(errors).toHaveLength(0);
});
it("rejects explanation with only Japanese and no Indonesian prose", () => {
const errors = getExplanationLanguageErrors(
"ใใฎๆ็ซ ใซใใใจใๆญฃใใ็ญใใฏAใงใใ",
);
expect(errors.length).toBeGreaterThan(0);
});
it("rejects English-only explanation", () => {
const errors = getExplanationLanguageErrors(
"The correct answer is A because the passage clearly states the main idea.",
);
expect(errors.some((e) => e.includes("Bahasa Indonesia"))).toBe(true);
});
});
|