import { rules } from "../../../../src/adapters/syllabs/fr/rules.ts";

describe("French syllable function rules", () => {
  it("registers every exported function rule", () => {
    expect([...rules.keys()].sort()).toEqual([
      "avoir_rule",
      "ent_rule",
      "er_rule",
      "ient_rule",
      "ment_rule",
      "mer_rule",
      "nc_ai_final_rule",
      "s_final_rule",
      "t_final_rule",
      "tien_rule",
    ]);
  });

  it("accepts a final nc_ai exception at the expected position", () => {
    expect(rules.get("nc_ai_final_rule")?.("balai", 4)).toBe(true);
    expect(rules.get("nc_ai_final_rule")?.("balai", 3)).toBe(false);
  });

  it("detects ent words and rejects non-listed endings", () => {
    expect(rules.get("ent_rule")?.("souvent", 5)).toBe(true);
    expect(rules.get("ent_rule")?.("talent", 5)).toBe(false);
  });

  it("matches avoir conjugations only at the beginning of the word", () => {
    expect(rules.get("avoir_rule")?.("eu", 1)).toBe(true);
    expect(rules.get("avoir_rule")?.("eu", 2)).toBe(false);
  });

  it("detects ient endings tied to ier verbs", () => {
    expect(rules.get("ient_rule")?.("crient", 4)).toBe(true);
    expect(rules.get("ient_rule")?.("quotient", 6)).toBe(false);
  });

  it("detects er ending exceptions and ignores ordinary infinitives", () => {
    expect(rules.get("er_rule")?.("mer", 2)).toBe(true);
    expect(rules.get("er_rule")?.("manger", 5)).toBe(false);
  });

  it("detects adverbial ment endings and excludes dormir forms", () => {
    expect(rules.get("ment_rule")?.("vraiment", 6)).toBe(true);
    expect(rules.get("ment_rule")?.("dorment", 4)).toBe(false);
  });

  it("detects mer-verb plural endings as the inverse of ment words", () => {
    expect(rules.get("mer_rule")?.("ferment", 4)).toBe(true);
    expect(rules.get("mer_rule")?.("vraiment", 6)).toBe(false);
  });

  it("keeps the final s for listed words only", () => {
    expect(rules.get("s_final_rule")?.("bus", 0)).toBe(true);
    expect(rules.get("s_final_rule")?.("temps", 0)).toBe(false);
  });

  it("detects tien exceptions at the end of a word", () => {
    expect(rules.get("tien_rule")?.("soutien", 4)).toBe(true);
    expect(rules.get("tien_rule")?.("chien", 3)).toBe(false);
  });

  it("keeps the final t for listed words only", () => {
    expect(rules.get("t_final_rule")?.("internet", 0)).toBe(true);
    expect(rules.get("t_final_rule")?.("avant", 0)).toBe(false);
  });
});
