# file      : tests/value/reverse.testscript
# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
# license   : MIT; see accompanying LICENSE file

# Test reversal to canonical/original representation.
#

.include ../common.testscript

: name
:
{
  : dir
  :
  $* <<EOI >>EOO
  x = s/foo/bar/
  print ([string] $x)
  print "$x"
  print -e=$x
  EOI
  s/foo/bar/
  s/foo/bar/
  -e=s/foo/bar/
  EOO

  : proj
  :
  $* <<EOI >>EOO
  print ([strings] foo%bar foo% %bar)
  EOI
  foo%bar foo% %bar
  EOO

  : pair
  :
  $* <<EOI >>EOO
  print ([strings] foo@bar foo/@bar/ foo@ @bar @ "@@")
  EOI
  foo@bar foo/@bar/ foo@ @bar @ @@
  EOO

  : proj-pair
  :
  $* <<EOI >>EOO
  print ([strings] xx%foo@yy%bar xx%foo/@yy%bar/)
  EOI
  xx%foo@yy%bar xx%foo/@yy%bar/
  EOO

  : invalid
  :
  : We should be able to represent an invalid name provided it is quoted.
  :
  $* <<EOI >>EOO
  print ([strings] "pkcs11:object=SIGN%20key")
  EOI
  pkcs11:object=SIGN%20key
  EOO
}

: dir-path
:
{
  : rel
  :
  $* <<EOI >>"EOO"
  x = [dir_path] foo/bar/
  print ([string] $x)
  print "$x"
  print "-I$x"
  EOI
  foo/bar/
  foo/bar
  -Ifoo/bar
  EOO

  : root
  :
  if ($cxx.target.class != 'windows')
  {
    $* <<EOI >>EOO
    x = [dir_path] /
    print ([string] $x)
    print "$x"
    print "-I$x"
    EOI
    /
    /
    -I/
    EOO
  }
}