Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksnyder committed Dec 3, 2023
1 parent 6ad78bd commit 0dbd027
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
20 changes: 15 additions & 5 deletions v2/internal/plural/codegen/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/xml"
"fmt"
"regexp"
"strconv"
"strings"
)

Expand Down Expand Up @@ -48,22 +49,31 @@ func (pr *PluralRule) Condition() string {
}

// Examples returns the integer and decimal examples for the PluralRule.
func (pr *PluralRule) Examples() (integer []string, decimal []string) {
func (pr *PluralRule) Examples() (integers []string, decimals []string) {
ex := strings.ReplaceAll(pr.Rule, ", …", "")
ddelim := "@decimal"
if i := strings.Index(ex, ddelim); i > 0 {
dex := strings.TrimSpace(ex[i+len(ddelim):])
dex = strings.ReplaceAll(dex, "c", "e")
decimal = strings.Split(dex, ", ")
decimals = strings.Split(dex, ", ")
ex = ex[:i]
}
idelim := "@integer"
if i := strings.Index(ex, idelim); i > 0 {
iex := strings.TrimSpace(ex[i+len(idelim):])
iex = strings.ReplaceAll(iex, "c", "e")
integer = strings.Split(iex, ", ")
integers = strings.Split(iex, ", ")
for j, integer := range integers {
ii := strings.IndexAny(integer, "eEcC")
if ii > 0 {
zeros, err := strconv.ParseInt(integer[ii+1:], 10, 0)
if err != nil {
panic(err)
}
integers[j] = integer[:ii] + strings.Repeat("0", int(zeros))
}
}
}
return integer, decimal
return integers, decimals
}

// IntegerExamples returns the integer examples for the PluralRule.
Expand Down
16 changes: 8 additions & 8 deletions v2/internal/plural/rule_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ func TestFr(t *testing.T) {
tests = appendIntegerTests(tests, One, []string{"0", "1"})
tests = appendDecimalTests(tests, One, []string{"0.0~1.5"})

tests = appendIntegerTests(tests, Many, []string{"1000000", "1e6", "2e6", "3e6", "4e6", "5e6", "6e6"})
tests = appendIntegerTests(tests, Many, []string{"1000000", "1000000", "2000000", "3000000", "4000000", "5000000", "6000000"})
tests = appendDecimalTests(tests, Many, []string{"1.0000001e6", "1.1e6", "2.0000001e6", "2.1e6", "3.0000001e6", "3.1e6"})

tests = appendIntegerTests(tests, Other, []string{"2~17", "100", "1000", "10000", "100000", "1e3", "2e3", "3e3", "4e3", "5e3", "6e3"})
tests = appendIntegerTests(tests, Other, []string{"2~17", "100", "1000", "10000", "100000", "1000", "2000", "3000", "4000", "5000", "6000"})
tests = appendDecimalTests(tests, Other, []string{"2.0~3.5", "10.0", "100.0", "1000.0", "10000.0", "100000.0", "1000000.0", "1.0001e3", "1.1e3", "2.0001e3", "2.1e3", "3.0001e3", "3.1e3"})

locales := []string{"fr"}
Expand All @@ -363,10 +363,10 @@ func TestPt(t *testing.T) {
tests = appendIntegerTests(tests, One, []string{"0", "1"})
tests = appendDecimalTests(tests, One, []string{"0.0~1.5"})

tests = appendIntegerTests(tests, Many, []string{"1000000", "1e6", "2e6", "3e6", "4e6", "5e6", "6e6"})
tests = appendIntegerTests(tests, Many, []string{"1000000", "1000000", "2000000", "3000000", "4000000", "5000000", "6000000"})
tests = appendDecimalTests(tests, Many, []string{"1.0000001e6", "1.1e6", "2.0000001e6", "2.1e6", "3.0000001e6", "3.1e6"})

tests = appendIntegerTests(tests, Other, []string{"2~17", "100", "1000", "10000", "100000", "1e3", "2e3", "3e3", "4e3", "5e3", "6e3"})
tests = appendIntegerTests(tests, Other, []string{"2~17", "100", "1000", "10000", "100000", "1000", "2000", "3000", "4000", "5000", "6000"})
tests = appendDecimalTests(tests, Other, []string{"2.0~3.5", "10.0", "100.0", "1000.0", "10000.0", "100000.0", "1000000.0", "1.0001e3", "1.1e3", "2.0001e3", "2.1e3", "3.0001e3", "3.1e3"})

locales := []string{"pt"}
Expand All @@ -380,10 +380,10 @@ func TestCaItPt_PTVec(t *testing.T) {

tests = appendIntegerTests(tests, One, []string{"1"})

tests = appendIntegerTests(tests, Many, []string{"1000000", "1e6", "2e6", "3e6", "4e6", "5e6", "6e6"})
tests = appendIntegerTests(tests, Many, []string{"1000000", "1000000", "2000000", "3000000", "4000000", "5000000", "6000000"})
tests = appendDecimalTests(tests, Many, []string{"1.0000001e6", "1.1e6", "2.0000001e6", "2.1e6", "3.0000001e6", "3.1e6"})

tests = appendIntegerTests(tests, Other, []string{"0", "2~16", "100", "1000", "10000", "100000", "1e3", "2e3", "3e3", "4e3", "5e3", "6e3"})
tests = appendIntegerTests(tests, Other, []string{"0", "2~16", "100", "1000", "10000", "100000", "1000", "2000", "3000", "4000", "5000", "6000"})
tests = appendDecimalTests(tests, Other, []string{"0.0~1.5", "10.0", "100.0", "1000.0", "10000.0", "100000.0", "1000000.0", "1.0001e3", "1.1e3", "2.0001e3", "2.1e3", "3.0001e3", "3.1e3"})

locales := []string{"ca", "it", "pt_PT", "vec"}
Expand All @@ -398,10 +398,10 @@ func TestEs(t *testing.T) {
tests = appendIntegerTests(tests, One, []string{"1"})
tests = appendDecimalTests(tests, One, []string{"1.0", "1.00", "1.000", "1.0000"})

tests = appendIntegerTests(tests, Many, []string{"1000000", "1e6", "2e6", "3e6", "4e6", "5e6", "6e6"})
tests = appendIntegerTests(tests, Many, []string{"1000000", "1000000", "2000000", "3000000", "4000000", "5000000", "6000000"})
tests = appendDecimalTests(tests, Many, []string{"1.0000001e6", "1.1e6", "2.0000001e6", "2.1e6", "3.0000001e6", "3.1e6"})

tests = appendIntegerTests(tests, Other, []string{"0", "2~16", "100", "1000", "10000", "100000", "1e3", "2e3", "3e3", "4e3", "5e3", "6e3"})
tests = appendIntegerTests(tests, Other, []string{"0", "2~16", "100", "1000", "10000", "100000", "1000", "2000", "3000", "4000", "5000", "6000"})
tests = appendDecimalTests(tests, Other, []string{"0.0~0.9", "1.1~1.6", "10.0", "100.0", "1000.0", "10000.0", "100000.0", "1000000.0", "1.0001e3", "1.1e3", "2.0001e3", "2.1e3", "3.0001e3", "3.1e3"})

locales := []string{"es"}
Expand Down

0 comments on commit 0dbd027

Please sign in to comment.