#!/bin/bash

# Copyright (C) 2016, 2017, 2018, 2019  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-gen-def:node-dict-closed-array-empty
#

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

diff -u$u -L node-dict-closed-array-empty.old <(echo \
'$ set -o pipefail
$ json() { LD_LIBRARY_PATH=../lib ../src/json -Td "$@"|sed -r '\''s/^#/\\#/;/^\s*\/\//d;/^\s*$/d'\''; }
$ json <<< '\''{"type":"dict","args":[{"name":"foo","type":{"type":"array","args":[]}}]}'\''
\#define EQ  cell.eq
\#define VAL cell.val
static const struct json_type_node_t* __0[] = {
    NULL
};
static const struct json_type_node_t __1 = {
    .type = json_type_array_node_type,
    .node.array = {
        .type = json_type_closed_array_node_type,
        .val.closed = {
            .args = __0,
            .size = 0
        }
    }
};
static const struct json_type_dict_trie_node_t __2 = {
    .sym = '\''\0'\'',
    .VAL = 0
};
static const struct json_type_dict_trie_node_t __3 = {
    .sym = '\''o'\'',
    .EQ = &__2
};
static const struct json_type_dict_trie_node_t __4 = {
    .sym = '\''o'\'',
    .EQ = &__3
};
static const struct json_type_dict_trie_node_t __5 = {
    .sym = '\''f'\'',
    .EQ = &__4
};
static const struct json_type_dict_trie_t __6 = {
    .root = &__5
};
static const struct json_type_dict_attr_t __7 = {
    .args = &__6
};
static const struct json_type_dict_node_arg_t __8[] = {
    {
        .name = (const uchar_t*) "foo",
        .type = &__1
    }
};
static const struct json_type_node_t __9 = {
    .type = json_type_dict_node_type,
    .attr.dict = &__7,
    .node.dict = {
        .args = __8,
        .size = 1
    }
};
static const struct json_type_def_t MODULE_TYPE_DEF = {
    .type = json_type_def_node_type,
    .val.node = &__9
};
$ json <<< '\''{"type":"dict","args":[{"name":"foo","type":{"type":"array","args":[{"type":"array","args":[]}]}}]}'\''
\#define EQ  cell.eq
\#define VAL cell.val
static const struct json_type_node_t* __0[] = {
    NULL
};
static const struct json_type_node_t __1 = {
    .type = json_type_array_node_type,
    .node.array = {
        .type = json_type_closed_array_node_type,
        .val.closed = {
            .args = __0,
            .size = 0
        }
    }
};
static const struct json_type_node_t* __2[] = {
    &__1,
    NULL
};
static const struct json_type_node_t __3 = {
    .type = json_type_array_node_type,
    .node.array = {
        .type = json_type_closed_array_node_type,
        .val.closed = {
            .args = __2,
            .size = 1
        }
    }
};
static const struct json_type_dict_trie_node_t __4 = {
    .sym = '\''\0'\'',
    .VAL = 0
};
static const struct json_type_dict_trie_node_t __5 = {
    .sym = '\''o'\'',
    .EQ = &__4
};
static const struct json_type_dict_trie_node_t __6 = {
    .sym = '\''o'\'',
    .EQ = &__5
};
static const struct json_type_dict_trie_node_t __7 = {
    .sym = '\''f'\'',
    .EQ = &__6
};
static const struct json_type_dict_trie_t __8 = {
    .root = &__7
};
static const struct json_type_dict_attr_t __9 = {
    .args = &__8
};
static const struct json_type_dict_node_arg_t __10[] = {
    {
        .name = (const uchar_t*) "foo",
        .type = &__3
    }
};
static const struct json_type_node_t __11 = {
    .type = json_type_dict_node_type,
    .attr.dict = &__9,
    .node.dict = {
        .args = __10,
        .size = 1
    }
};
static const struct json_type_def_t MODULE_TYPE_DEF = {
    .type = json_type_def_node_type,
    .val.node = &__11
};
$ json <<< '\''{"type":"dict","args":[{"name":"foo","type":{"type":"array","args":[{"type":"array","args":[{"type":"array","args":[]}]}]}}]}'\''
\#define EQ  cell.eq
\#define VAL cell.val
static const struct json_type_node_t* __0[] = {
    NULL
};
static const struct json_type_node_t __1 = {
    .type = json_type_array_node_type,
    .node.array = {
        .type = json_type_closed_array_node_type,
        .val.closed = {
            .args = __0,
            .size = 0
        }
    }
};
static const struct json_type_node_t* __2[] = {
    &__1,
    NULL
};
static const struct json_type_node_t __3 = {
    .type = json_type_array_node_type,
    .node.array = {
        .type = json_type_closed_array_node_type,
        .val.closed = {
            .args = __2,
            .size = 1
        }
    }
};
static const struct json_type_node_t* __4[] = {
    &__3,
    NULL
};
static const struct json_type_node_t __5 = {
    .type = json_type_array_node_type,
    .node.array = {
        .type = json_type_closed_array_node_type,
        .val.closed = {
            .args = __4,
            .size = 1
        }
    }
};
static const struct json_type_dict_trie_node_t __6 = {
    .sym = '\''\0'\'',
    .VAL = 0
};
static const struct json_type_dict_trie_node_t __7 = {
    .sym = '\''o'\'',
    .EQ = &__6
};
static const struct json_type_dict_trie_node_t __8 = {
    .sym = '\''o'\'',
    .EQ = &__7
};
static const struct json_type_dict_trie_node_t __9 = {
    .sym = '\''f'\'',
    .EQ = &__8
};
static const struct json_type_dict_trie_t __10 = {
    .root = &__9
};
static const struct json_type_dict_attr_t __11 = {
    .args = &__10
};
static const struct json_type_dict_node_arg_t __12[] = {
    {
        .name = (const uchar_t*) "foo",
        .type = &__5
    }
};
static const struct json_type_node_t __13 = {
    .type = json_type_dict_node_type,
    .attr.dict = &__11,
    .node.dict = {
        .args = __12,
        .size = 1
    }
};
static const struct json_type_def_t MODULE_TYPE_DEF = {
    .type = json_type_def_node_type,
    .val.node = &__13
};'
) -L node-dict-closed-array-empty.new <(
echo '$ set -o pipefail'
set -o pipefail 2>&1 ||
echo 'command failed: set -o pipefail'

echo '$ json() { LD_LIBRARY_PATH=../lib ../src/json -Td "$@"|sed -r '\''s/^#/\\#/;/^\s*\/\//d;/^\s*$/d'\''; }'
json() { LD_LIBRARY_PATH=../lib ../src/json -Td "$@"|sed -r 's/^#/\\#/;/^\s*\/\//d;/^\s*$/d'; } 2>&1 ||
echo 'command failed: json() { LD_LIBRARY_PATH=../lib ../src/json -Td "$@"|sed -r '\''s/^#/\\#/;/^\s*\/\//d;/^\s*$/d'\''; }'

echo '$ json <<< '\''{"type":"dict","args":[{"name":"foo","type":{"type":"array","args":[]}}]}'\'''
json <<< '{"type":"dict","args":[{"name":"foo","type":{"type":"array","args":[]}}]}' 2>&1 ||
echo 'command failed: json <<< '\''{"type":"dict","args":[{"name":"foo","type":{"type":"array","args":[]}}]}'\'''

echo '$ json <<< '\''{"type":"dict","args":[{"name":"foo","type":{"type":"array","args":[{"type":"array","args":[]}]}}]}'\'''
json <<< '{"type":"dict","args":[{"name":"foo","type":{"type":"array","args":[{"type":"array","args":[]}]}}]}' 2>&1 ||
echo 'command failed: json <<< '\''{"type":"dict","args":[{"name":"foo","type":{"type":"array","args":[{"type":"array","args":[]}]}}]}'\'''

echo '$ json <<< '\''{"type":"dict","args":[{"name":"foo","type":{"type":"array","args":[{"type":"array","args":[{"type":"array","args":[]}]}]}}]}'\'''
json <<< '{"type":"dict","args":[{"name":"foo","type":{"type":"array","args":[{"type":"array","args":[{"type":"array","args":[]}]}]}}]}' 2>&1 ||
echo 'command failed: json <<< '\''{"type":"dict","args":[{"name":"foo","type":{"type":"array","args":[{"type":"array","args":[{"type":"array","args":[]}]}]}}]}'\'''
)

