Skip to content

Instantly share code, notes, and snippets.

@samcv

samcv/ri.t Secret

Created August 13, 2018 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samcv/c39b3c916525e390e74c6ad050f887a1 to your computer and use it in GitHub Desktop.
Save samcv/c39b3c916525e390e74c6ad050f887a1 to your computer and use it in GitHub Desktop.
use Test;
sub test-it (:$text, :@chars-to-test, :@graphs, :@cps) {
#my $text = "join+comb";
#my @chars-to-test = ("a", "πŸ‡¦", "πŸ‡§", "πŸ‡¨", "πŸ‡©", "b").join.comb;
#my @graphs = "a", "πŸ‡¦πŸ‡§", "πŸ‡¨πŸ‡©", "b";
#my @cps = (("a",), ("πŸ‡¦", "πŸ‡§"), ("πŸ‡¨","πŸ‡©"), ("b",)).deepmap(*.ord);
is-deeply @chars-to-test, @graphs, "Graphemes compare correct in initial test of $text";
for ^@graphs -> $i {
is-deeply @graphs[$i].ords, @cps[$i], "Codepoints in isolated grapheme $i are correct";
}
for ^@chars-to-test -> $i {
is-deeply @chars-to-test[$i].ords, @cps[$i], "Codepoints in grapheme $i created from $text is correct";
is-deeply @chars-to-test[$i].chars, 1, "Number of graphemes in grapheme $i created from $text is correct";
}
}
test-it(
:text("join+comb"),
:chars-to-test(("a", "πŸ‡¦", "πŸ‡§", "πŸ‡¨", "πŸ‡©", "b").join.comb),
:graphs:("a", "πŸ‡¦πŸ‡§", "πŸ‡¨πŸ‡©", "b"),
:cps((("a",), ("πŸ‡¦", "πŸ‡§"), ("πŸ‡¨","πŸ‡©"), ("b",)).deepmap(*.ord))
);
{
my $text = "join+comb";
my @chars-to-test = ("a", "πŸ‡¦", "πŸ‡§", "πŸ‡¨", "πŸ‡©", "b").join.comb;
my @graphs = "a", "πŸ‡¦πŸ‡§", "πŸ‡¨πŸ‡©", "b";
my @cps = (("a",), ("πŸ‡¦", "πŸ‡§"), ("πŸ‡¨","πŸ‡©"), ("b",)).deepmap(*.ord);
is-deeply @chars-to-test, @graphs, "Graphemes seem correct";
for ^@graphs -> $i {
is-deeply @graphs[$i].ords, @cps[$i], "Codepoints in isolated grapheme $i are correct";
}
for ^@chars-to-test -> $i {
is-deeply @chars-to-test[$i].ords, @cps[$i], "Codepoints in grapheme $i created from $text is correct";
is-deeply @chars-to-test[$i].chars, 1, "Number of graphemes in grapheme $i created from $text is correct";
}
}
{
my Str:D $concat = "πŸ‡¦πŸ‡§" ~ "πŸ‡¨πŸ‡©";
my $text = "concat+comb";
my @chars-to-test = $concat.comb;
my @graphs = "πŸ‡¦πŸ‡§", "πŸ‡¨πŸ‡©";
my @cps = ( ("πŸ‡¦","πŸ‡§"), ("πŸ‡¨", "πŸ‡©") ).deepmap(*.ord);
is-deeply $concat.chars, 2, "Correct number of chars from concat of two Regional Indicators";
for ^@graphs -> $i {
is-deeply @graphs[$i].ords, @cps[$i], "Codepoints in isolated grapheme $i are correct";
}
for ^@chars-to-test -> $i {
is-deeply @chars-to-test[$i].ords, @cps[$i], "Codepoints in grapheme $i created from $text is correct";
is-deeply @chars-to-test[$i].chars, 1, "Number of graphemes in grapheme $i created from $text is correct";
}
}
is-deeply ("πŸ‡¦πŸ‡§" ~ "πŸ‡¨").comb, ("πŸ‡¦πŸ‡§", "πŸ‡¨").Seq;
is-deeply ("πŸ‡¦πŸ‡§πŸ‡¨" ~ "πŸ‡©").comb, ("πŸ‡¦πŸ‡§", "πŸ‡¨πŸ‡©").Seq;
done-testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment