# file      : file/testscript
# license   : MIT; see accompanying LICENSE file

# End-of-line marker. Place its expansion in here-documents after the trailing
# spaces to prevent them from being stripped by editors and to improve
# readability.
#
eol = ""

+cat <<EOI >=empty.ops
# Empty options file.
#

EOI
+cat <<EOI >=base.ops
-a 21
-b 21
EOI

: with-spaces
:
cat <<EOI >=test.ops;
-a 	11
-b  11
  -a 12

	-b 12
a
EOI
$* -a 1 --file ../empty.ops -b 1 --file ../base.ops --file test.ops b >>EOO
-a
1
-b
1
-a
21
-b
21
-a
11
-b
11
-a
12
-b
12
a
b
EOO

: empty
:
cat <<EOI >=test.ops;
# Empty options file.
#

EOI
$* -a 1 -- --file test.ops b >>EOO
-a
1
--
--file
test.ops
b
EOO

: non-empty-empty
:
cat <<EOI >=test.ops;
-a 11
-b 11
--
--file ../base.ops
-a 12
-b 12
a
EOI
$* -a 1 --file test.ops --file ../empty.ops b >>EOO
-a
1
-a
11
-b
11
--
--file
../base.ops
-a
12
-b
12
a
--file
../empty.ops
b
EOO

: non-existent
:
$* -a 1 --file ../base.ops --file test.ops b >>EOO 2>>EOE
-a
1
-a
21
-b
21
EOO
unable to open file 'test.ops' or read failure
EOE

: quoted
:
cat <<EOI >=test.ops;
-a a"b"c
-a "abc"
-a "a"b"
-a ""
-a " abc "
-a " "
-a """
-a "'"

-a a'b'c
-a 'abc'
-a 'a'b'
-a ''
-a ' abc '
-a ' '
-a '''
-a '"'
EOI
$* --file test.ops >>"EOO"
-a
a"b"c
-a
abc
-a
a"b
-a

-a
 abc $eol
-a
 $eol
-a
"
-a
'
-a
a'b'c
-a
abc
-a
a'b
-a

-a
 abc $eol
-a
 $eol
-a
'
-a
"
EOO

: unmatched-double-quote1
:
cat <<EOI >=test.ops;
-a "
EOI
$* --file test.ops 2>>EOE
unmatched quote in argument '"'
EOE

: unmatched-double-quote2
:
cat <<EOI >=test.ops;
-a "abc
EOI
$* --file test.ops 2>>EOE
unmatched quote in argument '"abc'
EOE

: unmatched-double-quote3
:
cat <<EOI >=test.ops;
-a abc"
EOI
$* --file test.ops 2>>EOE
unmatched quote in argument 'abc"'
EOE

: unmatched-quote1
:
cat <<EOI >=test.ops;
-a '
EOI
$* --file test.ops 2>>EOE
unmatched quote in argument '''
EOE

: unmatched-quote2
:
cat <<EOI >=test.ops;
-a 'abc
EOI
$* --file test.ops 2>>EOE
unmatched quote in argument ''abc'
EOE

: unmatched-quote3
:
cat <<EOI >=test.ops;
-a abc'
EOI
$* --file test.ops 2>>EOE
unmatched quote in argument 'abc''
EOE

: unmatched-quote4
:
cat <<EOI >=test.ops;
-a "abc'
EOI
$* --file test.ops 2>>EOE
unmatched quote in argument '"abc''
EOE

: unmatched-quote5
:
cat <<EOI >=test.ops;
-a 'abc"
EOI
$* --file test.ops 2>>EOE
unmatched quote in argument ''abc"'
EOE

: quoted-argument
:
cat <<EOI >=test.ops;
"'foo  bar'"
'"foo  bar"'
EOI
$* --file test.ops >>EOO
'foo  bar'
"foo  bar"
EOO

: direct-file-load
:
cat <<EOI >=test.ops;
-f
-a 123
EOI
$* --- test.ops >>EOO
-f
-a
123
EOO

: direct-file-empty
:
cat <<EOI >=test.ops;
EOI
$* --- test.ops

: direct-file-load-nested
:
cat <<EOI >=test.ops;
-f
--file ../base.ops
-a 123
EOI
$* ---- test.ops >>EOO
-f
-a
21
-b
21
-a
123
EOO

: relativeness
:
{{
  +cat <<EOI >=test1.ops
    -a 11
    --file test/test.ops
    EOI

  +cat <<"EOI" >=test2.ops
    -a 11
    --file $~/test/test.ops
    EOI

  +mkdir test
  +cat <<EOI >=test/test.ops
    -b 22
    EOI

  : relative
  :
  $* --file ../test1.ops >>EOO
    -a
    11
    -b
    22
    EOO

  : absolute
  :
  $* --file ../test2.ops >>EOO
    -a
    11
    -b
    22
    EOO

  : relative-against-absolute
  :
  $* --file $~/../test1.ops >>EOO
    -a
    11
    -b
    22
    EOO

  : relative-against-normalized
  :
  $* --file $path.normalize($~/../test1).ops >>EOO
    -a
    11
    -b
    22
    EOO
}}
