Skip to content

Commit 229cd27

Browse files
committed
Add JSON compare utility for testing
1 parent 3041006 commit 229cd27

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

scripts/compare-jsonl.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if [ "$#" -ne 2 ]; then
5+
echo "Usage: $0 <left.jsonl|jsonl.gz> <right.jsonl|jsonl.gz>" >&2
6+
exit 2
7+
fi
8+
9+
read_jsonl() {
10+
case "$1" in
11+
*.gz) gzip -dc -- "$1" ;;
12+
*) cat -- "$1" ;;
13+
esac
14+
}
15+
16+
normalize() {
17+
jq -S -c '
18+
if .recordType == "node" then
19+
{
20+
recordType: "node",
21+
labels: (.labels | sort),
22+
properties: .properties
23+
}
24+
elif .recordType == "relationship" then
25+
{
26+
recordType: "relationship",
27+
type: .type,
28+
properties: .properties
29+
}
30+
else
31+
error("Unsupported recordType: \(.recordType)")
32+
end
33+
'
34+
}
35+
36+
if diff -u \
37+
<(read_jsonl "$1" | sed "/^[[:space:]]*$/d" | normalize | LC_ALL=C sort) \
38+
<(read_jsonl "$2" | sed "/^[[:space:]]*$/d" | normalize | LC_ALL=C sort); then
39+
echo "JSONL content matches."
40+
else
41+
echo "JSONL content differs." >&2
42+
exit 1
43+
fi

0 commit comments

Comments
 (0)