Files
drharness/tests/test_json_variant.sh
hal9000 ffcc907a99 Add std::variant JSON serialization infrastructure (issue 150)
- Add #include <variant> header
- Add json_type_for_type() helper for type-based disambiguation
- Add to_json for std::variant that serializes active alternative
- Add variant_try_helper_impl for recursive variant deserialization
- Add json_to_impl specialization for std::variant
- Add TestVariantType (std::variant<std::string, std::vector<FunctionCall>>)
  for testing variant serialization
- Register TestVariantType in json_dispatch_map for -R debug flag
- Add compile-time static_assert for TestVariantType
- Add test_json_variant.sh test suite
- Add test to CMakeLists.txt
2026-06-11 21:13:10 +00:00

68 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
# test_json_variant.sh - Tests for std::variant JSON serialization/deserialization
# Test TestVariantType with string alternative (JSON string)
OUTPUT=$("${DRHARNESS}" -R TestVariantType '"hello world"')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: TestVariantType string alternative - expected 'success', got '${OUTPUT}'"
exit 1
fi
# Test TestVariantType with vector alternative (JSON array with valid FunctionCall)
OUTPUT=$("${DRHARNESS}" -R TestVariantType '[{"name": "test", "arguments": "{}"}]')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: TestVariantType vector alternative - expected 'success', got '${OUTPUT}'"
exit 1
fi
# Test TestVariantType with empty vector
OUTPUT=$("${DRHARNESS}" -R TestVariantType '[]')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: TestVariantType empty vector - expected 'success', got '${OUTPUT}'"
exit 1
fi
# Test TestVariantType with multiple FunctionCalls in vector
OUTPUT=$("${DRHARNESS}" -R TestVariantType '[{"name": "func1", "arguments": "{}"}, {"name": "func2", "arguments": "{}"}]')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: TestVariantType multiple items in vector - expected 'success', got '${OUTPUT}'"
exit 1
fi
# Test TestVariantType with invalid JSON type (number - no matching alternative)
OUTPUT=$("${DRHARNESS}" -R TestVariantType '123')
if [ "${OUTPUT}" != "error: no variant alternative matched JSON type" ]; then
echo "FAIL: TestVariantType number type - expected error, got '${OUTPUT}'"
exit 1
fi
# Test TestVariantType with invalid JSON type (object - no matching alternative)
OUTPUT=$("${DRHARNESS}" -R TestVariantType '{"name": "test"}')
if [ "${OUTPUT}" != "error: no variant alternative matched JSON type" ]; then
echo "FAIL: TestVariantType object type - expected error, got '${OUTPUT}'"
exit 1
fi
# Test TestVariantType with invalid JSON type (boolean - no matching alternative)
OUTPUT=$("${DRHARNESS}" -R TestVariantType 'true')
if [ "${OUTPUT}" != "error: no variant alternative matched JSON type" ]; then
echo "FAIL: TestVariantType boolean type - expected error, got '${OUTPUT}'"
exit 1
fi
# Test TestVariantType with empty string (valid string alternative)
OUTPUT=$("${DRHARNESS}" -R TestVariantType '""')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: TestVariantType empty string - expected 'success', got '${OUTPUT}'"
exit 1
fi
# Test TestVariantType with vector containing FunctionCall with only optional fields
OUTPUT=$("${DRHARNESS}" -R TestVariantType '[{"name": "test"}]')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: TestVariantType partial FunctionCall - expected 'success', got '${OUTPUT}'"
exit 1
fi
echo "All variant tests passed!"