Skip to content

Commit 1385798

Browse files
committed
feat: update function split according to the test suite
1 parent 4a3ff85 commit 1385798

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

jsonquerylang/functions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ def key_by(data):
143143

144144
fn_flatten = lambda: lambda data: [x for xs in data for x in xs]
145145
fn_join = lambda separator="": lambda data: separator.join(data)
146-
fn_split = lambda separator=None: lambda data: (
147-
data.split(separator) if separator is not "" else split_chars(data)
146+
fn_split = build_function(
147+
lambda text, separator=None: (
148+
text.split(separator) if separator is not "" else split_chars(text)
149+
)
148150
)
149151
fn_substring = lambda start, end=None: lambda data: data[max(start, 0) : end]
150152
fn_uniq = lambda: lambda data: list(dict.fromkeys(data))

tests/test-suite/compile.test.json

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -505,30 +505,37 @@
505505

506506
{
507507
"category": "split",
508-
"description": "should split a string",
509-
"input": "start with a b c",
510-
"query": ["split"],
508+
"description": "should split a string (1)",
509+
"input": null,
510+
"query": ["split", "start with a b c"],
511+
"output": ["start", "with", "a", "b", "c"]
512+
},
513+
{
514+
"category": "split",
515+
"description": "should split a string (2)",
516+
"input": { "message": "start with a b c" },
517+
"query": ["split", ["get", "message"]],
511518
"output": ["start", "with", "a", "b", "c"]
512519
},
513520
{
514521
"category": "split",
515522
"description": "should split a string with multiple whitespaces between the words",
516-
"input": " \n\n\t start with a b \n\r\t c \n\n\t ",
517-
"query": ["split"],
523+
"input": null,
524+
"query": ["split", " \n\n\t start with a b \n\r\t c \n\n\t "],
518525
"output": ["start", "with", "a", "b", "c"]
519526
},
520527
{
521528
"category": "split",
522529
"description": "should split a string by individual characters",
523-
"input": "abc",
524-
"query": ["split", ""],
530+
"input": null,
531+
"query": ["split", "abc", ""],
525532
"output": ["a", "b", "c"]
526533
},
527534
{
528535
"category": "split",
529536
"description": "should split a string with a separator",
530-
"input": "a,b,c",
531-
"query": ["split", ","],
537+
"input": null,
538+
"query": ["split", "a,b,c", ","],
532539
"output": ["a", "b", "c"]
533540
},
534541

0 commit comments

Comments
 (0)