MCPcopy
hub / github.com/gvergnaud/ts-pattern / testFn

Function testFn

tests/multiple-patterns.test.ts:7–31  ·  view source on GitHub ↗
(input: Option<number>)

Source from the content-addressed store, hash-verified

5describe('Multiple patterns', () => {
6 it('should match if one of the patterns matches', () => {
7 const testFn = (input: Option<number>) =>
8 match(input)
9 .with(
10 { kind: 'some', value: 2 as const },
11 { kind: 'some', value: 3 as const },
12 { kind: 'some', value: 4 as const },
13 (x) => {
14 type t = Expect<
15 Equal<
16 typeof x,
17 | { kind: 'some'; value: 2 }
18 | { kind: 'some'; value: 3 }
19 | { kind: 'some'; value: 4 }
20 >
21 >;
22 return true;
23 }
24 )
25 .with({ kind: 'none' }, { kind: 'some' }, (x) => {
26 type t = Expect<
27 Equal<typeof x, { kind: 'some'; value: number } | { kind: 'none' }>
28 >;
29 return false;
30 })
31 .run();
32
33 const cases = [
34 { input: { kind: 'some', value: 3 }, expected: true },

Callers 1

Calls 4

matchFunction · 0.90
runMethod · 0.80
withMethod · 0.80
exhaustiveMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…