#!/bin/bash

# Copyright (C) 2016, 2017  Stefan Vargyas
# 
# This file is part of Json-Type.
# 
# Json-Type is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# Json-Type is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with Json-Type.  If not, see <http://www.gnu.org/licenses/>.

#
# File generated by a command like:
# $ json-gentest -C type-cases:17
#

[[ "$1" =~ ^-u[0-9]+$ ]] &&
u="${1:2}" ||
u=""

diff -u$u -L 17.old <(echo \
'$ json() { set -o pipefail && LD_LIBRARY_PATH=../lib ../src/json --terse --verbose --literal-value "$@" 2>&1|sed -r '\''/error:/s|(/dev/fd/)[0-9]+|\1??|'\''; }
$ json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"string"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":1,"bar":null}'\''
json: error: <stdin>:1:9: type check error: too many arguments
json: error: <stdin>:1:9: {"foo":1,"bar":null}
json: error: <stdin>:1:9:         ^
{"foo":1
command failed: json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"string"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":1,"bar":null}'\''
$ json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"string"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":"","bar":null}'\''
json: error: <stdin>:1:17: type check error: type mismatch: expected a value of type `"array"'\''
json: error: <stdin>:1:17: {"foo":"","bar":null}
json: error: <stdin>:1:17:                 ^
{"foo":"","bar":
command failed: json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"string"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":"","bar":null}'\''
$ json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"string"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":"","bar":[1]}'\''
{"foo":"","bar":[1]}
$ json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"number"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":"","bar":[1]}'\''
json: error: <stdin>:1:8: type check error: type mismatch: expected a value of type `"number"'\''
json: error: <stdin>:1:8: {"foo":"","bar":[1]}
json: error: <stdin>:1:8:        ^
{"foo":
command failed: json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"number"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":"","bar":[1]}'\''
$ json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"number"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":1,"bar":null}'\''
json: error: <stdin>:1:16: type check error: type mismatch: expected a value of type `"array"'\''
json: error: <stdin>:1:16: {"foo":1,"bar":null}
json: error: <stdin>:1:16:                ^
{"foo":1,"bar":
command failed: json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"number"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":1,"bar":null}'\''
$ json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"number"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":1,"bar":[],"baz":null}'\''
json: error: <stdin>:1:18: type check error: too many arguments
json: error: <stdin>:1:18: {"foo":1,"bar":[],"baz":null}
json: error: <stdin>:1:18:                  ^
{"foo":1,"bar":[]
command failed: json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"number"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":1,"bar":[],"baz":null}'\'''
) -L 17.new <(
echo '$ json() { set -o pipefail && LD_LIBRARY_PATH=../lib ../src/json --terse --verbose --literal-value "$@" 2>&1|sed -r '\''/error:/s|(/dev/fd/)[0-9]+|\1??|'\''; }'
json() { set -o pipefail && LD_LIBRARY_PATH=../lib ../src/json --terse --verbose --literal-value "$@" 2>&1|sed -r '/error:/s|(/dev/fd/)[0-9]+|\1??|'; } 2>&1 ||
echo 'command failed: json() { set -o pipefail && LD_LIBRARY_PATH=../lib ../src/json --terse --verbose --literal-value "$@" 2>&1|sed -r '\''/error:/s|(/dev/fd/)[0-9]+|\1??|'\''; }'

echo '$ json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"string"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":1,"bar":null}'\'''
json -d '{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"string"},{"name":"bar","type":"array"}]}]}' <<< '{"foo":1,"bar":null}' 2>&1 ||
echo 'command failed: json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"string"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":1,"bar":null}'\'''

echo '$ json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"string"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":"","bar":null}'\'''
json -d '{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"string"},{"name":"bar","type":"array"}]}]}' <<< '{"foo":"","bar":null}' 2>&1 ||
echo 'command failed: json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"string"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":"","bar":null}'\'''

echo '$ json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"string"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":"","bar":[1]}'\'''
json -d '{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"string"},{"name":"bar","type":"array"}]}]}' <<< '{"foo":"","bar":[1]}' 2>&1 ||
echo 'command failed: json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"string"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":"","bar":[1]}'\'''

echo '$ json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"number"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":"","bar":[1]}'\'''
json -d '{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"number"},{"name":"bar","type":"array"}]}]}' <<< '{"foo":"","bar":[1]}' 2>&1 ||
echo 'command failed: json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"number"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":"","bar":[1]}'\'''

echo '$ json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"number"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":1,"bar":null}'\'''
json -d '{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"number"},{"name":"bar","type":"array"}]}]}' <<< '{"foo":1,"bar":null}' 2>&1 ||
echo 'command failed: json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"number"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":1,"bar":null}'\'''

echo '$ json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"number"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":1,"bar":[],"baz":null}'\'''
json -d '{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"number"},{"name":"bar","type":"array"}]}]}' <<< '{"foo":1,"bar":[],"baz":null}' 2>&1 ||
echo 'command failed: json -d '\''{"type":"list","args":[{"type":"object","args":[{"name":"foo","type":"number"}]},{"type":"object","args":[{"name":"foo","type":"number"},{"name":"bar","type":"array"}]}]}'\'' <<< '\''{"foo":1,"bar":[],"baz":null}'\'''
)

