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

View File

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