#!/usr/bin/zsh # shellcheck disable=SC2219 # prefer let syntax alias kvstore='cargo run --' let 'kvstore_test_total_tried = 0' let 'kvstore_test_total_passed = 0' mark_pass() { let 'kvstore_test_total_tried = kvstore_test_total_tried + 1' let 'kvstore_test_total_passed = kvstore_test_total_passed + 1' echo "Pass: $kvstore_test_total_tried" } mark_fail() { let 'kvstore_test_total_tried = kvstore_test_total_tried + 1' echo "Fail: $kvstore_test_total_tried" } run_tests() { kvstore set t1 1 if [ "$(kvstore get t1)" = "Integer:1" ]; then mark_pass; else mark_fail; fi kvstore setString t2 1 if [ "$(kvstore get t2)" = "String:1" ]; then mark_pass; else mark_fail; fi kvstore setInt t3 1 if [ "$(kvstore getInt t3)" = "1" ]; then mark_pass; else mark_fail; fi kvstore setFloat t4 1.5 if [ "$(kvstore getFloat t4)" = "1.5" ]; then mark_pass; else mark_fail; fi kvstore setInt t5 7 kvstore increment t5 if [ "$(kvstore getInt t5)" = "8" ]; then mark_pass; else mark_fail; fi kvstore setInt t6 7 kvstore decrement t6 if [ "$(kvstore getInt t6)" = "6" ]; then mark_pass; else mark_fail; fi kvstore setInt t7 7 kvstore setInt t8 3 kvstore multiply t7 "$(kvstore getInt t8)" if [ "$(kvstore getInt t7)" = "21" ]; then mark_pass; else mark_fail; fi kvstore setInt t7 7 kvstore setInt t8 3 kvstore add t7 "$(kvstore getInt t8)" if [ "$(kvstore getInt t7)" = "10" ]; then mark_pass; else mark_fail; fi kvstore setInt t7 7 kvstore setInt t8 3 kvstore subtract t7 "$(kvstore getInt t8)" if [ "$(kvstore getInt t7)" = "4" ]; then mark_pass; else mark_fail; fi kvstore setInt t7 7 kvstore setInt t8 3 kvstore divide t7 "$(kvstore getInt t8)" if [ "$(kvstore getInt t7)" = "2" ]; then mark_pass; else mark_fail; fi kvstore setFloat t7 3 kvstore setFloat t8 0.5 kvstore multiply t7 "$(kvstore getFloat t8)" if [ "$(kvstore getFloat t7)" = "1.5" ]; then mark_pass; else mark_fail; fi kvstore setFloat t7 7 kvstore setFloat t8 2 kvstore divide t7 "$(kvstore getFloat t8)" if [ "$(kvstore getFloat t7)" = "3.5" ]; then mark_pass; else mark_fail; fi kvstore setString t7 "hello" kvstore append t7 " world" if [ "$(kvstore getString t7)" = "hello world" ]; then mark_pass; else mark_fail; fi kvstore setInt t7 1 kvstore setInt t8 2 kvstore add t7 t8 if [ "$(kvstore getInt t7)" = "3" ]; then mark_pass; else mark_fail; fi kvstore setInt t7 2 kvstore setInt t8 3 kvstore multiply t7 t8 if [ "$(kvstore getInt t7)" = "6" ]; then mark_pass; else mark_fail; fi kvstore setInt t7 2 local a=$(kvstore getInt t7) if [ "$a" = "2" ]; then mark_pass; else mark_fail; fi kvstore delete t7 local a=$(kvstore getInt t7) echo "^^^^^ intentional failure" if [ "$a" = "" ]; then mark_pass; else mark_fail; fi kvstore delete tString kvstore append tString hello if [ "$(kvstore getString tString)" = "hello" ]; then mark_pass; else mark_fail; fi } run_tests echo "----------" echo "| Result |" echo "----------" echo "Pass: $kvstore_test_total_passed" echo "Total: $kvstore_test_total_tried"