#!/bin/bash

# Copyright (C) 2016  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-lib:literal-value
#

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

diff -u$u -L literal-value.old <(echo \
'$ json() { set -o pipefail && LD_LIBRARY_PATH=../lib ../src/json --literal-value -V -TA "$@"|LD_LIBRARY_PATH=../lib ../src/json --from-ast-print --verbose --no-error; }
$ json <<< '\''null'\''
json: error: <stdin>:1:1: meta error: invalid top value: it must be a type or an array of "name" objects
json: error: <stdin>:1:1: null
json: error: <stdin>:1:1: ^
command failed: json <<< '\''null'\''
$ json <<< '\''false'\''
json: error: <stdin>:1:1: meta error: invalid top value: it must be a type or an array of "name" objects
json: error: <stdin>:1:1: false
json: error: <stdin>:1:1: ^
command failed: json <<< '\''false'\''
$ json <<< '\''true'\''
json: error: <stdin>:1:1: meta error: invalid top value: it must be a type or an array of "name" objects
json: error: <stdin>:1:1: true
json: error: <stdin>:1:1: ^
command failed: json <<< '\''true'\''
$ json <<< '\''123'\''
json: error: <stdin>:1:1: meta error: invalid top value: it must be a type or an array of "name" objects
json: error: <stdin>:1:1: 123
json: error: <stdin>:1:1: ^
command failed: json <<< '\''123'\''
$ json <<< '\''"foo"'\''
json: error: <stdin>:1:1: meta error: invalid top value: it must be a type or an array of "name" objects
json: error: <stdin>:1:1: "foo"
json: error: <stdin>:1:1: ^
command failed: json <<< '\''"foo"'\''
$ json <<< '\''"type"'\''
command failed: json <<< '\''"type"'\''
$ json <<< '\''"null"'\''
command failed: json <<< '\''"null"'\''
$ json <<< '\''"boolean"'\''
command failed: json <<< '\''"boolean"'\''
$ json <<< '\''"number"'\''
command failed: json <<< '\''"number"'\''
$ json <<< '\''"string"'\''
command failed: json <<< '\''"string"'\''
$ json <<< '\''"object"'\''
command failed: json <<< '\''"object"'\''
$ json <<< '\''"array"'\''
command failed: json <<< '\''"array"'\''
$ json <<< '\''"list"'\''
json: error: <stdin>:1:1: meta error: invalid top value: it must be a type or an array of "name" objects
json: error: <stdin>:1:1: "list"
json: error: <stdin>:1:1: ^
command failed: json <<< '\''"list"'\'''
) -L literal-value.new <(
echo '$ json() { set -o pipefail && LD_LIBRARY_PATH=../lib ../src/json --literal-value -V -TA "$@"|LD_LIBRARY_PATH=../lib ../src/json --from-ast-print --verbose --no-error; }'
json() { set -o pipefail && LD_LIBRARY_PATH=../lib ../src/json --literal-value -V -TA "$@"|LD_LIBRARY_PATH=../lib ../src/json --from-ast-print --verbose --no-error; } 2>&1 ||
echo 'command failed: json() { set -o pipefail && LD_LIBRARY_PATH=../lib ../src/json --literal-value -V -TA "$@"|LD_LIBRARY_PATH=../lib ../src/json --from-ast-print --verbose --no-error; }'

echo '$ json <<< '\''null'\'''
json <<< 'null' 2>&1 ||
echo 'command failed: json <<< '\''null'\'''

echo '$ json <<< '\''false'\'''
json <<< 'false' 2>&1 ||
echo 'command failed: json <<< '\''false'\'''

echo '$ json <<< '\''true'\'''
json <<< 'true' 2>&1 ||
echo 'command failed: json <<< '\''true'\'''

echo '$ json <<< '\''123'\'''
json <<< '123' 2>&1 ||
echo 'command failed: json <<< '\''123'\'''

echo '$ json <<< '\''"foo"'\'''
json <<< '"foo"' 2>&1 ||
echo 'command failed: json <<< '\''"foo"'\'''

echo '$ json <<< '\''"type"'\'''
json <<< '"type"' 2>&1 ||
echo 'command failed: json <<< '\''"type"'\'''

echo '$ json <<< '\''"null"'\'''
json <<< '"null"' 2>&1 ||
echo 'command failed: json <<< '\''"null"'\'''

echo '$ json <<< '\''"boolean"'\'''
json <<< '"boolean"' 2>&1 ||
echo 'command failed: json <<< '\''"boolean"'\'''

echo '$ json <<< '\''"number"'\'''
json <<< '"number"' 2>&1 ||
echo 'command failed: json <<< '\''"number"'\'''

echo '$ json <<< '\''"string"'\'''
json <<< '"string"' 2>&1 ||
echo 'command failed: json <<< '\''"string"'\'''

echo '$ json <<< '\''"object"'\'''
json <<< '"object"' 2>&1 ||
echo 'command failed: json <<< '\''"object"'\'''

echo '$ json <<< '\''"array"'\'''
json <<< '"array"' 2>&1 ||
echo 'command failed: json <<< '\''"array"'\'''

echo '$ json <<< '\''"list"'\'''
json <<< '"list"' 2>&1 ||
echo 'command failed: json <<< '\''"list"'\'''
)

