Skip to content

Commit

Permalink
✨ feat(scriptor): support adjectives
Browse files Browse the repository at this point in the history
  • Loading branch information
hugo-t-b committed Jun 26, 2024
1 parent 1480ae6 commit 901f662
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 40 deletions.
21 changes: 19 additions & 2 deletions scriptor/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { assertNever } from "assert-never";
import { parseForm, parsePrincipalParts } from "./utils/parse";
import Verb from "./utils/verb";

import Adjective from "./utils/adjective";
import Noun from "./utils/noun";
import Verb from "./utils/verb";

const validateKey = (key: string, word: Noun | Verb): key is keyof typeof word => key in word;
const validateKey = (key: string, word: Adjective | Noun | Verb): key is keyof typeof word => key in word;

export default (parts: string, ...form: string[]): string => {
const principalPartsParseResult = parsePrincipalParts(parts);
Expand Down Expand Up @@ -75,6 +77,21 @@ export default (parts: string, ...form: string[]): string => {
}

return nounResult;
case "adjective":
const adjective = new Adjective(principalParts);
const adjectiveKey = formParseResult.data.join("_");

if (!validateKey(adjectiveKey, adjective)) {
throw new Error("Unsupported or invalid form");
}

const adjectiveResult = adjective[adjectiveKey];

if (typeof adjectiveResult !== "string") {
throw new Error("Invalid form");
}

return adjectiveResult;
default:
assertNever(partOfSpeech);
}
Expand Down
72 changes: 36 additions & 36 deletions scriptor/tests/adjectives.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const scriptus = "scriptus, scripta, scriptum";
describe("Masculine singular", () => {
const repeated = ["masculine", "singular"];

test.todo("Nominative", () => {
test("Nominative", () => {
const form = ["nominative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aeger");
Expand All @@ -22,7 +22,7 @@ describe("Masculine singular", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptus");
});

test.todo("Vocative", () => {
test("Vocative", () => {
const form = ["vocative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aeger");
Expand All @@ -33,7 +33,7 @@ describe("Masculine singular", () => {
expect(scriptor(scriptus, ...form)).toBe("scripte");
});

test.todo("Accusative", () => {
test("Accusative", () => {
const form = ["accusative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegrum");
Expand All @@ -44,7 +44,7 @@ describe("Masculine singular", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptum");
});

test.todo("Genitive", () => {
test("Genitive", () => {
const form = ["genitive", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegri");
Expand All @@ -55,7 +55,7 @@ describe("Masculine singular", () => {
expect(scriptor(scriptus, ...form)).toBe("scripti");
});

test.todo("Dative", () => {
test("Dative", () => {
const form = ["dative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegro");
Expand All @@ -66,7 +66,7 @@ describe("Masculine singular", () => {
expect(scriptor(scriptus, ...form)).toBe("scripto");
});

test.todo("Ablative", () => {
test("Ablative", () => {
const form = ["ablative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegro");
Expand All @@ -81,7 +81,7 @@ describe("Masculine singular", () => {
describe("Feminine singular", () => {
const repeated = ["feminine", "singular"];

test.todo("Nominative", () => {
test("Nominative", () => {
const form = ["nominative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegra");
Expand All @@ -92,7 +92,7 @@ describe("Feminine singular", () => {
expect(scriptor(scriptus, ...form)).toBe("scripta");
});

test.todo("Vocative", () => {
test("Vocative", () => {
const form = ["vocative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegra");
Expand All @@ -103,7 +103,7 @@ describe("Feminine singular", () => {
expect(scriptor(scriptus, ...form)).toBe("scripta");
});

test.todo("Accusative", () => {
test("Accusative", () => {
const form = ["accusative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegram");
Expand All @@ -114,7 +114,7 @@ describe("Feminine singular", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptam");
});

test.todo("Genitive", () => {
test("Genitive", () => {
const form = ["genitive", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegrae");
Expand All @@ -125,7 +125,7 @@ describe("Feminine singular", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptae");
});

test.todo("Dative", () => {
test("Dative", () => {
const form = ["dative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegrae");
Expand All @@ -136,7 +136,7 @@ describe("Feminine singular", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptae");
});

test.todo("Ablative", () => {
test("Ablative", () => {
const form = ["ablative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegra");
Expand All @@ -151,7 +151,7 @@ describe("Feminine singular", () => {
describe("Neuter singular", () => {
const repeated = ["neuter", "singular"];

test.todo("Nominative", () => {
test("Nominative", () => {
const form = ["nominative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegrum");
Expand All @@ -162,7 +162,7 @@ describe("Neuter singular", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptum");
});

test.todo("Vocative", () => {
test("Vocative", () => {
const form = ["vocative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegrum");
Expand All @@ -173,7 +173,7 @@ describe("Neuter singular", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptum");
});

test.todo("Accusative", () => {
test("Accusative", () => {
const form = ["accusative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegrum");
Expand All @@ -184,7 +184,7 @@ describe("Neuter singular", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptum");
});

test.todo("Genitive", () => {
test("Genitive", () => {
const form = ["genitive", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegri");
Expand All @@ -195,7 +195,7 @@ describe("Neuter singular", () => {
expect(scriptor(scriptus, ...form)).toBe("scripti");
});

test.todo("Dative", () => {
test("Dative", () => {
const form = ["dative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegro");
Expand All @@ -206,7 +206,7 @@ describe("Neuter singular", () => {
expect(scriptor(scriptus, ...form)).toBe("scripto");
});

test.todo("Ablative", () => {
test("Ablative", () => {
const form = ["ablative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegro");
Expand All @@ -221,7 +221,7 @@ describe("Neuter singular", () => {
describe("Masculine plural", () => {
const repeated = ["masculine", "plural"];

test.todo("Nominative", () => {
test("Nominative", () => {
const form = ["nominative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegri");
Expand All @@ -232,7 +232,7 @@ describe("Masculine plural", () => {
expect(scriptor(scriptus, ...form)).toBe("scripti");
});

test.todo("Vocative", () => {
test("Vocative", () => {
const form = ["vocative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegri");
Expand All @@ -243,7 +243,7 @@ describe("Masculine plural", () => {
expect(scriptor(scriptus, ...form)).toBe("scripti");
});

test.todo("Accusative", () => {
test("Accusative", () => {
const form = ["accusative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegros");
Expand All @@ -254,7 +254,7 @@ describe("Masculine plural", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptos");
});

test.todo("Genitive", () => {
test("Genitive", () => {
const form = ["genitive", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegrorum");
Expand All @@ -265,7 +265,7 @@ describe("Masculine plural", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptorum");
});

test.todo("Dative", () => {
test("Dative", () => {
const form = ["dative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegris");
Expand All @@ -276,7 +276,7 @@ describe("Masculine plural", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptis");
});

test.todo("Ablative", () => {
test("Ablative", () => {
const form = ["ablative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegris");
Expand All @@ -291,7 +291,7 @@ describe("Masculine plural", () => {
describe("Feminine plural", () => {
const repeated = ["feminine", "plural"];

test.todo("Nominative", () => {
test("Nominative", () => {
const form = ["nominative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegrae");
Expand All @@ -302,7 +302,7 @@ describe("Feminine plural", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptae");
});

test.todo("Vocative", () => {
test("Vocative", () => {
const form = ["vocative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegrae");
Expand All @@ -313,7 +313,7 @@ describe("Feminine plural", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptae");
});

test.todo("Accusative", () => {
test("Accusative", () => {
const form = ["accusative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegras");
Expand All @@ -324,7 +324,7 @@ describe("Feminine plural", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptas");
});

test.todo("Genitive", () => {
test("Genitive", () => {
const form = ["genitive", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegrarum");
Expand All @@ -335,7 +335,7 @@ describe("Feminine plural", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptarum");
});

test.todo("Dative", () => {
test("Dative", () => {
const form = ["dative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegris");
Expand All @@ -346,7 +346,7 @@ describe("Feminine plural", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptis");
});

test.todo("Ablative", () => {
test("Ablative", () => {
const form = ["ablative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegris");
Expand All @@ -361,7 +361,7 @@ describe("Feminine plural", () => {
describe("Neuter plural", () => {
const repeated = ["neuter", "plural"];

test.todo("Nominative", () => {
test("Nominative", () => {
const form = ["nominative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegra");
Expand All @@ -372,7 +372,7 @@ describe("Neuter plural", () => {
expect(scriptor(scriptus, ...form)).toBe("scripta");
});

test.todo("Vocative", () => {
test("Vocative", () => {
const form = ["vocative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegra");
Expand All @@ -383,7 +383,7 @@ describe("Neuter plural", () => {
expect(scriptor(scriptus, ...form)).toBe("scripta");
});

test.todo("Accusative", () => {
test("Accusative", () => {
const form = ["accusative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegra");
Expand All @@ -394,7 +394,7 @@ describe("Neuter plural", () => {
expect(scriptor(scriptus, ...form)).toBe("scripta");
});

test.todo("Genitive", () => {
test("Genitive", () => {
const form = ["genitive", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegrorum");
Expand All @@ -405,7 +405,7 @@ describe("Neuter plural", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptorum");
});

test.todo("Dative", () => {
test("Dative", () => {
const form = ["dative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegris");
Expand All @@ -416,7 +416,7 @@ describe("Neuter plural", () => {
expect(scriptor(scriptus, ...form)).toBe("scriptis");
});

test.todo("Ablative", () => {
test("Ablative", () => {
const form = ["ablative", ...repeated];

expect(scriptor(aeger, ...form)).toBe("aegris");
Expand Down
Loading

0 comments on commit 901f662

Please sign in to comment.