mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
bytes, strings: allow -1 in Map to mean "drop this character".
xml: drop invalid characters in attribute names
when constructing struct field names.
R=rsc
CC=r
https://golang.org/cl/157104
This commit is contained in:
parent
67aa1399d6
commit
128974adfd
6 changed files with 91 additions and 26 deletions
|
|
@ -365,6 +365,19 @@ func TestMap(t *testing.T) {
|
|||
if string(m) != expect {
|
||||
t.Errorf("rot13: expected %q got %q", expect, m)
|
||||
}
|
||||
|
||||
// 5. Drop
|
||||
dropNotLatin := func(rune int) int {
|
||||
if unicode.Is(unicode.Latin, rune) {
|
||||
return rune
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
m = Map(dropNotLatin, Bytes("Hello, 세계"));
|
||||
expect = "Hello";
|
||||
if string(m) != expect {
|
||||
t.Errorf("drop: expected %q got %q", expect, m)
|
||||
}
|
||||
}
|
||||
|
||||
func TestToUpper(t *testing.T) { runStringTests(t, ToUpper, "ToUpper", upperTests) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue