Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Test suite refactoring (spec/S29).

Copied /t/builtins/strings/length.t
Added smartlinks for bytes and chars.


git-svn-id: http://svn.pugscode.org/pugs@19450 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
commit d8d57b6706007f775601f44b5c2fa5360afd172c 1 parent daacea3
authored January 12, 2008

Showing 1 changed file with 74 additions and 0 deletions. Show diff stats Hide diff stats

  1. 74  S29-functions/str/length.t
74  S29-functions/str/length.t
... ...
@@ -0,0 +1,74 @@
  1
+use v6-alpha;
  2
+
  3
+use Test;
  4
+
  5
+# L<S29/Str/=item length>
  6
+
  7
+=kwid
  8
+
  9
+Various length tests (though "length" should not be used)
  10
+
  11
+This does not adequately test .chars, which is language dependent 
  12
+and needs more careful tests.
  13
+
  14
+L<"http://www.unicode.org/unicode/reports/tr11/">
  15
+
  16
+=cut
  17
+
  18
+plan 54;
  19
+
  20
+eval_dies_ok('"moose".length', 'Str.length properly not implemented');
  21
+
  22
+# string literals, for sanity
  23
+
  24
+# L<S29/Str/=item bytes>
  25
+
  26
+is("".bytes,         0, "empty string");
  27
+is("moose".bytes,    5, "moose");
  28
+my $x = undef; 
  29
+ok(!(try { $x.bytes }), "undef.bytes fail()s");
  30
+# See thread "undef.chars" on p6l started by Ingo Blechschmidt:
  31
+# L<"http://www.nntp.perl.org/group/perl.perl6.language/22595">
  32
+
  33
+# L<S29/Str/=item chars>
  34
+
  35
+# Precedence tests
  36
+ok (chars "abcdef" > 4),     "chars() has the right precedence (1)";
  37
+is (chars("abcdef" > 4)), 0, "chars() has the right precedence (2)";
  38
+
  39
+# and the real tests.
  40
+
  41
+# Please add test strings in your favorite script, especially if
  42
+# it is boustrophedonic or otherwise interesting.
  43
+my @stringy = <@stringy>;
  44
+my @data = (
  45
+    # string            octets codepoints grapheme chars
  46
+    "",                      0,        0,         0,  0,
  47
+    "moose",                 5,        5,         5,  5,
  48
+    "C:\\Program Files",    16,       16,        16, 16,
  49
+    ~@stringy,               8,        8,         8,  8,
  50
+    "\x020ac \\x020ac",     11,        9,         9,  9,
  51
+    "בדיקה",                10,        5,         5,  5,
  52
+    "בדיקה 123",            14,        9,         9,  9,
  53
+    "rántottcsirke",        14,        13,       13, 13,
  54
+    "aáeéiíoóöőuúüű",       23,        14,       14, 14,
  55
+    "AÁEÉIÍOÓÖŐUÚÜŰ",       23,        14,       14, 14,
  56
+    "»«",                    4,         2,        2,  2,
  57
+    ">><<",                  4,         4,        4,  4,
  58
+
  59
+);
  60
+#:map { my %hash; %hash<string bytes codes graphs> = $_; \%hash };
  61
+
  62
+# Should we split the loop into 4 different ones,
  63
+# just to properly cross-reference them with
  64
+# smartlinks?
  65
+
  66
+# L<S29/Str/=item length>
  67
+
  68
+for @data -> $string, $bytes, $codes, $graphs, $chars {
  69
+    is($string.bytes, $bytes, "'{$string}'.bytes");
  70
+    is($string.chars, $chars, "'{$string}'.chars");
  71
+    is($string.codes, $codes, "'{$string}'.codes");
  72
+    is($string.graphs, $graphs, "'{$string}'.graphs");
  73
+}
  74
+

0 notes on commit d8d57b6

Please sign in to comment.
Something went wrong with that request. Please try again.