Skip to content

Commit fa09325

Browse files
committed
test: add placeholder tests for #26
1 parent c78c4e1 commit fa09325

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/augments.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { expect, it, describe } from 'vitest'
2+
import { expectTypeOf } from 'expect-type'
3+
4+
import { createRegExp, global, MagicRegExpMatchArray, MagicRegExp, char } from '../src'
5+
6+
describe('String', () => {
7+
it('.match non-global', () => {
8+
const result = 'test'.match(createRegExp(char.as('foo')))
9+
expect(Array.isArray(result)).toBeTruthy()
10+
expect(result?.groups?.foo).toEqual('t')
11+
expectTypeOf(result).toEqualTypeOf<MagicRegExpMatchArray<
12+
MagicRegExp<'/(?<foo>.)/', 'foo', never>
13+
> | null>()
14+
})
15+
it('.match global', () => {
16+
const result = 'test'.match(createRegExp(char.as('foo'), [global]))
17+
expect(Array.isArray(result)).toBeTruthy()
18+
expect(result?.groups).toBeUndefined()
19+
// TODO: https://github.com/danielroe/magic-regexp/issues/26
20+
// expectTypeOf(result).toEqualTypeOf<null | string[]>()
21+
})
22+
it.todo('.matchAll non-global', () => {
23+
// TODO: @ts-expect-error
24+
'test'.matchAll(createRegExp(char.as('foo')))
25+
})
26+
it('.matchAll global', () => {
27+
const results = 'test'.matchAll(createRegExp(char.as('foo'), [global]))
28+
expect(Array.isArray([...results])).toBeTruthy()
29+
for (const result of results) {
30+
expect(result?.groups).toBeUndefined()
31+
// TODO: https://github.com/danielroe/magic-regexp/issues/26
32+
// expectTypeOf(result).toEqualTypeOf<null | string[]>()
33+
}
34+
})
35+
})

0 commit comments

Comments
 (0)