• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang assert.Equal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/alecthomas/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:alecthomas,项目名称:gorx,代码行数:7,代码来源:gorx_test.go


示例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)
}
开发者ID:alecthomas,项目名称:gorx,代码行数:7,代码来源:gorx_test.go


示例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"))
}
开发者ID:nextrevision,项目名称:sapt,代码行数:26,代码来源:cmd_test.go


示例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)
}
开发者ID:alecthomas,项目名称:gorx,代码行数:7,代码来源:gorx_test.go


示例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)
}
开发者ID:alecthomas,项目名称:gorx,代码行数:7,代码来源:gorx_test.go


示例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)
}
开发者ID:alecthomas,项目名称:gorx,代码行数:7,代码来源:gorx_test.go


示例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)
}
开发者ID:tempuser1909,项目名称:certigo,代码行数:8,代码来源:values_test.go


示例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)
}
开发者ID:alecthomas,项目名称:gorx,代码行数:9,代码来源:gorx_test.go


示例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"))
}
开发者ID:nextrevision,项目名称:sapt,代码行数:56,代码来源:cmd_test.go


示例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"))
}
开发者ID:nextrevision,项目名称:sapt,代码行数:10,代码来源:cmd_test.go


示例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()))
}
开发者ID:nextrevision,项目名称:sapt,代码行数:10,代码来源:cmd_test.go


示例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())
}
开发者ID:itchio,项目名称:wharf,代码行数:54,代码来源:dripwriter_test.go


示例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)
}
开发者ID:bjaglin,项目名称:kingpin,代码行数:11,代码来源:app_test.go


示例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)
}
开发者ID:nextrevision,项目名称:sapt,代码行数:11,代码来源:flags_test.go


示例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)
}
开发者ID:bjaglin,项目名称:kingpin,代码行数:12,代码来源:app_test.go


示例16: TestCreate

func TestCreate(t *testing.T) {
	s := CreateInt(func(observer IntObserver, subscription Subscription) {
		observer.Next(0)
		observer.Next(1)
		observer.Next(2)
		observer.Complete()
	})
	a := s.ToArray()
	b := s.ToArray()
	assert.Equal(t, []int{0, 1, 2}, a)
	assert.Equal(t, []int{0, 1, 2}, b)
}
开发者ID:alecthomas,项目名称:gorx,代码行数:12,代码来源:gorx_test.go


示例17: TestDefaultSubcommandWithFlags

func TestDefaultSubcommandWithFlags(t *testing.T) {
	app := newTestApp()
	c0 := app.Command("c0", "").Default()
	_ = c0.Flag("f0", "").Int()
	c0c1 := c0.Command("c1", "").Default()
	c0c1f1 := c0c1.Flag("f1", "").Int()
	selected, err := app.Parse([]string{"--f1=2"})
	assert.NoError(t, err)
	assert.Equal(t, "c0 c1", selected)
	assert.Equal(t, 2, *c0c1f1)
	_, err = app.Parse([]string{"--f2"})
	assert.Error(t, err)
}
开发者ID:nextrevision,项目名称:sapt,代码行数:13,代码来源:cmd_test.go


示例18: TestNestedCommandsWithArgs

func TestNestedCommandsWithArgs(t *testing.T) {
	app := New("app", "")
	cmd := app.Command("a", "").Command("b", "")
	a := cmd.Arg("a", "").String()
	b := cmd.Arg("b", "").String()
	context := tokenize([]string{"a", "b", "c", "d"}, false)
	selected, err := parseAndExecute(app, context)
	assert.NoError(t, err)
	assert.True(t, context.EOL())
	assert.Equal(t, "a b", selected)
	assert.Equal(t, "c", *a)
	assert.Equal(t, "d", *b)
}
开发者ID:nextrevision,项目名称:sapt,代码行数:13,代码来源:cmd_test.go


示例19: TestReplay

func TestReplay(t *testing.T) {
	ch := make(chan int, 5)
	for i := 0; i < 5; i++ {
		ch <- i
	}
	close(ch)
	s := FromIntChannel(ch).Replay(0, 0)
	a := s.ToArray()
	b := s.ToArray()
	expected := []int{0, 1, 2, 3, 4}
	assert.Equal(t, expected, a)
	assert.Equal(t, expected, b)
}
开发者ID:alecthomas,项目名称:gorx,代码行数:13,代码来源:gorx_test.go


示例20: TestDefaultSubcommandWithArg

func TestDefaultSubcommandWithArg(t *testing.T) {
	app := newTestApp()
	c0 := app.Command("c0", "").Default()
	c01 := c0.Command("c01", "").Default()
	c012 := c01.Command("c012", "").Default()
	a0 := c012.Arg("a0", "").String()
	c0.Command("c02", "")

	cmd, err := app.Parse([]string{"c0", "hello"})
	assert.NoError(t, err)
	assert.Equal(t, "c0 c01 c012", cmd)
	assert.Equal(t, "hello", *a0)
}
开发者ID:nextrevision,项目名称:sapt,代码行数:13,代码来源:cmd_test.go



注:本文中的github.com/alecthomas/assert.Equal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang assert.Error函数代码示例发布时间:2022-05-24
下一篇:
Golang token.Buffer类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap