From 128974adfd8384ef6d8ee90f711df6a771c9cb1f Mon Sep 17 00:00:00 2001 From: Kei Son Date: Fri, 11 Dec 2009 10:37:48 -0800 Subject: 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 --- src/pkg/bytes/bytes_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/pkg/bytes/bytes_test.go') diff --git a/src/pkg/bytes/bytes_test.go b/src/pkg/bytes/bytes_test.go index 553ceb7c5a..3f77e6e9ff 100644 --- a/src/pkg/bytes/bytes_test.go +++ b/src/pkg/bytes/bytes_test.go @@ -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) } -- cgit v1.3-5-g9baa