# file      : tests/test/script/runner/if.testscript
# license   : MIT; see accompanying LICENSE file

.include ../common.testscript

: if-branch
:
$c <<EOI && $b >'if'
{
  if cat <'foo' >'foo'
    echo 'if' >|
  else
    echo 'else' >|
}
EOI

: else-branch
:
$c <<EOI && $b >'else'
{
  if cat <'foo' >'bar'
    echo 'if' >|
  else
    echo 'else' >|
}
EOI

: ifn-branch
:
$c <<EOI && $b >'if'
{
  ifn $foo
    echo 'if' >|
  else
    echo 'else' >|
}
EOI

: ifnn-branch
:
$c <<EOI && $b >'if'
{
  foo =
  ifn! $foo
    echo 'if' >|
  else
    echo 'else' >|
}
EOI

: ife-branch
:
$c <<EOI && $b >'if'
{
  foo =
  ife $foo
    echo 'if' >|
  else
    echo 'else' >|
}
EOI

: ifen-branch
:
$c <<EOI && $b >'if'
{
  foo = 'abc'
  ife! $foo
    echo 'if' >|
  else
    echo 'else' >|
}
EOI

: ifen-group
:
$c <<EOI && $b >'a.txt'
+touch a.txt
fs = $path_search('*.txt', $~)
ife! $fs
{{
  echo $fs >|
}}
else
{{
  echo 'no files' >|
}}
EOI

: ifen-test
:
$c <<EOI && $b >'a.txt'
+touch a.txt
fs = $path_search('*.txt', $~)
ife! $fs
  echo $fs >|
else
  echo 'no files' >|
EOI

: syntax-1
:
{{
  b = [cmdline] $regex.apply($b, '(.+testscript.syntax).+', "\1 = 1'")

  : if-branch
  :
  $c <<EOI && $b >'if'
  if cat <'foo' >'foo'
    echo 'if' >|
  else
    echo 'else' >|
  end
  EOI

  : else-branch
  :
  $c <<EOI && $b >'else'
  if cat <'foo' >'bar'
    echo 'if' >|
  else
    echo 'else' >|
  end
  EOI
}}
