本文整理汇总了Golang中github.com/alecthomas/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestTake
func TestTake(t *testing.T) {
s := FromInts(1, 2, 3, 4, 5)
a := s.Take(2).ToArray()
b := s.Take(3).ToArray()
assert.Equal(t, []int{1, 2}, a)
assert.Equal(t, []int{1, 2, 3}, b)
}
示例2: TestRepeat
func TestRepeat(t *testing.T) {
s := RepeatInt(5, 3)
a := s.ToArray()
b := s.ToArray()
assert.Equal(t, []int{5, 5, 5}, a)
assert.Equal(t, []int{5, 5, 5}, b)
}
示例3: TestHiddenCmdCompletion
func TestHiddenCmdCompletion(t *testing.T) {
app := newTestApp()
// top level visible & hidden cmds, with no sub-cmds
app.Command("visible1", "")
app.Command("hidden1", "").Hidden()
// visible cmd with visible & hidden sub-cmds
visible2 := app.Command("visible2", "")
visible2.Command("visible2-visible", "")
visible2.Command("visible2-hidden", "").Hidden()
// hidden cmd with visible & hidden sub-cmds
hidden2 := app.Command("hidden2", "").Hidden()
hidden2.Command("hidden2-visible", "")
hidden2.Command("hidden2-hidden", "").Hidden()
// Only top level visible cmds should show
assert.Equal(t, []string{"help", "visible1", "visible2"}, complete(t, app))
// Only visible sub-cmds should show
assert.Equal(t, []string{"visible2-visible"}, complete(t, app, "visible2"))
// Hidden commands should still complete visible sub-cmds
assert.Equal(t, []string{"hidden2-visible"}, complete(t, app, "hidden2"))
}
示例4: TestTakeLast
func TestTakeLast(t *testing.T) {
s := FromInts(1, 2, 3, 4, 5)
a := s.TakeLast(2).ToArray()
b := s.TakeLast(3).ToArray()
assert.Equal(t, []int{4, 5}, a)
assert.Equal(t, []int{3, 4, 5}, b)
}
示例5: TestRange
func TestRange(t *testing.T) {
s := Range(1, 5)
a := s.ToArray()
b := s.ToArray()
assert.Equal(t, []int{1, 2, 3, 4, 5}, a)
assert.Equal(t, []int{1, 2, 3, 4, 5}, b)
}
示例6: TestStart
func TestStart(t *testing.T) {
s := StartInt(func() (int, error) { return 42, nil })
a := s.ToArray()
b := s.ToArray()
assert.Equal(t, []int{42}, a)
assert.Equal(t, []int{42}, b)
}
示例7: TestAccumulatorStrings
func TestAccumulatorStrings(t *testing.T) {
target := []string{}
acc := newAccumulator(&target, func(v interface{}) Value { return newStringValue(v.(*string)) })
acc.Set("a")
assert.Equal(t, []string{"a"}, target)
acc.Set("b")
assert.Equal(t, []string{"a", "b"}, target)
}
示例8: TestConcat
func TestConcat(t *testing.T) {
a := []int{1, 2, 3}
b := []int{4, 5}
c := []int{6, 7}
s := FromIntArray(a).Concat(FromIntArray(b)).Concat(FromIntArray(c)).ToArray()
assert.Equal(t, []int{1, 2, 3, 4, 5, 6, 7}, s)
s = FromIntArray(a).Concat(FromIntArray(b), FromIntArray(c)).ToArray()
assert.Equal(t, []int{1, 2, 3, 4, 5, 6, 7}, s)
}
示例9: TestDefaultCmdCompletion
func TestDefaultCmdCompletion(t *testing.T) {
app := newTestApp()
cmd1 := app.Command("cmd1", "")
cmd1Sub1 := cmd1.Command("cmd1-sub1", "")
cmd1Sub1.Arg("cmd1-sub1-arg1", "").HintOptions("cmd1-arg1").String()
cmd2 := app.Command("cmd2", "").Default()
cmd2.Command("cmd2-sub1", "")
cmd2Sub2 := cmd2.Command("cmd2-sub2", "").Default()
cmd2Sub2Sub1 := cmd2Sub2.Command("cmd2-sub2-sub1", "").Default()
cmd2Sub2Sub1.Arg("cmd2-sub2-sub1-arg1", "").HintOptions("cmd2-sub2-sub1-arg1").String()
cmd2Sub2Sub1.Arg("cmd2-sub2-sub1-arg2", "").HintOptions("cmd2-sub2-sub1-arg2").String()
// Without args, should get:
// - root cmds (incuding implicit "help")
// - thread of default cmds
// - first arg hints for the final default cmd
assert.Equal(t, []string{"cmd1", "cmd2", "cmd2-sub1", "cmd2-sub2", "cmd2-sub2-sub1", "cmd2-sub2-sub1-arg1", "help"}, complete(t, app))
// With a non-default cmd already listed, should get:
// - sub cmds of that arg
assert.Equal(t, []string{"cmd1-sub1"}, complete(t, app, "cmd1"))
// With an explicit default cmd listed, should get:
// - default child-cmds
// - first arg hints for the final default cmd
assert.Equal(t, []string{"cmd2-sub1", "cmd2-sub2", "cmd2-sub2-sub1", "cmd2-sub2-sub1-arg1"}, complete(t, app, "cmd2"))
// Args should be completed when all preceding cmds are explicit, and when
// any of them are implicit (not listed). Check this by trying all possible
// combinations of choosing/excluding the three levels of cmds. This tests
// root-level default, middle default, and end default.
for i := 0; i < 8; i++ {
var cmdline []string
if i&1 != 0 {
cmdline = append(cmdline, "cmd2")
}
if i&2 != 0 {
cmdline = append(cmdline, "cmd2-sub2")
}
if i&4 != 0 {
cmdline = append(cmdline, "cmd2-sub2-sub1")
}
assert.Contains(t, complete(t, app, cmdline...), "cmd2-sub2-sub1-arg1", "with cmdline: %v", cmdline)
}
// With both args of a default sub cmd, should get no completions
assert.Empty(t, complete(t, app, "arg1", "arg2"))
}
示例10: TestCmdCompletion
func TestCmdCompletion(t *testing.T) {
app := newTestApp()
app.Command("one", "")
two := app.Command("two", "")
two.Command("sub1", "")
two.Command("sub2", "")
assert.Equal(t, []string{"help", "one", "two"}, complete(t, app))
assert.Equal(t, []string{"sub1", "sub2"}, complete(t, app, "two"))
}
示例11: TestAliasedCommand
func TestAliasedCommand(t *testing.T) {
app := newTestApp()
app.Command("one", "").Alias("two")
selected, _ := app.Parse([]string{"one"})
assert.Equal(t, "one", selected)
selected, _ = app.Parse([]string{"two"})
assert.Equal(t, "one", selected)
// 2 due to "help" and "one"
assert.Equal(t, 2, len(app.Model().FlattenedCommands()))
}
示例12: Test_Writer
func Test_Writer(t *testing.T) {
dropSize := 16
numShort := 0
shortSize := 0
validate := func(buf []byte) error {
switch {
case len(buf) == dropSize:
if numShort > 0 {
return fmt.Errorf("got full after short")
}
return nil
case len(buf) < dropSize:
if numShort > 0 {
return fmt.Errorf("got second short (%d)", len(buf))
}
numShort++
shortSize = len(buf)
default:
return fmt.Errorf("drop too large (%d > %d)", len(buf), dropSize)
}
return nil
}
buf := make([]byte, dropSize)
countingWriter := counter.NewWriter(nil)
dw := &Writer{
Buffer: buf,
Validate: validate,
Writer: countingWriter,
}
rbuf := make([]byte, 128)
write := func(l int) {
written, wErr := dw.Write(rbuf[0:l])
assert.Equal(t, l, written)
assert.NoError(t, wErr)
}
write(12)
write(4)
write(10)
write(6)
write(16)
write(64)
write(5)
assert.NoError(t, dw.Close())
assert.Equal(t, 5, shortSize)
assert.Equal(t, int64(12+4+10+6+16+64+5), countingWriter.Count())
}
示例13: TestDefaultEnvars
func TestDefaultEnvars(t *testing.T) {
a := New("some-app", "").Terminate(nil).DefaultEnvars()
f0 := a.Flag("some-flag", "")
f0.Bool()
f1 := a.Flag("some-other-flag", "").NoEnvar()
f1.Bool()
_, err := a.Parse([]string{})
assert.NoError(t, err)
assert.Equal(t, "SOME_APP_SOME_FLAG", f0.envar)
assert.Equal(t, "", f1.envar)
}
示例14: TestGetFlagAndOverrideDefault
func TestGetFlagAndOverrideDefault(t *testing.T) {
app := newTestApp()
a := app.Flag("a", "").Default("default").String()
_, err := app.Parse([]string{})
assert.NoError(t, err)
assert.Equal(t, "default", *a)
app.GetFlag("a").Default("new")
_, err = app.Parse([]string{})
assert.NoError(t, err)
assert.Equal(t, "new", *a)
}
示例15: TestInterspersedFalse
func TestInterspersedFalse(t *testing.T) {
app := newTestApp().Interspersed(false)
a1 := app.Arg("a1", "").String()
a2 := app.Arg("a2", "").String()
f1 := app.Flag("flag", "").String()
_, err := app.Parse([]string{"a1", "--flag=flag"})
assert.NoError(t, err)
assert.Equal(t, "a1", *a1)
assert.Equal(t, "--flag=flag", *a2)
assert.Equal(t, "", *f1)
}