1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
package prompter
import (
"fmt"
"log"
"os"
"testing"
"github.com/cli/go-gh/v2/pkg/term"
"github.com/stretchr/testify/assert"
)
func ExamplePrompter() {
term := term.FromEnv()
in, ok := term.In().(*os.File)
if !ok {
log.Fatal("error casting to file")
}
out, ok := term.Out().(*os.File)
if !ok {
log.Fatal("error casting to file")
}
errOut, ok := term.ErrOut().(*os.File)
if !ok {
log.Fatal("error casting to file")
}
prompter := New(in, out, errOut)
response, err := prompter.Confirm("Shall we play a game", true)
if err != nil {
log.Fatal(err)
}
fmt.Println(response)
}
func TestLatinMatchingFilter(t *testing.T) {
tests := []struct {
name string
filter string
value string
want bool
}{
{
name: "exact match no diacritics",
filter: "Mikelis",
value: "Mikelis",
want: true,
},
{
name: "exact match no diacritics",
filter: "Mikelis",
value: "Mikelis",
want: true,
},
{
name: "exact match diacritics",
filter: "Miķelis",
value: "Miķelis",
want: true,
},
{
name: "partial match diacritics",
filter: "Miķe",
value: "Miķelis",
want: true,
},
{
name: "exact match diacritics in value",
filter: "Mikelis",
value: "Miķelis",
want: true,
},
{
name: "partial match diacritics in filter",
filter: "Miķe",
value: "Miķelis",
want: true,
},
{
name: "no match when removing diacritics in filter",
filter: "Mielis",
value: "Mikelis",
want: false,
},
{
name: "no match when removing diacritics in value",
filter: "Mikelis",
value: "Mielis",
want: false,
},
{
name: "no match diacritics in filter",
filter: "Miķelis",
value: "Mikelis",
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, latinMatchingFilter(tt.filter, tt.value, 0), tt.want)
})
}
}
|