Skip to content

Commit

Permalink
Cover toPluralForm
Browse files Browse the repository at this point in the history
  • Loading branch information
fullpipe committed Sep 10, 2024
1 parent 60c2b41 commit 29920c8
Showing 1 changed file with 131 additions and 0 deletions.
131 changes: 131 additions & 0 deletions message/plural_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package message

import (
"reflect"
"testing"

"golang.org/x/text/feature/plural"
Expand Down Expand Up @@ -171,3 +172,133 @@ func TestPlural_Eval(t *testing.T) {
})
}
}

func Test_toPluralForm(t *testing.T) {
tests := []struct {
name string
num any
want pm
wantErr bool
}{
{
"int",
int(42),
pm{i: 42},
false,
},
{
"-int",
int(-42),
pm{i: 42},
false,
},
{
"int8",
int8(42),
pm{i: 42},
false,
},
{
"-int8",
int8(-42),
pm{i: 42},
false,
},
{
"int16",
int16(42),
pm{i: 42},
false,
},
{
"-int16",
int16(-42),
pm{i: 42},
false,
},
{
"int32",
int32(42),
pm{i: 42},
false,
},
{
"-int32",
int32(-42),
pm{i: 42},
false,
},
{
"int64",
int64(42),
pm{i: 42},
false,
},
{
"-int64",
int64(-42),
pm{i: 42},
false,
},
{
"uint",
uint(42),
pm{i: 42},
false,
},
{
"uint8",
uint8(42),
pm{i: 42},
false,
},
{
"uint16",
uint16(42),
pm{i: 42},
false,
},
{
"uint32",
uint32(42),
pm{i: 42},
false,
},
{
"uint64",
uint64(42),
pm{i: 42},
false,
},
{
"error on unknown type",
[]byte("foo"),
pm{},
true,
},
{
"float string",
"42.4200",
pm{i: 42, v: 4, w: 2, f: 4200, t: 42},
false,
},
{
"float string",
"1200.50",
pm{i: 1200, v: 2, w: 1, f: 50, t: 5},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := toPluralForm(tt.num)
if (err != nil) != tt.wantErr {
t.Errorf("toPluralForm() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("toPluralForm() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 29920c8

Please sign in to comment.