summaryrefslogtreecommitdiff
path: root/tests/basic.spec.ts
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2022-01-25 00:21:07 +0530
committerAkshay Nair <phenax5@gmail.com>2022-01-25 00:21:07 +0530
commit35930fd49039ec48680c9240cfdb39b6e1101bfa (patch)
tree7c5196a0952d91349ac8b35e5a3553c39305f646 /tests/basic.spec.ts
parentea0baf1bb82d40ebfcaca1de6a2a0f6d56c709e7 (diff)
downloadelxr-35930fd49039ec48680c9240cfdb39b6e1101bfa.tar.gz
elxr-35930fd49039ec48680c9240cfdb39b6e1101bfa.zip
feat(eval): adds eval for regex
Diffstat (limited to 'tests/basic.spec.ts')
-rw-r--r--tests/basic.spec.ts58
1 files changed, 34 insertions, 24 deletions
diff --git a/tests/basic.spec.ts b/tests/basic.spec.ts
index 86fdb7c..f02169c 100644
--- a/tests/basic.spec.ts
+++ b/tests/basic.spec.ts
@@ -1,4 +1,4 @@
-import {jlog} from '../src/utils'
+import { jlog } from '../src/utils'
import { matchAll } from '../src'
describe('Basic tests', () => {
@@ -43,6 +43,28 @@ describe('Basic tests', () => {
{ value: true, index: 3 },
],
)
+
+ expect(
+ matchAll(/ [name "foobar"] /, [
+ {},
+ { name: 'foobar' },
+ { name: 'fuck' },
+ ]).groups,
+ ).toEqual([{ value: { name: 'foobar' }, index: 1 }])
+
+ expect(
+ matchAll(/ [name "test" | \/foo(bar|baz)\/] /, [
+ { name: 'test' },
+ { name: 'foobar' },
+ { name: 'foo' },
+ { name: 'foobaz' },
+ {},
+ ]).groups,
+ ).toEqual([
+ { value: { name: 'test' }, index: 0 },
+ { value: { name: 'foobar' }, index: 1 },
+ { value: { name: 'foobaz' }, index: 3 },
+ ])
})
it('should match simple expression', () => {
@@ -200,31 +222,17 @@ describe('Basic tests', () => {
})
it('should match min-max quantified expressions', () => {
- expect(
- matchAll(/[age \n]{2, 4}/, [
- {},
- { age: 1 },
- '',
- ]).groups,
- ).toEqual([])
+ expect(matchAll(/[age \n]{2, 4}/, [{}, { age: 1 }, '']).groups).toEqual(
+ [],
+ )
expect(
- matchAll(/[age \n]{2, 4}/, [
- {},
- { age: 1 },
- { age: 0 },
- '',
- ]).groups,
+ matchAll(/[age \n]{2, 4}/, [{}, { age: 1 }, { age: 0 }, '']).groups,
).toEqual([{ value: [{ age: 1 }, { age: 0 }], index: 1 }])
expect(
- matchAll(/[age \n]{2, 4}/, [
- {},
- { age: 1 },
- { age: 2 },
- { age: 0 },
- '',
- ]).groups,
+ matchAll(/[age \n]{2, 4}/, [{}, { age: 1 }, { age: 2 }, { age: 0 }, ''])
+ .groups,
).toEqual([{ value: [{ age: 1 }, { age: 2 }, { age: 0 }], index: 1 }])
expect(
@@ -237,7 +245,9 @@ describe('Basic tests', () => {
{ age: 4 },
'',
]).groups,
- ).toEqual([{ value: [{ age: 1 }, { age: 2 }, { age: 0 }, { age: 8 }], index: 1 }])
+ ).toEqual([
+ { value: [{ age: 1 }, { age: 2 }, { age: 0 }, { age: 8 }], index: 1 },
+ ])
expect(
matchAll(/[age \n]{2, 4}/, [
@@ -251,8 +261,8 @@ describe('Basic tests', () => {
'',
]).groups,
).toEqual([
- { value: [{ age: 1 }, { age: 2 }, { age: 0 }, { age: 8 }], index: 1 },
- { value: [{ age: 4 }, { age: 9 }], index: 5 },
+ { value: [{ age: 1 }, { age: 2 }, { age: 0 }, { age: 8 }], index: 1 },
+ { value: [{ age: 4 }, { age: 9 }], index: 5 },
])
})
})