Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(18)

Side by Side Diff: src/pkg/utf8/utf8_test.go

Issue 5234041: code review 5234041: utf8: add Valid and ValidString (Closed)
Patch Set: diff -r 48caa9c4edf8 https://go.googlecode.com/hg/ Created 13 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/utf8/utf8.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package utf8_test 5 package utf8_test
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "testing" 9 "testing"
10 . "utf8" 10 . "utf8"
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 tt := runecounttests[i] 267 tt := runecounttests[i]
268 if out := RuneCountInString(tt.in); out != tt.out { 268 if out := RuneCountInString(tt.in); out != tt.out {
269 t.Errorf("RuneCountInString(%q) = %d, want %d", tt.in, o ut, tt.out) 269 t.Errorf("RuneCountInString(%q) = %d, want %d", tt.in, o ut, tt.out)
270 } 270 }
271 if out := RuneCount([]byte(tt.in)); out != tt.out { 271 if out := RuneCount([]byte(tt.in)); out != tt.out {
272 t.Errorf("RuneCount(%q) = %d, want %d", tt.in, out, tt.o ut) 272 t.Errorf("RuneCount(%q) = %d, want %d", tt.in, out, tt.o ut)
273 } 273 }
274 } 274 }
275 } 275 }
276 276
277 type ValidTest struct {
278 in string
279 out bool
280 }
281
282 var validTests = []ValidTest{
283 {"", true},
284 {"a", true},
285 {"abc", true},
286 {"Ж", true},
287 {"ЖЖ", true},
288 {"брэд-ЛГТМ", true},
289 {"☺☻☹", true},
290 {string([]byte{66, 250}), false},
291 {string([]byte{66, 250, 67}), false},
292 {"a\uFFFDb", true},
293 }
294
295 func TestValid(t *testing.T) {
296 for i, tt := range validTests {
297 if Valid([]byte(tt.in)) != tt.out {
298 t.Errorf("%d. Valid(%q) = %v; want %v", i, tt.in, !tt.ou t, tt.out)
299 }
300 if ValidString(tt.in) != tt.out {
301 t.Errorf("%d. ValidString(%q) = %v; want %v", i, tt.in, !tt.out, tt.out)
302 }
303 }
304 }
305
277 func BenchmarkRuneCountTenASCIIChars(b *testing.B) { 306 func BenchmarkRuneCountTenASCIIChars(b *testing.B) {
278 for i := 0; i < b.N; i++ { 307 for i := 0; i < b.N; i++ {
279 RuneCountInString("0123456789") 308 RuneCountInString("0123456789")
280 } 309 }
281 } 310 }
282 311
283 func BenchmarkRuneCountTenJapaneseChars(b *testing.B) { 312 func BenchmarkRuneCountTenJapaneseChars(b *testing.B) {
284 for i := 0; i < b.N; i++ { 313 for i := 0; i < b.N; i++ {
285 RuneCountInString("日本語日本語日本語日") 314 RuneCountInString("日本語日本語日本語日")
286 } 315 }
(...skipping 19 matching lines...) Expand all
306 DecodeRune(a) 335 DecodeRune(a)
307 } 336 }
308 } 337 }
309 338
310 func BenchmarkDecodeJapaneseRune(b *testing.B) { 339 func BenchmarkDecodeJapaneseRune(b *testing.B) {
311 nihon := []byte("本") 340 nihon := []byte("本")
312 for i := 0; i < b.N; i++ { 341 for i := 0; i < b.N; i++ {
313 DecodeRune(nihon) 342 DecodeRune(nihon)
314 } 343 }
315 } 344 }
OLDNEW
« no previous file with comments | « src/pkg/utf8/utf8.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b