mirror of
https://github.com/johnkerl/miller.git
synced 2026-01-23 02:14:13 +00:00
New strmatch/strmatchx DSL functions (#1448)
* New `match`/`matchx` DSL functions * unit-test cases * match/matchx -> strmatch/strmatchx * help strings for strmatch and strmatchx * update regex doc page re strmatch/strmatchx * unit-test update
This commit is contained in:
parent
211b15ad4f
commit
c6b745537a
21 changed files with 747 additions and 34 deletions
1
test/cases/dsl-match/0001/cmd
Normal file
1
test/cases/dsl-match/0001/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --ojsonl --from ${CASEDIR}/input put -f ${CASEDIR}/mlr
|
||||
0
test/cases/dsl-match/0001/experr
Normal file
0
test/cases/dsl-match/0001/experr
Normal file
11
test/cases/dsl-match/0001/expout
Normal file
11
test/cases/dsl-match/0001/expout
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{"x": "a", "y": "b", "z": false}
|
||||
{"x": "abc", "y": "ab", "z": true}
|
||||
{"x": " 345 78 ", "y": "([0-9]+)", "z": true}
|
||||
{"x": " 345 78 ", "y": "([0-9]+) ([0-9]+)", "z": true}
|
||||
{"x": " 345 78 ", "y": "([0-9]+)(.)([0-9]+)", "z": true}
|
||||
{"x": "", "y": "", "z": true}
|
||||
{"x": "", "y": "b", "z": false}
|
||||
{"x": "a", "y": "", "z": true}
|
||||
{"x": "a", "z": (error)}
|
||||
{"y": "b", "z": (error)}
|
||||
{"foo": "bar", "z": (error)}
|
||||
11
test/cases/dsl-match/0001/input
Normal file
11
test/cases/dsl-match/0001/input
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
x=a,y=b
|
||||
x=abc,y=ab
|
||||
x= 345 78 ,y=([0-9]+)
|
||||
x= 345 78 ,y=([0-9]+) ([0-9]+)
|
||||
x= 345 78 ,y=([0-9]+)(.)([0-9]+)
|
||||
x=,y=
|
||||
x=,y=b
|
||||
x=a,y=
|
||||
x=a
|
||||
y=b
|
||||
foo=bar
|
||||
1
test/cases/dsl-match/0001/mlr
Normal file
1
test/cases/dsl-match/0001/mlr
Normal file
|
|
@ -0,0 +1 @@
|
|||
$z = strmatch($x, $y)
|
||||
1
test/cases/dsl-match/0002/cmd
Normal file
1
test/cases/dsl-match/0002/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --ojson --from ${CASEDIR}/input put -f ${CASEDIR}/mlr
|
||||
0
test/cases/dsl-match/0002/experr
Normal file
0
test/cases/dsl-match/0002/experr
Normal file
110
test/cases/dsl-match/0002/expout
Normal file
110
test/cases/dsl-match/0002/expout
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
[
|
||||
{
|
||||
"x": "a",
|
||||
"y": "b",
|
||||
"z": {
|
||||
"matched": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"x": "abc",
|
||||
"y": "ab",
|
||||
"z": {
|
||||
"matched": true,
|
||||
"full_capture": "ab",
|
||||
"full_start": 1,
|
||||
"full_end": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"x": " 345 78 ",
|
||||
"y": "([0-9]+)",
|
||||
"z": {
|
||||
"matched": true,
|
||||
"full_capture": "345",
|
||||
"full_start": 3,
|
||||
"full_end": 5,
|
||||
"captures": ["345"],
|
||||
"starts": [3],
|
||||
"ends": [5]
|
||||
}
|
||||
},
|
||||
{
|
||||
"x": " 345 78 ",
|
||||
"y": "([0-9]+) ([0-9]+)",
|
||||
"z": {
|
||||
"matched": true,
|
||||
"full_capture": "345 78",
|
||||
"full_start": 3,
|
||||
"full_end": 8,
|
||||
"captures": ["345", "78"],
|
||||
"starts": [3, 7],
|
||||
"ends": [5, 8]
|
||||
}
|
||||
},
|
||||
{
|
||||
"x": " 345 78 ",
|
||||
"y": "([0-9]+)(.)([0-9]+)",
|
||||
"z": {
|
||||
"matched": true,
|
||||
"full_capture": "345 78",
|
||||
"full_start": 3,
|
||||
"full_end": 8,
|
||||
"captures": ["345", " ", "78"],
|
||||
"starts": [3, 6, 7],
|
||||
"ends": [5, 6, 8]
|
||||
}
|
||||
},
|
||||
{
|
||||
"x": "",
|
||||
"y": "",
|
||||
"z": {
|
||||
"matched": true,
|
||||
"full_capture": "",
|
||||
"full_start": 1,
|
||||
"full_end": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"x": "",
|
||||
"y": "b",
|
||||
"z": {
|
||||
"matched": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"x": "a",
|
||||
"y": "",
|
||||
"z": {
|
||||
"matched": true,
|
||||
"full_capture": "",
|
||||
"full_start": 1,
|
||||
"full_end": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"x": "a",
|
||||
"z": (error)
|
||||
},
|
||||
{
|
||||
"y": "b",
|
||||
"z": (error)
|
||||
},
|
||||
{
|
||||
"foo": "bar",
|
||||
"z": (error)
|
||||
},
|
||||
{
|
||||
"x": "1234567890abcdefghij",
|
||||
"y": "(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)",
|
||||
"z": {
|
||||
"matched": true,
|
||||
"full_capture": "1234567890abcdefghij",
|
||||
"full_start": 1,
|
||||
"full_end": 20,
|
||||
"captures": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"],
|
||||
"starts": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
|
||||
"ends": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
|
||||
}
|
||||
}
|
||||
]
|
||||
12
test/cases/dsl-match/0002/input
Normal file
12
test/cases/dsl-match/0002/input
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
x=a,y=b
|
||||
x=abc,y=ab
|
||||
x= 345 78 ,y=([0-9]+)
|
||||
x= 345 78 ,y=([0-9]+) ([0-9]+)
|
||||
x= 345 78 ,y=([0-9]+)(.)([0-9]+)
|
||||
x=,y=
|
||||
x=,y=b
|
||||
x=a,y=
|
||||
x=a
|
||||
y=b
|
||||
foo=bar
|
||||
x=1234567890abcdefghij,y=(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)
|
||||
1
test/cases/dsl-match/0002/mlr
Normal file
1
test/cases/dsl-match/0002/mlr
Normal file
|
|
@ -0,0 +1 @@
|
|||
$z = strmatchx($x, $y)
|
||||
Loading…
Add table
Add a link
Reference in a new issue