зеркало из https://github.com/golang/text.git
go.text/language: fixed bug that caused EncodeM49 to panic for some values.
The added test doesn't test much, but mainly serves the purpose of asserting no panic occurs for any value. R=r CC=golang-codereviews https://golang.org/cl/48080043
This commit is contained in:
Родитель
a36a459697
Коммит
b8c3e1927b
|
@ -207,6 +207,11 @@ func TestEncodeM49(t *testing.T) {
|
|||
t.Errorf("%d:%d: was %s, %v; want %s, %v", i, tt.m49, r, err == nil, tt.code, tt.ok)
|
||||
}
|
||||
}
|
||||
for i := 1; i <= 1000; i++ {
|
||||
if r, err := EncodeM49(i); err == nil && r.M49() == 0 {
|
||||
t.Errorf("%d has no error, but maps to undefined region", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRegion(t *testing.T) {
|
||||
|
|
|
@ -296,7 +296,7 @@ func getRegionM49(n int) (regionID, error) {
|
|||
i := sort.Search(len(buf), func(i int) bool {
|
||||
return buf[i] >= val
|
||||
})
|
||||
if r := buf[i]; r&^regionMask == val {
|
||||
if r := fromM49[int(m49Index[idx])+i]; r&^regionMask == val {
|
||||
return regionID(r & regionMask), nil
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче