From d4f1f96e45b908b0055cf6e0730ab22172a75581 Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Fri, 2 Aug 2024 18:15:41 +0200 Subject: [PATCH 1/3] Add more tests for selectors --- tests/basic.json | 21 +++++++++++ tests/index_selector.json | 48 +++++++++++++++++++++++++ tests/slice_selector.json | 73 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+) diff --git a/tests/basic.json b/tests/basic.json index eb30e40..0063d30 100644 --- a/tests/basic.json +++ b/tests/basic.json @@ -170,6 +170,16 @@ "selector": "$[0 2]", "invalid_selector": true }, + { + "name": "selector, leading comma", + "selector": "$[,0]", + "invalid_selector": true + }, + { + "name": "selector, trailing comma", + "selector": "$[0,]", + "invalid_selector": true + }, { "name": "multiple selectors, name and index, array data", "selector": "$['a',1]", @@ -200,6 +210,17 @@ 1 ] }, + { + "name": "multiple selectors, spaces", + "selector": "$[ 'a' , 1 ]", + "document": { + "a": 1, + "b": 2 + }, + "result": [ + 1 + ] + }, { "name": "multiple selectors, index and slice", "selector": "$[1,5:7]", diff --git a/tests/index_selector.json b/tests/index_selector.json index ae70358..0e0d17a 100644 --- a/tests/index_selector.json +++ b/tests/index_selector.json @@ -31,6 +31,34 @@ ], "result": [] }, + { + "name": "min exact index", + "selector": "$[-9007199254740991]", + "document": [ + "first", + "second" + ], + "result": [] + }, + { + "name": "max exact index", + "selector": "$[9007199254740991]", + "document": [ + "first", + "second" + ], + "result": [] + }, + { + "name": "min exact index - 1", + "selector": "$[-9007199254740992]", + "invalid_selector": true + }, + { + "name": "max exact index + 1", + "selector": "$[9007199254740992]", + "invalid_selector": true + }, { "name": "overflowing index", "selector": "$[231584178474632390847141970017375815706539969331281128078915168015826259279872]", @@ -85,6 +113,26 @@ "selector": "$[01]", "invalid_selector": true }, + { + "name": "decimal", + "selector": "$[1.0]", + "invalid_selector": true + }, + { + "name": "plus", + "selector": "$[+1]", + "invalid_selector": true + }, + { + "name": "minus space", + "selector": "$[- 1]", + "invalid_selector": true + }, + { + "name": "-0", + "selector": "$[-0]", + "invalid_selector": true + }, { "name": "leading -0", "selector": "$[-01]", diff --git a/tests/slice_selector.json b/tests/slice_selector.json index ca5a2e4..fcf4b7a 100644 --- a/tests/slice_selector.json +++ b/tests/slice_selector.json @@ -41,6 +41,27 @@ 5 ] }, + { + "name": "slice selector with spaces", + "selector": "$[ 1 : 6 : 2 ]", + "document": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "result": [ + 1, + 3, + 5 + ] + }, { "name": "slice selector with everything omitted, short form", "selector": "$[:]", @@ -610,6 +631,28 @@ 9 ] }, + { + "name": "min exact", + "selector": "$[:-9007199254740991:]", + "document": [], + "result": [] + }, + { + "name": "max exact", + "selector": "$[:9007199254740991:]", + "document": [], + "result": [] + }, + { + "name": "min exact - 1", + "selector": "$[:-9007199254740992:]", + "invalid_selector": true + }, + { + "name": "max exact + 1", + "selector": "$[:9007199254740992:]", + "invalid_selector": true + }, { "name": "overflowing to value", "selector": "$[2:231584178474632390847141970017375815706539969331281128078915168015826259279872]", @@ -639,6 +682,36 @@ "name": "underflowing step", "selector": "$[-1:-10:-231584178474632390847141970017375815706539969331281128078915168015826259279872]", "invalid_selector": true + }, + { + "name": "leading 0", + "selector": "$[:01:]", + "invalid_selector": true + }, + { + "name": "decimal", + "selector": "$[:1.0:]", + "invalid_selector": true + }, + { + "name": "plus", + "selector": "$[:+1:]", + "invalid_selector": true + }, + { + "name": "minus space", + "selector": "$[:- 1:]", + "invalid_selector": true + }, + { + "name": "-0", + "selector": "$[:-0:]", + "invalid_selector": true + }, + { + "name": "leading -0", + "selector": "$[:-01:]", + "invalid_selector": true } ] } From b83d681e8038afe8af07b21e571994dbb30341f2 Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Sat, 3 Aug 2024 16:11:31 +0200 Subject: [PATCH 2/3] Remove duplicated whitespace tests --- tests/basic.json | 11 ----------- tests/slice_selector.json | 21 --------------------- 2 files changed, 32 deletions(-) diff --git a/tests/basic.json b/tests/basic.json index 0063d30..e85ac6d 100644 --- a/tests/basic.json +++ b/tests/basic.json @@ -210,17 +210,6 @@ 1 ] }, - { - "name": "multiple selectors, spaces", - "selector": "$[ 'a' , 1 ]", - "document": { - "a": 1, - "b": 2 - }, - "result": [ - 1 - ] - }, { "name": "multiple selectors, index and slice", "selector": "$[1,5:7]", diff --git a/tests/slice_selector.json b/tests/slice_selector.json index fcf4b7a..fa99741 100644 --- a/tests/slice_selector.json +++ b/tests/slice_selector.json @@ -41,27 +41,6 @@ 5 ] }, - { - "name": "slice selector with spaces", - "selector": "$[ 1 : 6 : 2 ]", - "document": [ - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9 - ], - "result": [ - 1, - 3, - 5 - ] - }, { "name": "slice selector with everything omitted, short form", "selector": "$[:]", From 4e9f117445f6adbfcf80ef18fbb3c20f8e760a8a Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Sat, 3 Aug 2024 22:59:21 +0200 Subject: [PATCH 3/3] Extend slice tests for start and step arguments --- tests/slice_selector.json | 124 +++++++++++++++++++++++++++++++++++--- 1 file changed, 114 insertions(+), 10 deletions(-) diff --git a/tests/slice_selector.json b/tests/slice_selector.json index fa99741..e6cd723 100644 --- a/tests/slice_selector.json +++ b/tests/slice_selector.json @@ -611,27 +611,71 @@ ] }, { - "name": "min exact", + "name": "start, min exact", + "selector": "$[-9007199254740991::]", + "document": [], + "result": [] + }, + { + "name": "start, max exact", + "selector": "$[9007199254740991::]", + "document": [], + "result": [] + }, + { + "name": "start, min exact - 1", + "selector": "$[-9007199254740992::]", + "invalid_selector": true + }, + { + "name": "start, max exact + 1", + "selector": "$[9007199254740992::]", + "invalid_selector": true + }, + { + "name": "end, min exact", "selector": "$[:-9007199254740991:]", "document": [], "result": [] }, { - "name": "max exact", + "name": "end, max exact", "selector": "$[:9007199254740991:]", "document": [], "result": [] }, { - "name": "min exact - 1", + "name": "end, min exact - 1", "selector": "$[:-9007199254740992:]", "invalid_selector": true }, { - "name": "max exact + 1", + "name": "end, max exact + 1", "selector": "$[:9007199254740992:]", "invalid_selector": true }, + { + "name": "step, min exact", + "selector": "$[::-9007199254740991]", + "document": [], + "result": [] + }, + { + "name": "step, max exact", + "selector": "$[::9007199254740991]", + "document": [], + "result": [] + }, + { + "name": "step, min exact - 1", + "selector": "$[::-9007199254740992]", + "invalid_selector": true + }, + { + "name": "step, max exact + 1", + "selector": "$[::9007199254740992]", + "invalid_selector": true + }, { "name": "overflowing to value", "selector": "$[2:231584178474632390847141970017375815706539969331281128078915168015826259279872]", @@ -663,34 +707,94 @@ "invalid_selector": true }, { - "name": "leading 0", + "name": "start, leading 0", + "selector": "$[01::]", + "invalid_selector": true + }, + { + "name": "start, decimal", + "selector": "$[1.0::]", + "invalid_selector": true + }, + { + "name": "start, plus", + "selector": "$[+1::]", + "invalid_selector": true + }, + { + "name": "start, minus space", + "selector": "$[- 1::]", + "invalid_selector": true + }, + { + "name": "start, -0", + "selector": "$[-0::]", + "invalid_selector": true + }, + { + "name": "start, leading -0", + "selector": "$[-01::]", + "invalid_selector": true + }, + { + "name": "end, leading 0", "selector": "$[:01:]", "invalid_selector": true }, { - "name": "decimal", + "name": "end, decimal", "selector": "$[:1.0:]", "invalid_selector": true }, { - "name": "plus", + "name": "end, plus", "selector": "$[:+1:]", "invalid_selector": true }, { - "name": "minus space", + "name": "end, minus space", "selector": "$[:- 1:]", "invalid_selector": true }, { - "name": "-0", + "name": "end, -0", "selector": "$[:-0:]", "invalid_selector": true }, { - "name": "leading -0", + "name": "end, leading -0", "selector": "$[:-01:]", "invalid_selector": true + }, + { + "name": "step, leading 0", + "selector": "$[::01]", + "invalid_selector": true + }, + { + "name": "step, decimal", + "selector": "$[::1.0]", + "invalid_selector": true + }, + { + "name": "step, plus", + "selector": "$[::+1]", + "invalid_selector": true + }, + { + "name": "step, minus space", + "selector": "$[::- 1]", + "invalid_selector": true + }, + { + "name": "step, -0", + "selector": "$[::-0]", + "invalid_selector": true + }, + { + "name": "step, leading -0", + "selector": "$[::-01]", + "invalid_selector": true } ] }