-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
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,59 @@ | ||
import { Expect, Equal } from "type-testing"; | ||
|
||
type Count< | ||
Toys extends string[], | ||
Toy extends string, | ||
Counts extends string[] = [], | ||
> = Toys extends [infer First, ...infer Rest extends string[]] | ||
? First extends Toy | ||
? Count<Rest, Toy, [...Counts, "1"]> | ||
: Count<Rest, Toy, Counts> | ||
: Counts["length"]; | ||
|
||
// ------------------- Test section --------------------- | ||
|
||
// prettier-ignore | ||
type ToySack = [ | ||
'๐ธ', '๐ง', '๐', '๐', '๐ป', '๐ช', '๐งฉ', '๐ฎ', | ||
'๐จ', '๐น๏ธ', '๐ฑ', '๐งฉ', '๐งธ', '๐ง', '๐', '๐ฒ', | ||
'๐', 'โ', '๐จ', '๐', '๐ธ', '๐งธ', '๐', '๐ธ', | ||
'๐ฑ', '๐ง', '๐ฎ', '๐', '๐ฑ', '๐งฉ', '๐งฉ', '๐ฒ', | ||
'๐น๏ธ', '๐งต', '๐ฑ', '๐น๏ธ', '๐ฐ๏ธ', '๐งข', '๐น๏ธ', '๐', | ||
'๐งธ', '๐', '๐ง', '๐งฉ', '๐ธ', '๐ฎ', '๐ง', '๐', | ||
'๐ป', 'โ', '๐น', '๐ง', '๐งฃ', '๐ช', '๐ธ', '๐งธ', | ||
'๐งธ', '๐งธ', '๐งฉ', '๐ช', '๐๏ธ', '๐๏ธ', '๐ง', '๐', | ||
'๐งธ', '๐ถ๏ธ', '๐ป', 'โ', 'โ', '๐ถ๏ธ', '๐ง', '๐ง', | ||
'๐ง', '๐ป', '๐', '๐ธ', '๐ป', '๐ช', '๐', '๐จ', | ||
'๐ฑ', '๐ง', '๐ฑ', '๐ธ', '๐๏ธ', '๐', '๐ฒ', '๐ฑ', | ||
'๐ฒ', '๐ธ' | ||
]; | ||
|
||
type test_0_actual = Count<ToySack, "๐">; | ||
// ^? | ||
type test_0_expected = 8; | ||
type test_0 = Expect<Equal<test_0_expected, test_0_actual>>; | ||
|
||
type test_1_actual = Count<ToySack, "๐งฆ">; | ||
// ^? | ||
type test_1_expected = 0; | ||
type test_1 = Expect<Equal<test_1_expected, test_1_actual>>; | ||
|
||
type test_2_actual = Count<ToySack, "๐งฉ">; | ||
// ^? | ||
type test_2_expected = 6; | ||
type test_2 = Expect<Equal<test_2_expected, test_2_actual>>; | ||
|
||
type test_3_actual = Count<ToySack, "๐น">; | ||
// ^? | ||
type test_3_expected = 1; | ||
type test_3 = Expect<Equal<test_3_expected, test_3_actual>>; | ||
|
||
type test_4_actual = Count<ToySack, "๐๏ธ">; | ||
// ^? | ||
type test_4_expected = 3; | ||
type test_4 = Expect<Equal<test_4_expected, test_4_actual>>; | ||
|
||
type test_5_actual = Count<ToySack, "๐">; | ||
// ^? | ||
type test_5_expected = 5; | ||
type test_5 = Expect<Equal<test_5_expected, test_5_actual>>; |