package ncli_test import ( "git.noahlan.cn/noahlan/ntool/ncli" "git.noahlan.cn/noahlan/ntool/ntest/assert" "testing" ) func TestReadFirst(t *testing.T) { // testutil.RewriteStdout() // _, err := os.Stdout.WriteString("haha") // ans, err1 := ncli.ReadFirst("hi?") // testutil.RestoreStdout() // assert.NoError(t, err) // assert.NoError(t, err1) // assert.Equal(t, "haha", ans) } func TestInputIsYes(t *testing.T) { tests := []struct { in string wnt bool }{ {"y", true}, {"yes", true}, {"yES", true}, {"Y", true}, {"Yes", true}, {"YES", true}, {"h", false}, {"n", false}, {"no", false}, {"NO", false}, } for _, test := range tests { assert.Eq(t, test.wnt, ncli.InputIsYes(test.in)) } } func TestByteIsYes(t *testing.T) { tests := []struct { in byte wnt bool }{ {'y', true}, {'Y', true}, {'h', false}, {'n', false}, {'N', false}, } for _, test := range tests { assert.Eq(t, test.wnt, ncli.ByteIsYes(test.in)) } }