# CHECK: -- Testing:{{.*}}
# CHECK-NEXT: PASS: shtest-if-else :: test.txt (1 of 1)
# CHECK-NEXT: Script:
# CHECK-NEXT: --

# RUN: %if feature %{ echo "feature" %} %else %{ echo "missing feature" %}
# CHECK-NEXT: echo "feature"

#
# RUN: %if nofeature %{ echo "found unicorn" %} %else %{ echo "nofeature" %}
# CHECK-NEXT: "nofeature"
# CHECK-NOT: found unicorn

# Spaces inside curly braces are not ignored
#
# RUN: echo test-%if feature %{ 3 %} %else %{ echo "fail" %}-test
# RUN: echo test-%if feature %{ 4 4 %} %else %{ echo "fail" %}-test
# RUN: echo test-%if nofeature %{ echo "fail" %} %else %{ 5 5 %}-test
# CHECK-NEXT: echo test- 3 -test
# CHECK-NOT: echo "fail"
# CHECK-NEXT: echo test- 4 4 -test
# CHECK-NOT: echo "fail"
# CHECK-NEXT: echo test- 5 5 -test
# CHECK-NOT: echo "fail"

# Escape line breaks for multi-line expressions
#
# RUN: %if feature  \
# RUN:   %{ echo     \
# RUN:     "test-5" \
# RUN:   %} %else %{ echo "fail" %}
# CHECK-NEXT: echo "test-5"

# RUN: %if nofeature       \
# RUN:   %{ echo "fail" %}   \
# RUN: %else               \
# RUN:   %{ echo "test-6" %}
# CHECK-NEXT: echo "test-6"

# RUN: echo "test%if feature %{%} %else %{%}-7"
# CHECK-NEXT: echo "test-7"


# Nested expressions are supported:
#
# RUN: echo %if feature %{ %if feature %{ %if nofeature %{"fail"%} %else %{"test-9"%} %} %}
# CHECK-NEXT: echo "test-9"

# Spaces between %if and %else are ignored. If there is no %else -
# space after %if %{...%} is not ignored.
#
# RUN: echo XX %if feature %{YY%} ZZ
# RUN: echo AA %if feature %{BB%} %else %{CC%} DD
# RUN: echo AA %if nofeature %{BB%} %else %{CC%} DD
# CHECK-NEXT: echo XX YY ZZ
# CHECK-NEXT: echo AA BB DD
# CHECK-NEXT: echo AA CC DD

# '{' and '}' can be used without escaping
#
# RUN: %if feature %{echo {}%}
# CHECK-NEXT: echo {}

# Spaces are not required
#
# RUN: echo %if feature%{"ok"%}%else%{"fail"%}
# CHECK-NEXT: echo "ok"

# Substitutions with braces are handled correctly
#
# RUN: echo %{sub} %if feature%{test-%{sub}%}%else%{"fail"%}
# CHECK-NEXT: echo ok test-ok

# CHECK-NEXT: --
# CHECK-NEXT: Exit Code: 0
