1
0
mirror of https://github.com/golang/go synced 2024-11-25 05:57:57 -07:00

use the new %U format for runes

R=rsc
CC=golang-dev
https://golang.org/cl/3483041
This commit is contained in:
Rob Pike 2010-12-06 14:38:25 -05:00
parent 53eaf40eba
commit 42cfe48ffc
5 changed files with 15 additions and 15 deletions

View File

@ -3139,7 +3139,7 @@ out:
c = yyTok2[1] /* unknown char */ c = yyTok2[1] /* unknown char */
} }
if yyDebug >= 3 { if yyDebug >= 3 {
fmt.Printf("lex %.4x %s\n", uint(yychar), yyTokname(c)) fmt.Printf("lex %U %s\n", uint(yychar), yyTokname(c))
} }
return c return c
} }

View File

@ -275,10 +275,10 @@ func TestRuneIO(t *testing.T) {
size := utf8.EncodeRune(b[n:], r) size := utf8.EncodeRune(b[n:], r)
nbytes, err := buf.WriteRune(r) nbytes, err := buf.WriteRune(r)
if err != nil { if err != nil {
t.Fatalf("WriteRune(U+%.4x) error: %s", r, err) t.Fatalf("WriteRune(%U) error: %s", r, err)
} }
if nbytes != size { if nbytes != size {
t.Fatalf("WriteRune(U+%.4x) expected %d, got %d", r, size, nbytes) t.Fatalf("WriteRune(%U) expected %d, got %d", r, size, nbytes)
} }
n += size n += size
} }
@ -295,7 +295,7 @@ func TestRuneIO(t *testing.T) {
size := utf8.EncodeRune(p, r) size := utf8.EncodeRune(p, r)
nr, nbytes, err := buf.ReadRune() nr, nbytes, err := buf.ReadRune()
if nr != r || nbytes != size || err != nil { if nr != r || nbytes != size || err != nil {
t.Fatalf("ReadRune(U+%.4x) got U+%.4x,%d not U+%.4x,%d (err=%s)", r, nr, nbytes, r, size, err) t.Fatalf("ReadRune(%U) got %U,%d not %U,%d (err=%s)", r, nr, nbytes, r, size, err)
} }
} }
@ -305,11 +305,11 @@ func TestRuneIO(t *testing.T) {
for r := 0; r < NRune; r++ { for r := 0; r < NRune; r++ {
r1, size, _ := buf.ReadRune() r1, size, _ := buf.ReadRune()
if err := buf.UnreadRune(); err != nil { if err := buf.UnreadRune(); err != nil {
t.Fatalf("UnreadRune(U+%.4x) got error %q", r, err) t.Fatalf("UnreadRune(%U) got error %q", r, err)
} }
r2, nbytes, err := buf.ReadRune() r2, nbytes, err := buf.ReadRune()
if r1 != r2 || r1 != r || nbytes != size || err != nil { if r1 != r2 || r1 != r || nbytes != size || err != nil {
t.Fatalf("ReadRune(U+%.4x) after UnreadRune got U+%.4x,%d not U+%.4x,%d (err=%s)", r, r2, nbytes, r, size, err) t.Fatalf("ReadRune(%U) after UnreadRune got %U,%d not %U,%d (err=%s)", r, r2, nbytes, r, size, err)
} }
} }
} }

View File

@ -157,7 +157,7 @@ func parseCategory(line string) (state State) {
char := &chars[point] char := &chars[point]
char.field = field char.field = field
if char.codePoint != 0 { if char.codePoint != 0 {
die.Logf("point U+%04x reused\n") die.Logf("point %U reused\n")
} }
char.codePoint = lastChar char.codePoint = lastChar
char.category = field[FGeneralCategory] char.category = field[FGeneralCategory]
@ -167,7 +167,7 @@ func parseCategory(line string) (state State) {
// Decimal digit // Decimal digit
_, err := strconv.Atoi(field[FNumericValue]) _, err := strconv.Atoi(field[FNumericValue])
if err != nil { if err != nil {
die.Log("U+%04x: bad numeric field: %s", point, err) die.Log("%U: bad numeric field: %s", point, err)
} }
case "Lu": case "Lu":
char.letter(field[FCodePoint], field[FSimpleLowercaseMapping], field[FSimpleTitlecaseMapping]) char.letter(field[FCodePoint], field[FSimpleLowercaseMapping], field[FSimpleTitlecaseMapping])
@ -208,7 +208,7 @@ func (char *Char) letterValue(s string, cas string) int {
v, err := strconv.Btoui64(s, 16) v, err := strconv.Btoui64(s, 16)
if err != nil { if err != nil {
char.dump(cas) char.dump(cas)
die.Logf("U+%04x: bad letter(%s): %s", char.codePoint, s, err) die.Logf("%U: bad letter(%s): %s", char.codePoint, s, err)
} }
return int(v) return int(v)
} }

View File

@ -21,7 +21,7 @@ func TestScanForwards(t *testing.T) {
for i, expect := range runes { for i, expect := range runes {
got := str.At(i) got := str.At(i)
if got != expect { if got != expect {
t.Errorf("%s[%d]: expected %c (U+%04x); got %c (U+%04x)", s, i, expect, expect, got, got) t.Errorf("%s[%d]: expected %c (%U); got %c (%U)", s, i, expect, expect, got, got)
} }
} }
} }
@ -39,7 +39,7 @@ func TestScanBackwards(t *testing.T) {
expect := runes[i] expect := runes[i]
got := str.At(i) got := str.At(i)
if got != expect { if got != expect {
t.Errorf("%s[%d]: expected %c (U+%04x); got %c (U+%04x)", s, i, expect, expect, got, got) t.Errorf("%s[%d]: expected %c (%U); got %c (%U)", s, i, expect, expect, got, got)
} }
} }
} }
@ -63,7 +63,7 @@ func TestRandomAccess(t *testing.T) {
expect := runes[i] expect := runes[i]
got := str.At(i) got := str.At(i)
if got != expect { if got != expect {
t.Errorf("%s[%d]: expected %c (U+%04x); got %c (U+%04x)", s, i, expect, expect, got, got) t.Errorf("%s[%d]: expected %c (%U); got %c (%U)", s, i, expect, expect, got, got)
} }
} }
} }

View File

@ -58,11 +58,11 @@ func TestFullRune(t *testing.T) {
m := utf8map[i] m := utf8map[i]
b := []byte(m.str) b := []byte(m.str)
if !FullRune(b) { if !FullRune(b) {
t.Errorf("FullRune(%q) (rune %04x) = false, want true", b, m.rune) t.Errorf("FullRune(%q) (%U) = false, want true", b, m.rune)
} }
s := m.str s := m.str
if !FullRuneInString(s) { if !FullRuneInString(s) {
t.Errorf("FullRuneInString(%q) (rune %04x) = false, want true", s, m.rune) t.Errorf("FullRuneInString(%q) (%U) = false, want true", s, m.rune)
} }
b1 := b[0 : len(b)-1] b1 := b[0 : len(b)-1]
if FullRune(b1) { if FullRune(b1) {
@ -172,7 +172,7 @@ func TestIntConversion(t *testing.T) {
i := 0 i := 0
for _, r := range ts { for _, r := range ts {
if r != runes[i] { if r != runes[i] {
t.Errorf("%q[%d]: expected %c (U+%04x); got %c (U+%04x)", ts, i, runes[i], runes[i], r, r) t.Errorf("%q[%d]: expected %c (%U); got %c (%U)", ts, i, runes[i], runes[i], r, r)
} }
i++ i++
} }