# file      : tests/variable/override/testscript
# license   : MIT; see accompanying LICENSE file

.include ../../common.testscript

: cache-invalidation
:
{{
  : value-version
  :
  $* p.x+=01 p.y+=01 <<EOI >>EOO
  p.x = [string] 0
  print $p.x

  p.x = [uint64] 1
  print $p.x

  p.y = 0
  print $p.y

  [uint64] p.y = [null]
  print $p.y
  EOI
  001
  2
  0 01
  1
  EOO

  : value-position
  :
  $* p.x+=01 <<EOI >>EOO
  p.x = [string] 0

  print $p.x
  dir/
  {
    print $p.x
  }

  dir/ p.x = [uint64] 1

  print $p.x
  dir/
  {
    print $p.x
  }

  EOI
  001
  001
  001
  2
  EOO
}}

: override-cached
:
: Test overriding cached target type/pattern-specific prepend/append
:
{{
  $* p.x+=X <<EOI >>EOO
  p.x = 0
  file{*}: p.x += a

  file{foo}:

  print $(file{foo}:p.x)

  p.x = 1                 # Should invalidate both caches.
  print $(file{foo}:p.x)

  file{*}: p.x += b       # Should invalidate both caches.
  print $(file{foo}:p.x)
  EOI
  0 a X
  1 a X
  1 a b X
  EOO
}}

: order
:
{{
  : after
  :
  $* p.x=1 p.x+=2 p.x=+0 <<EOI >>EOO
  print $p.x
  EOI
  0 1 2
  EOO

  : before
  :
  $* p.x+=2 p.x=+0 p.x=1 <<EOI >>EOO
  print $p.x
  EOI
  1
  EOO

  : both
  :
  $* p.x=+0 p.x=1 p.x+=2 <<EOI >>EOO
  print $p.x
  EOI
  1 2
  EOO
}}

: multiple
:
{{
  : assign
  :
  $* p.x=0 !p.y=0 p.x=1 !p.y=1 <<EOI >>EOO
  print $p.x
  print $p.y
  EOI
  1
  1
  EOO

  : append
  :
  $* p.x=0 p.x+=1 p.x+=2 <<EOI >>EOO
  print $p.x
  EOI
  0 1 2
  EOO

  : prepend
  :
  $* p.x=2 p.x=+1 p.x=+0 <<EOI >>EOO
  print $p.x
  EOI
  0 1 2
  EOO
}}
