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);
  });
});