# file      : tests/function/name/testscript
# license   : MIT; see accompanying LICENSE file

.include ../../common.testscript

: is_a
:
{{
  $* <'print $is_a(file{foo},    path_target)' >'true'  : basics-true
  $* <'print $is_a(alias{foo},   path_target)' >'false' : basics-false
  $* <'print $is_a(file{foo}@./, path_target)' >'true'  : out
  $* <<EOI                                     >'true'  : derived
  define txt: file
  print $is_a(txt{foo}, path_target)
  EOI
}}

: filter
:
{{
  $* <<EOI >'file{foo}@./ txt{baz}' : basics
  define txt: file
  print $filter(file{foo}@./ alias{bar} dir{./} txt{baz}, file)
  EOI

  $* <<EOI >'file{foo}@./ txt{baz}' : basics-out
  define txt: file
  print $filter_out(file{foo}@./ alias{bar} dir{./} txt{baz}, alias)
  EOI

  $* <<EOI >'file{foo}@./ dir{./} txt{baz}' : multiple
  define txt: file
  print $filter(file{foo}@./ alias{bar} dir{./} txt{baz}, file dir)
  EOI

  $* <<EOI >'file{foo}@./ alias{bar}' : multiple-out
  define txt: file
  print $filter_out(file{foo}@./ alias{bar} dir{./} txt{baz}, txt dir)
  EOI
}}

: size
:
{{
  $* <'print $size(a b c@./)' >'3'      : basics
  $* <'print $type($size(a))' >'uint64' : type
}}

: sort
:
{{
  $* <'print $sort(d/t{a} t{c b} d/t{a})'        >'t{b} t{c} d/t{a} d/t{a}' : basics
  $* <'print $sort(d/t{a} t{c b} d/t{a}, dedup)' >'t{b} t{c} d/t{a}'        : dedup
}}

: find
:
{{
  $* <'print $find([names] d/t{a} t{a b}, t{a})'   >'true'  : basics-true
  $* <'print $find([names] d/t{a} t{a b}, d/t{b})' >'false' : basics-false
}}

: find_index
:
{{
  $* <'print $find_index([names] d/t{a} t{a b}, t{a})'   >'1' : basics-true
  $* <'print $find_index([names] d/t{a} t{a b}, d/t{b})' >'3' : basics-false
}}

: front
:
{{
  $* <'print $front(a)'    >'a'    : single-entry
  $* <'print $front(a b)'    >'a'  : mult-entries
  $* <'print $front(a@b/)' >'a@b/' : single-pair
}}

: back
:
{{
  $* <'print $back(a)'      >'a'    : single-entry
  $* <'print $back(a b)'    >'b'    : mult-entries
  $* <'print $back(a@b/)'   >'a@b/' : single-pair
  $* <'print $back(a b@c/)' >'b@c/' : pair-last
}}
