test notnotea is deleted
parent
954b8e932e
commit
72e17bdd43
|
|
@ -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
|
||||||
return 1
|
if meta "$id" | jq .Deleted | grep -q true; then
|
||||||
fi
|
return 0
|
||||||
local meta="$(meta "$id")"
|
fi
|
||||||
if echo "$meta" | jq .deleted | grep -q 1; then
|
if [ "$id" == "${id%/*}" ]; then
|
||||||
return 0
|
return 1
|
||||||
fi
|
fi
|
||||||
local pid="$(echo "$meta" | jq -r .pid)"
|
id="${id%/*}"
|
||||||
if [ -z "$pid" ]; then
|
done
|
||||||
return 0
|
return 1
|
||||||
fi
|
|
||||||
_is_deleted "$pid"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_tree_ids() {
|
_tree_ids() {
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
)"
|
)"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue