test notnotea is deleted

master
Bel LaPointe 2022-02-10 07:17:06 -07:00
parent 954b8e932e
commit 72e17bdd43
3 changed files with 49 additions and 26 deletions

View File

@ -22,9 +22,6 @@ notnotea() (
}
_recurse_ids() {
_echo() {
echo "$*" || true
}
local prefix="$1"
local json="$2"
local b64lines="$(echo "$json" | jq -r '.Branches | keys[]' | base64)"
@ -35,31 +32,31 @@ notnotea() (
line="$(echo "$line" | base64 --decode)"
local subfix="$(printf "%s/%s" "$prefix" "$line")"
subfix="${subfix#/}"
_echo "$subfix"
if ! _is_deleted "$subfix"; then
echo "$subfix"
fi
_recurse_ids "$subfix" "$(echo "$json" | jq ".Branches.$line")"
done
}
meta() {
local key="$1"
key="${key//\//.Branches.}"
_tree | jq -c ".Branches.$key.Leaf"
local id="$1"
id="${id//\//.Branches.}"
_tree | jq -c ".Branches.$id.Leaf"
}
_is_deleted() {
local id="$1"
if [ "$id" == "root" ] || [ "$id" == "null" ]; then
return 1
fi
local meta="$(meta "$id")"
if echo "$meta" | jq .deleted | grep -q 1; then
return 0
fi
local pid="$(echo "$meta" | jq -r .pid)"
if [ -z "$pid" ]; then
return 0
fi
_is_deleted "$pid"
local id="$1"
while [ -n "$id" ]; do
if meta "$id" | jq .Deleted | grep -q true; then
return 0
fi
if [ "$id" == "${id%/*}" ]; then
return 1
fi
id="${id%/*}"
done
return 1
}
_tree_ids() {

View File

@ -1,6 +1,6 @@
#! /bin/bash
test__recurse_ids() {
test_ids() {
local two_levels='{
"Branches": {
"id": {
@ -12,9 +12,13 @@ test__recurse_ids() {
}
}
}'
(notnotea _recurse_ids "" "$two_levels"; true) | grep -q '^id$' || return 101
(notnotea _recurse_ids "" "$two_levels"; true) | tail -n 1 | grep -q '^id\/subid$' || return 102
notnotea _recurse_ids "" "$two_levels" | wc -l | grep -q 2 || return 103
notnotea eval "$(cat <<EOF
_tree() { echo '$two_levels'; true; }
(ids; true) | grep '^id$' > /dev/null || return 101
(ids; true) | grep '^id\/subid$' > /dev/null || return 102
ids | wc -l | grep 2 > /dev/null || return 103
EOF
)"
}
test_meta() {
@ -33,8 +37,30 @@ test_meta() {
}'
notnotea eval "$(cat <<EOF
_tree() { echo '$two_levels'; }
meta id | jq .Title | grep -q top.level || return 101
meta id/subid | jq .Title | grep -q sub.level || return 102
meta id | jq .Title | grep -q top.level || return 201
meta id/subid | jq .Title | grep -q sub.level || return 202
EOF
)"
}
test__is_deleted() {
local two_levels='{
"Branches": {
"id": {
"Leaf": {"Title": "top level", "Deleted": true},
"Branches": {
"subid": {
"Leaf": {"Title": "sub level"},
"Branches": {}
}
}
}
}
}'
notnotea eval "$(cat <<EOF
_tree() { echo '$two_levels'; }
_is_deleted id || return 301
_is_deleted id/subid || return 302
EOF
)"
}