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

plan 19;

my $haystack = "Currently the dynamic username coloring can choose colors that are very close to the background (light yellow on white, for instance). In addition, extremely dark or light colors are hard to distinguish from each other, as they effectively desaturate towards black or white respectively. (Desaturated colors with similar lightness are hard to distinguish in general, but I mention the light and dark cases because it's not always obvious that they are de facto desaturated.)";

is highlighter($haystack, "dark", "<em>", "</em>",
  :type<words>, :summary-if-larger-than(80)),
  '... extremely <em>dark</em> or light colo...the light and <em>dark</em> cases because...',
  'did "dark" get highlighted as a word';

is highlighter($haystack, "DARK", "<em>", "</em>",
  :type<words>, :ignorecase, :summary-if-larger-than(80)),
  '... extremely <em>dark</em> or light colo...the light and <em>dark</em> cases because...',
  'did "DARK" get highlighted as a word case-insensitively';

is highlighter($haystack, "ar", "<em>", "</em>",
  :type<words>, :summary-if-larger-than(80)),
  'Currently the dynamic username coloring can choose colors that are very close...',
  'did "ar" NOT get highlighted as a word';

is highlighter($haystack, "dar", "<em>", "</em>",
  :type<contains>, :summary-if-larger-than(80)),
  '... extremely <em>dar</em>k or light col...the light and <em>dar</em>k cases becaus...',
  'did "dar" get highlighted as a string';

is highlighter($haystack, "DAR", "<em>", "</em>", 
  :type<contains>, :ignorecase, :summary-if-larger-than(80)),
  '... extremely <em>dar</em>k or light col...the light and <em>dar</em>k cases becaus...',
  'did "DAR" get highlighted as a string case-insensitively';

is highlighter($haystack, "zz", "<em>", "</em>",
  :type<words>, :summary-if-larger-than(80)),
  'Currently the dynamic username coloring can choose colors that are very close...',
  'did "zz" NOT get highlighted as a string';

is highlighter($haystack, "Currently", "<em>", "</em>",
  :type<starts-with>, :summary-if-larger-than(80)),
  '<em>Currently</em> the dynamic username coloring can choose colors that are very close...',
  'did "Currently" get highlighted at beginning';

is highlighter($haystack, "CURRENTLY", "<em>","</em>",
  :type<starts-with>, :ignorecase, :summary-if-larger-than(80)),
  '<em>Currently</em> the dynamic username coloring can choose colors that are very close...',
  'did "CURRENTLY" get highlighted at beginning case-insensitively';

is highlighter($haystack, "zz", "<em>", "</em>",
  :type<starts-with>, :summary-if-larger-than(80)),
  'Currently the dynamic username coloring can choose colors that are very close...',
  'did "zz" NOT get highlighted at beginning';

is highlighter($haystack, "desaturated.)", "<em>", "</em>",
  :type<ends-with>, :summary-if-larger-than(80)),
  "...on the light and dark cases because it's not always obvious that they are de <em>desaturated.)</em>",
  'did "desaturated.)" get highlighted at end';

is highlighter($haystack, "DESATURATED.)", "<em>","</em>",
  :type<ends-with>, :ignorecase, :summary-if-larger-than(80)),
  "...on the light and dark cases because it's not always obvious that they are de <em>desaturated.)</em>",
  'did "DESATURATED.)" get highlighted at end case-insensitively';

is highlighter($haystack, "zz", "<em>", "</em>",
  :type<ends-with>, :summary-if-larger-than(80)),
  'Currently the dynamic username coloring can choose colors that are very close...',
  'did "zz" NOT get highlighted at end';

is highlighter($haystack, / << d.rk >> /, "<em>", "</em>",
  :summary-if-larger-than(80)),
  '... extremely <em>dark</em> or light colo...the light and <em>dark</em> cases because...',
  'did "d.rk" get highlighted as a match';

is highlighter($haystack, rx:i/ D.RK /, "<em>", "</em>",
  :summary-if-larger-than(80)),
  '... extremely <em>dark</em> or light colo...the light and <em>dark</em> cases because...',
  'did "D.RK" get highlighted as a match case-insensitively';

is highlighter($haystack, / zz /, "<em>", "</em>",
  :summary-if-larger-than(80)),
  'Currently the dynamic username coloring can choose colors that are very close...',
  'did "zz" NOT get highlighted as a match';

is highlighter($haystack, 'dar', "<em>", "</em>",
  :summary-if-larger-than(80)),
  '... extremely <em>dar</em>k or light col...the light and <em>dar</em>k cases becaus...',
  'did "dar" get highlighted';

is highlighter($haystack, *.contains("foo"),
  :summary-if-larger-than(80)),
  'Currently the dynamic username coloring can choose colors that are very close...',
  'did we get no highlighting at all';

is highlighter($haystack, / <( dar \w )> /, "<em>", "</em>",
  :summary-if-larger-than(80)),
  '... extremely <em>dark</em> or light colo...the light and <em>dark</em> cases because...',
  'did we get correct highlighting with capture markers';

is highlighter($haystack, / <( dar \w )> /, "", "\n",
  :only, :summary-if-larger-than(80)),
  "dark\ndark\n",
  'did we get correct highlighting with :only';

# vim: expandtab shiftwidth=4


