aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/unicode
diff options
context:
space:
mode:
authorDave Cheney <dave@cheney.net>2013-12-16 11:15:23 +1100
committerDave Cheney <dave@cheney.net>2013-12-16 11:15:23 +1100
commitfb31a0b1d010da48e53cce16e16c36aed58ab6cb (patch)
tree2ef45fa52b741f8270ffbec430f8effa3c2d5819 /src/pkg/unicode
parent22a7b3442ee621bd8b73d5b4ccdfcfd7b62ca8b0 (diff)
downloadgo-fb31a0b1d010da48e53cce16e16c36aed58ab6cb.tar.xz
unicode/utf16: add explicit tests for IsSurrogate
Update #6956 Add tests for IsSurrogate. R=golang-dev, r CC=golang-dev https://golang.org/cl/42570043
Diffstat (limited to 'src/pkg/unicode')
-rw-r--r--src/pkg/unicode/utf16/utf16_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/pkg/unicode/utf16/utf16_test.go b/src/pkg/unicode/utf16/utf16_test.go
index ee16a303df..05d6427b05 100644
--- a/src/pkg/unicode/utf16/utf16_test.go
+++ b/src/pkg/unicode/utf16/utf16_test.go
@@ -99,3 +99,31 @@ func TestDecode(t *testing.T) {
}
}
}
+
+var surrogateTests = []struct {
+ r rune
+ want bool
+}{
+ // from http://en.wikipedia.org/wiki/UTF-16
+ {'\u007A', false}, // LATIN SMALL LETTER Z
+ {'\u6C34', false}, // CJK UNIFIED IDEOGRAPH-6C34 (water)
+ {'\uFEFF', false}, // Byte Order Mark
+ {'\U00010000', false}, // LINEAR B SYLLABLE B008 A (first non-BMP code point)
+ {'\U0001D11E', false}, // MUSICAL SYMBOL G CLEF
+ {'\U0010FFFD', false}, // PRIVATE USE CHARACTER-10FFFD (last Unicode code point)
+
+ {rune(0xd7ff), false}, // surr1-1
+ {rune(0xd800), true}, // surr1
+ {rune(0xdc00), true}, // surr2
+ {rune(0xe000), false}, // surr3
+ {rune(0xdfff), true}, // surr3-1
+}
+
+func TestIsSurrogate(t *testing.T) {
+ for i, tt := range surrogateTests {
+ got := IsSurrogate(tt.r)
+ if got != tt.want {
+ t.Errorf("%d: IsSurrogate(%q) = %v; want %v", i, tt.r, got, tt.want)
+ }
+ }
+}