#!/bin/sh
# Test __GLOSSARY__ and __GLOSSARY_GNU__

# Copyright (C) 2007 Michael Geng <linux@MichaelGeng.de>

# This program 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 2 of the License, or
# (at your option) any later version.

# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.

if test "$VERBOSE" = yes; then
  set -x
fi

. test-lib.sh

echo "a / aparam string
b string
NONE / cparam string
#usage_begin
__GLOSSARY__
#usage_end" > x.gp

echo "   [ -a ] [ --aparam ] (type=STRING)
   [ -b ] (type=STRING)
   [ --cparam ] (type=STRING)
   [ -h ] [ --help ] (type=FLAG)
          Display this help and exit.
   [ -v ] [ --version ] (type=FLAG)
          Output version information and exit." > exp

for language in $all_languages
do
  gen_code x.gp $language
  parse_cl --help > out || fail=1
  cmp out exp || fail=1
done

# -------------------------------------------------------

echo "a / aparam string
b string
NONE / cparam string
#usage_begin
__GLOSSARY_GNU__
#usage_end" > x.gp

echo "  -a, --aparam
  -b
      --cparam
  -h, --help            Display this help and exit.
  -v, --version         Output version information and exit." > exp

for language in $all_languages
do
  gen_code x.gp $language
  parse_cl --help > out || fail=1
  cmp out exp || fail=1
done

# -------------------------------------------------------

echo "a / aparam string
b string
NONE / cparam string
#usage_begin
__GLOSSARY_GNU__(16)
#usage_end" > x.gp

echo "  -a, --aparam
  -b
      --cparam
  -h, --help    Display this help and exit.
  -v, --version Output version information and exit." > exp

for language in $all_languages
do
  gen_code x.gp $language
  parse_cl --help > out || fail=1
  cmp out exp || fail=1
done

# -------------------------------------------------------

echo "a / aparam*[=ax] string
NONE / bparam=bx string \"bx is the default for bparam\"
NONE / cparam=cxxxxxxxxxxxxxxxxxxxxx string \"cxxxxxxxxxxxxxxxxxxxxx is the default for cparam\"
#usage_begin
__GLOSSARY__
#usage_end" > x.gp

echo "   [ -a ] [ --aparam[=ax] ] (type=STRING)
   [ --bparam=bx ] (type=STRING)
          bx is the default for bparam
   [ --cparam=cxxxxxxxxxxxxxxxxxxxxx ] (type=STRING)
          cxxxxxxxxxxxxxxxxxxxxx is the default for cparam
   [ -h ] [ --help ] (type=FLAG)
          Display this help and exit.
   [ -v ] [ --version ] (type=FLAG)
          Output version information and exit." > exp

for language in $all_languages
do
  gen_code x.gp $language
  parse_cl --help > out || fail=1
  cmp out exp || fail=1
done

# -------------------------------------------------------

echo "a / aparam*[=ax] string
NONE / bparam=bx string \"bx is the default for bparam\"
NONE / cparam=cxxxxxxxxxxxxxxxxxxxxx string \"cxxxxxxxxxxxxxxxxxxxxx is the default for cparam\"
#usage_begin
__GLOSSARY_GNU__
#usage_end" > x.gp

echo "  -a, --aparam[=ax]
      --bparam=bx       bx is the default for bparam
      --cparam=cxxxxxxxxxxxxxxxxxxxxxcxxxxxxxxxxxxxxxxxxxxx is the default for cparam
  -h, --help            Display this help and exit.
  -v, --version         Output version information and exit." > exp

for language in $all_languages
do
  gen_code x.gp $language
  parse_cl --help > out || fail=1
  cmp out exp || fail=1
done

# -------------------------------------------------------

echo "a int 12 [2..20]
b float 1.2 [1.0..2]
c char 'b'
d string {\"abc\"}
e flag
#usage_begin
__GLOSSARY__
#usage_end" > x.gp

echo "   [ -a ] (type=INTEGER, range=2...20, default=12)
   [ -b ] (type=REAL, range=1.0...2, default=1.2)
   [ -c ] (type=CHARACTER, default='b')
   [ -d ] (type=STRING, default=abc)
   [ -e ] (type=FLAG)
   [ -h ] [ --help ] (type=FLAG)
          Display this help and exit.
   [ -v ] [ --version ] (type=FLAG)
          Output version information and exit." > exp

for language in $all_languages
do
  gen_code x.gp $language
  parse_cl --help > out || fail=1
  cmp out exp || fail=1
done

# -------------------------------------------------------

echo "a long 12 [2..20]
b ulong 34 [20..50]
c intmax 56 [50..60]
d uintmax 78 [70..80]
e double 1.2 [1..2.0]
#usage_begin
__GLOSSARY__
#usage_end" > x.gp

echo "   [ -a ] (type=LONG, range=2...20, default=12)
   [ -b ] (type=UNSIGNED LONG, range=20...50, default=34)
   [ -c ] (type=INTMAX, range=50...60, default=56)
   [ -d ] (type=UINTMAX, range=70...80, default=78)
   [ -e ] (type=DOUBLE, range=1...2.0, default=1.2)
   [ -h ] [ --help ] (type=FLAG)
          Display this help and exit.
   [ -v ] [ --version ] (type=FLAG)
          Output version information and exit." > exp

genparse --gnulib x.gp >/dev/null || fail=1
$CC $CPPFLAGS -o parse_cl $GNULIB_CPPFLAGS parse_cl.c $GNULIB_LDFLAGS $srcdir/simple.c || fail=1
parse_cl --help > out || fail=1
cmp out exp || fail=1

# -------------------------------------------------------

echo "a int \"comment for a\"
\"left aligned comment for a\"
            \"not left aligned comment for a\"
\"another left aligned comment for a\"
b string 
\"left aligned comment for b\"
            \"not left aligned comment for b\"
#usage_begin
__GLOSSARY__

__GLOSSARY_GNU__
#usage_end" > x.gp

echo "   [ -a ] (type=INTEGER)
          comment for a
left aligned comment for a
          not left aligned comment for a
another left aligned comment for a
   [ -b ] (type=STRING)
left aligned comment for b
          not left aligned comment for b
   [ -h ] [ --help ] (type=FLAG)
          Display this help and exit.
   [ -v ] [ --version ] (type=FLAG)
          Output version information and exit.

  -a                    comment for a
left aligned comment for a
                        not left aligned comment for a
another left aligned comment for a
  -b                    left aligned comment for b
                        not left aligned comment for b
  -h, --help            Display this help and exit.
  -v, --version         Output version information and exit." > exp

for language in $all_languages
do
  gen_code x.gp $language
  parse_cl --help > out || fail=1
  cmp out exp || fail=1
done

exit $fail
