feature/plural: fixed bug
bug in tests and API cancelled each other out
Change-Id: I94520066f30180448c84bc195ea3b6797432d452
Reviewed-on: https://go-review.googlesource.com/58412
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/feature/plural/plural.go b/feature/plural/plural.go
index 2b4cfe3..7273091 100644
--- a/feature/plural/plural.go
+++ b/feature/plural/plural.go
@@ -113,13 +113,12 @@
// 100000.00 []byte{1} 6......3
func (p *Rules) MatchDigits(t language.Tag, digits []byte, exp, scale int) Form {
index, _ := language.CompactIndex(t)
- endN := len(digits) + exp
// Differentiate up to including mod 1000000 for the integer part.
- n := getIntApprox(digits, 0, endN, 6, 1000000)
+ n := getIntApprox(digits, 0, exp, 6, 1000000)
// Differentiate up to including mod 100 for the fractional part.
- f := getIntApprox(digits, endN, endN+scale, 2, 100)
+ f := getIntApprox(digits, exp, exp+scale, 2, 100)
return matchPlural(p, index, n, f, scale)
}
diff --git a/feature/plural/plural_test.go b/feature/plural/plural_test.go
index e5524c5..2b30e9d 100644
--- a/feature/plural/plural_test.go
+++ b/feature/plural/plural_test.go
@@ -28,6 +28,8 @@
{"123", 0, 2, 2, 12},
{"123", 3, 4, 2, 0},
{"12345", 3, 4, 2, 4},
+ {"40", 0, 1, 2, 4},
+ {"1", 0, 7, 2, big},
{"123", 0, 5, 2, big},
{"123", 0, 5, 3, big},
@@ -114,7 +116,7 @@
for i := range digits {
digits[i] -= '0'
}
- if f := p.MatchDigits(tag, digits, 0, 0); f != Form(tc.form) {
+ if f := p.MatchDigits(tag, digits, len(digits), 0); f != Form(tc.form) {
t.Errorf("MatchDigits: got %v; want %v", f, Form(tc.form))
}
})
@@ -142,11 +144,12 @@
if f := p.matchComponents(tag, n/m, n%m, scale); f != Form(tc.form) {
t.Errorf("matchComponents: got %v; want %v", f, Form(tc.form))
}
+ exp := strings.IndexByte(num, '.')
digits := []byte(strings.Replace(num, ".", "", 1))
for i := range digits {
digits[i] -= '0'
}
- if f := p.MatchDigits(tag, digits, -scale, scale); f != Form(tc.form) {
+ if f := p.MatchDigits(tag, digits, exp, scale); f != Form(tc.form) {
t.Errorf("MatchDigits: got %v; want %v", f, Form(tc.form))
}
})