### ----------------------------------------------------
### -- highlighter
### -- Licenses: Artistic-2.0
### -- Authors: Elizabeth Mattijsen
### -- File: t/03-columns.rakutest
### ----------------------------------------------------
use Test;
use highlighter;

plan 75;

my $haystack = "foo bar baz bar zop";

my sub test-co($needle, $capture, \result, $description) is test-assertion {
    is-deeply columns($haystack, $needle, |$capture),
      result,
      $description;

    is-deeply columns($haystack, ($needle, "frobnicate"), |$capture),
      result,
      "$description (list first)";

    is-deeply columns($haystack, ("frobnicate", $needle), |$capture),
      result,
      "$description (list last)";
}

test-co "bar", \(:type<words>),
  (5,13),
  'did "bar" produce columns as a word';

test-co "bar" but Type<words>, \(),
  (5,13),
  'did "bar"<words> produce columns as a word';

test-co "BAR", \(:type<words>, :ignorecase),
  (5,13),
  'did "BAR" produce columns as a word case-insensitively';

test-co "ar", \(:type<words>),
  (),
  'did "ar" NOT produce columns as a word';

test-co "ba", \(:type<contains>),
  (5,9,13),
  'did "ba" produce columns as a string';

test-co "BA", \(:type<contains>, :ignorecase),
  (5,9,13),
  'did "BA" produce columns as a string case-insensitively';

test-co "zz", \(:type<words>),
  (),
  'did "zz" NOT produce columns as a string';

for
  \(:type<starts-with>),
  \(:type<starts-with>, :smartcase),
  \(:type<starts-with>, :ignorecase),
  \(:type<starts-with>, :smartmark),
  \(:type<starts-with>, :ignoremark)
-> $capture {
    test-co "foo", $capture,
      (1,),
      "did 'foo' produce columns at beginning $capture.keys()";
}

test-co "FOO", \(:type<starts-with>, :ignorecase),
  (1,),
  'did "FOO" produce columns at beginning case-insensitively';

test-co "zz", \(:type<starts-with>),
  (),
  'did "zz" NOT produce columns at beginning';

test-co "zop", \(:type<ends-with>),
  (17,),
  'did "zop" produce columns at end';

test-co "ZOP", \(:type<ends-with>, :ignorecase),
  (17,),
  'did "ZOP" produce columns at end case-insensitively';

test-co "zz", \(:type<ends-with>),
  (),
  'did "zz" NOT produce columns at end';

test-co / << b.r >> /, \(),
  (5,13),
  'did "b.r" produce columns as a match';

test-co rx:i/ B.R /, \(),
  (5,13),
  'did "B.R" produce columns as a match case-insensitively';

test-co / zz /, \(),
  (),
  'did "zz" NOT produce columns as a match';

test-co 'ar', \(),
  (6,14),
  'did "ar" produce columns';

test-co *.contains("foo"), \(),
  (),
  'did we get no highlighting at all';

test-co / <( ba \w )> /, \(),
  (5,9,13),
  'did we get correct highlighting with capture markers';

test-co $haystack, \(:type<equal>),
  (1,),
  'did haystack produce columns when equal';

test-co $haystack.uc, \(:type<equal>, :ignorecase),
  (1,),
  'did haystack produce columns when equal and ignorecase';

# vim: expandtab shiftwidth=4


