summaryrefslogtreecommitdiff
path: root/src/pkg/utf8/utf8_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/utf8/utf8_test.go')
-rw-r--r--src/pkg/utf8/utf8_test.go90
1 files changed, 45 insertions, 45 deletions
diff --git a/src/pkg/utf8/utf8_test.go b/src/pkg/utf8/utf8_test.go
index 595efc634..68bfa6a77 100644
--- a/src/pkg/utf8/utf8_test.go
+++ b/src/pkg/utf8/utf8_test.go
@@ -5,15 +5,15 @@
package utf8_test
import (
- "bytes";
- "strings";
- "testing";
- . "utf8";
+ "bytes"
+ "strings"
+ "testing"
+ . "utf8"
)
type Utf8Map struct {
- rune int;
- str string;
+ rune int
+ str string
}
var utf8map = []Utf8Map{
@@ -47,27 +47,27 @@ var utf8map = []Utf8Map{
// strings.Bytes with one extra byte at end
func makeBytes(s string) []byte {
- s += "\x00";
- b := strings.Bytes(s);
- return b[0 : len(s)-1];
+ s += "\x00"
+ b := strings.Bytes(s)
+ return b[0 : len(s)-1]
}
func TestFullRune(t *testing.T) {
for i := 0; i < len(utf8map); i++ {
- m := utf8map[i];
- b := makeBytes(m.str);
+ m := utf8map[i]
+ b := makeBytes(m.str)
if !FullRune(b) {
t.Errorf("FullRune(%q) (rune %04x) = false, want true", b, m.rune)
}
- s := m.str;
+ s := m.str
if !FullRuneInString(s) {
t.Errorf("FullRuneInString(%q) (rune %04x) = false, want true", s, m.rune)
}
- b1 := b[0 : len(b)-1];
+ b1 := b[0 : len(b)-1]
if FullRune(b1) {
t.Errorf("FullRune(%q) = true, want false", b1)
}
- s1 := string(b1);
+ s1 := string(b1)
if FullRuneInString(s1) {
t.Errorf("FullRune(%q) = true, want false", s1)
}
@@ -76,11 +76,11 @@ func TestFullRune(t *testing.T) {
func TestEncodeRune(t *testing.T) {
for i := 0; i < len(utf8map); i++ {
- m := utf8map[i];
- b := makeBytes(m.str);
- var buf [10]byte;
- n := EncodeRune(m.rune, &buf);
- b1 := buf[0:n];
+ m := utf8map[i]
+ b := makeBytes(m.str)
+ var buf [10]byte
+ n := EncodeRune(m.rune, &buf)
+ b1 := buf[0:n]
if !bytes.Equal(b, b1) {
t.Errorf("EncodeRune(%#04x) = %q want %q", m.rune, b1, b)
}
@@ -89,40 +89,40 @@ func TestEncodeRune(t *testing.T) {
func TestDecodeRune(t *testing.T) {
for i := 0; i < len(utf8map); i++ {
- m := utf8map[i];
- b := makeBytes(m.str);
- rune, size := DecodeRune(b);
+ m := utf8map[i]
+ b := makeBytes(m.str)
+ rune, size := DecodeRune(b)
if rune != m.rune || size != len(b) {
t.Errorf("DecodeRune(%q) = %#04x, %d want %#04x, %d", b, rune, size, m.rune, len(b))
}
- s := m.str;
- rune, size = DecodeRuneInString(s);
+ s := m.str
+ rune, size = DecodeRuneInString(s)
if rune != m.rune || size != len(b) {
t.Errorf("DecodeRune(%q) = %#04x, %d want %#04x, %d", s, rune, size, m.rune, len(b))
}
// there's an extra byte that bytes left behind - make sure trailing byte works
- rune, size = DecodeRune(b[0:cap(b)]);
+ rune, size = DecodeRune(b[0:cap(b)])
if rune != m.rune || size != len(b) {
t.Errorf("DecodeRune(%q) = %#04x, %d want %#04x, %d", b, rune, size, m.rune, len(b))
}
- s = m.str + "\x00";
- rune, size = DecodeRuneInString(s);
+ s = m.str + "\x00"
+ rune, size = DecodeRuneInString(s)
if rune != m.rune || size != len(b) {
t.Errorf("DecodeRuneInString(%q) = %#04x, %d want %#04x, %d", s, rune, size, m.rune, len(b))
}
// make sure missing bytes fail
- wantsize := 1;
+ wantsize := 1
if wantsize >= len(b) {
wantsize = 0
}
- rune, size = DecodeRune(b[0 : len(b)-1]);
+ rune, size = DecodeRune(b[0 : len(b)-1])
if rune != RuneError || size != wantsize {
t.Errorf("DecodeRune(%q) = %#04x, %d want %#04x, %d", b[0:len(b)-1], rune, size, RuneError, wantsize)
}
- s = m.str[0 : len(m.str)-1];
- rune, size = DecodeRuneInString(s);
+ s = m.str[0 : len(m.str)-1]
+ rune, size = DecodeRuneInString(s)
if rune != RuneError || size != wantsize {
t.Errorf("DecodeRuneInString(%q) = %#04x, %d want %#04x, %d", s, rune, size, RuneError, wantsize)
}
@@ -133,12 +133,12 @@ func TestDecodeRune(t *testing.T) {
} else {
b[len(b)-1] = 0x7F
}
- rune, size = DecodeRune(b);
+ rune, size = DecodeRune(b)
if rune != RuneError || size != 1 {
t.Errorf("DecodeRune(%q) = %#04x, %d want %#04x, %d", b, rune, size, RuneError, 1)
}
- s = string(b);
- rune, size = DecodeRune(b);
+ s = string(b)
+ rune, size = DecodeRune(b)
if rune != RuneError || size != 1 {
t.Errorf("DecodeRuneInString(%q) = %#04x, %d want %#04x, %d", s, rune, size, RuneError, 1)
}
@@ -147,18 +147,18 @@ func TestDecodeRune(t *testing.T) {
// Check that negative runes encode as U+FFFD.
func TestNegativeRune(t *testing.T) {
- errorbuf := make([]byte, UTFMax);
- errorbuf = errorbuf[0:EncodeRune(RuneError, errorbuf)];
- buf := make([]byte, UTFMax);
- buf = buf[0:EncodeRune(-1, buf)];
+ errorbuf := make([]byte, UTFMax)
+ errorbuf = errorbuf[0:EncodeRune(RuneError, errorbuf)]
+ buf := make([]byte, UTFMax)
+ buf = buf[0:EncodeRune(-1, buf)]
if !bytes.Equal(buf, errorbuf) {
t.Errorf("incorrect encoding [% x] for -1; expected [% x]", buf, errorbuf)
}
}
type RuneCountTest struct {
- in string;
- out int;
+ in string
+ out int
}
var runecounttests = []RuneCountTest{
@@ -170,7 +170,7 @@ var runecounttests = []RuneCountTest{
func TestRuneCount(t *testing.T) {
for i := 0; i < len(runecounttests); i++ {
- tt := runecounttests[i];
+ tt := runecounttests[i]
if out := RuneCountInString(tt.in); out != tt.out {
t.Errorf("RuneCountInString(%q) = %d, want %d", tt.in, out, tt.out)
}
@@ -193,28 +193,28 @@ func BenchmarkRuneCountTenJapaneseChars(b *testing.B) {
}
func BenchmarkEncodeASCIIRune(b *testing.B) {
- buf := make([]byte, UTFMax);
+ buf := make([]byte, UTFMax)
for i := 0; i < b.N; i++ {
EncodeRune('a', buf)
}
}
func BenchmarkEncodeJapaneseRune(b *testing.B) {
- buf := make([]byte, UTFMax);
+ buf := make([]byte, UTFMax)
for i := 0; i < b.N; i++ {
EncodeRune('本', buf)
}
}
func BenchmarkDecodeASCIIRune(b *testing.B) {
- a := []byte{'a'};
+ a := []byte{'a'}
for i := 0; i < b.N; i++ {
DecodeRune(a)
}
}
func BenchmarkDecodeJapaneseRune(b *testing.B) {
- nihon := strings.Bytes("本");
+ nihon := strings.Bytes("本")
for i := 0; i < b.N; i++ {
DecodeRune(nihon)
}