Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

piglatin_test.gno

1.25 Kb · 56 lines
 1package piglatin
 2
 3import (
 4	"testing"
 5
 6	"gno.land/p/nt/uassert/v0"
 7)
 8
 9func TestTranslateWord(t *testing.T) {
10	cases := []struct {
11		in, want string
12	}{
13		{"pig", "igpay"},
14		{"banana", "ananabay"},
15		{"smile", "ilesmay"},
16		{"string", "ingstray"},
17		{"eat", "eatway"},
18		{"apple", "appleway"},
19		{"yellow", "ellowyay"}, // leading y = consonant
20		{"myth", "ythmay"},     // internal y = vowel
21		{"Hello", "Ellohay"},   // title-case preserved
22		{"NASA", "ASANAY"},     // all caps preserved
23	}
24	for _, c := range cases {
25		got := translateWord(c.in)
26		uassert.Equal(t, c.want, got)
27	}
28}
29
30func TestTranslateSentence(t *testing.T) {
31	cases := []struct {
32		in, want string
33	}{
34		{"hello world", "ellohay orldway"},
35		{"Hello, world!", "Ellohay, orldway!"},
36		{"The quick brown fox", "Ethay uickqay ownbray oxfay"},
37		{"", ""},
38		{"   ", "   "}, // whitespace preserved, no words
39	}
40	for _, c := range cases {
41		got := Translate(c.in)
42		uassert.Equal(t, c.want, got)
43	}
44}
45
46func TestSplitAffixes(t *testing.T) {
47	lead, core, trail := splitAffixes("(Hello!)")
48	uassert.Equal(t, "(", lead)
49	uassert.Equal(t, "Hello", core)
50	uassert.Equal(t, "!)", trail)
51
52	lead, core, trail = splitAffixes("...")
53	uassert.Equal(t, "...", lead)
54	uassert.Equal(t, "", core)
55	uassert.Equal(t, "", trail)
56}