-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pluralize type helper to account for uncountable nouns and speci…
…al rules (#10011)
- Loading branch information
1 parent
1cab15b
commit e228088
Showing
2 changed files
with
188 additions
and
30 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/core/types/src/common/__tests__/pluralize.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { expectTypeOf } from "expect-type" | ||
import { Pluralize } from "../common" | ||
|
||
describe("Pluralize", () => { | ||
test("pluralize uncountable nouns", () => { | ||
expectTypeOf<Pluralize<"media">>().toEqualTypeOf<"media">() | ||
expectTypeOf<Pluralize<"Media">>().toEqualTypeOf<"Media">() | ||
expectTypeOf<Pluralize<"you">>().toEqualTypeOf<"you">() | ||
expectTypeOf<Pluralize<"sheep">>().toEqualTypeOf<"sheep">() | ||
expectTypeOf<Pluralize<"series">>().toEqualTypeOf<"series">() | ||
expectTypeOf<Pluralize<"species">>().toEqualTypeOf<"species">() | ||
expectTypeOf<Pluralize<"deer">>().toEqualTypeOf<"deer">() | ||
}) | ||
|
||
test("pluralize words ending with fe", () => { | ||
expectTypeOf<Pluralize<"wife">>().toEqualTypeOf<"wives">() | ||
expectTypeOf<Pluralize<"knife">>().toEqualTypeOf<"knives">() | ||
}) | ||
|
||
test("pluralize words ending with o", () => { | ||
expectTypeOf<Pluralize<"hero">>().toEqualTypeOf<"heroes">() | ||
}) | ||
|
||
test("pluralize words ending with ch", () => { | ||
expectTypeOf<Pluralize<"watch">>().toEqualTypeOf<"watches">() | ||
}) | ||
|
||
test("pluralize words ending with z", () => { | ||
expectTypeOf<Pluralize<"fiz">>().toEqualTypeOf<"fizes">() | ||
}) | ||
|
||
test("pluralize words ending with y", () => { | ||
expectTypeOf<Pluralize<"puppy">>().toEqualTypeOf<"puppies">() | ||
}) | ||
|
||
test("pluralize words with special rules", () => { | ||
expectTypeOf<Pluralize<"person">>().toEqualTypeOf<"people">() | ||
expectTypeOf<Pluralize<"child">>().toEqualTypeOf<"children">() | ||
expectTypeOf<Pluralize<"man">>().toEqualTypeOf<"men">() | ||
expectTypeOf<Pluralize<"criterion">>().toEqualTypeOf<"criteria">() | ||
expectTypeOf<Pluralize<"tooth">>().toEqualTypeOf<"teeth">() | ||
expectTypeOf<Pluralize<"foot">>().toEqualTypeOf<"feet">() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters