Skip to content

Commit b6fd569

Browse files
committed
fix: #24 function uniq not working correctly with nullish types
1 parent 7d6ae32 commit b6fd569

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export const functions: FunctionBuildersMap = {
248248
const res: T[] = []
249249

250250
for (const item of data) {
251-
if (!res.find((resItem) => isEqual(resItem, item))) {
251+
if (res.findIndex((resItem) => isEqual(resItem, item)) === -1) {
252252
res.push(item)
253253
}
254254
}

test-suite/compile.test.json

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"source": "https://github.com/jsonquerylang/jsonquery/blob/v5.0.0/test-suite/compile.test.json",
3-
"version": "5.0.0",
2+
"source": "https://github.com/jsonquerylang/jsonquery/blob/v5.0.1/test-suite/compile.test.json",
3+
"version": "5.0.1",
44
"groups": [
55
{
66
"category": "value",
@@ -960,6 +960,17 @@
960960
}
961961
]
962962
},
963+
{
964+
"category": "uniq",
965+
"description": "should get unique values from a list with mixed nullish types",
966+
"tests": [
967+
{
968+
"input": [null, null, false, 0, "", null, false, 0, ""],
969+
"query": ["uniq"],
970+
"output": [null, false, 0, ""]
971+
}
972+
]
973+
},
963974
{
964975
"category": "uniqBy",
965976
"description": "should get unique objects by key (keeping the first)",
@@ -1208,7 +1219,10 @@
12081219
{ "input": null, "query": ["eq", true, false], "output": false },
12091220
{ "input": null, "query": ["eq", false, true], "output": false },
12101221
{ "input": null, "query": ["eq", false, true], "output": false },
1211-
{ "input": null, "query": ["eq", null, null], "output": true }
1222+
{ "input": null, "query": ["eq", false, false], "output": true },
1223+
{ "input": null, "query": ["eq", null, null], "output": true },
1224+
{ "input": null, "query": ["eq", 0, 0], "output": true },
1225+
{ "input": null, "query": ["eq", "", ""], "output": true }
12121226
]
12131227
},
12141228
{
@@ -1550,7 +1564,11 @@
15501564
"query": ["ne", ["get", "a"], ["get", "b"]],
15511565
"output": true
15521566
},
1553-
{ "input": null, "query": ["ne", 3, 2], "output": true }
1567+
{ "input": null, "query": ["ne", 3, 2], "output": true },
1568+
{ "input": null, "query": ["ne", false, false], "output": false },
1569+
{ "input": null, "query": ["ne", null, null], "output": false },
1570+
{ "input": null, "query": ["ne", 0, 0], "output": false },
1571+
{ "input": null, "query": ["ne", "", ""], "output": false }
15541572
]
15551573
},
15561574
{

test-suite/compile.test.schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema",
3-
"$id": "https://github.com/jsonquerylang/jsonquery/blob/v5.0.0/test-suite/compile.test.schema.json",
3+
"$id": "https://github.com/jsonquerylang/jsonquery/blob/v5.0.1/test-suite/compile.test.schema.json",
44
"type": "object",
55
"properties": {
66
"source": {
7-
"const": "https://github.com/jsonquerylang/jsonquery/blob/v5.0.0/test-suite/compile.test.json"
7+
"const": "https://github.com/jsonquerylang/jsonquery/blob/v5.0.1/test-suite/compile.test.json"
88
},
99
"version": {
10-
"const": "5.0.0"
10+
"const": "5.0.1"
1111
},
1212
"groups": {
1313
"type": "array",

0 commit comments

Comments
 (0)