summaryrefslogtreecommitdiff
path: root/src/lib/utf8_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2008-12-04 21:00:34 -0800
committerRuss Cox <rsc@golang.org>2008-12-04 21:00:34 -0800
commit966045873e54da1fe6f38d92f5b7850b8913c97b (patch)
tree40924d98cce298fa84801b75f01186399c0ef609 /src/lib/utf8_test.go
parent1fe7cdb6b5aef2617326746a4f01c8cd6476464f (diff)
downloadgolang-966045873e54da1fe6f38d92f5b7850b8913c97b.tar.gz
strings.utflen -> utf8.RuneCount, RuneCountInString
R=r DELTA=94 (52 added, 33 deleted, 9 changed) OCL=20547 CL=20552
Diffstat (limited to 'src/lib/utf8_test.go')
-rw-r--r--src/lib/utf8_test.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/utf8_test.go b/src/lib/utf8_test.go
index 18c06c2ce..31118dd30 100644
--- a/src/lib/utf8_test.go
+++ b/src/lib/utf8_test.go
@@ -156,3 +156,25 @@ export func TestDecodeRune(t *testing.T) {
}
}
}
+
+type RuneCountTest struct {
+ in string;
+ out int;
+}
+var runecounttests = []RuneCountTest {
+ RuneCountTest{ "abcd", 4 },
+ RuneCountTest{ "☺☻☹", 3 },
+ RuneCountTest{ "1,2,3,4", 7 },
+ RuneCountTest{ "\xe2\x00", 2 },
+}
+export func TestRuneCount(t *testing.T) {
+ for i := 0; i < len(runecounttests); i++ {
+ tt := runecounttests[i];
+ if out := utf8.RuneCountInString(tt.in, 0, len(tt.in)); out != tt.out {
+ t.Errorf("RuneCountInString(%q) = %d, want %d", tt.in, out, tt.out);
+ }
+ if out := utf8.RuneCount(Bytes(tt.in)); out != tt.out {
+ t.Errorf("RuneCount(%q) = %d, want %d", tt.in, out, tt.out);
+ }
+ }
+}