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

Golang expect.New函数代码示例

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

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



在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestSort

func TestSort(t *testing.T) {
	expect := expect.New(t)

	v := []string{
		"SomeLongThing",
		"Something",
		"Thing",
		"thing",
		"thisIsBad",
		"thingimajigger",
		"thingy",
		"thisIsNotAGoodMatch",
		"Thang",
		"tang",
		"bacon",
		"eggs",
	}
	expect(scoring.Sort(v, "thing")).To.Equal([]string{
		"thing",
		"Thing",
		"thingy",
		"thingimajigger",
		"Thang",
		"tang",
		"thisIsBad",
		"thisIsNotAGoodMatch",
		"Something",
		"SomeLongThing",
	})
}
开发者ID:nelsam,项目名称:vidar,代码行数:30,代码来源:score_test.go


示例2: TestLoad

func TestLoad(t *testing.T) {
	expect := expect.New(t)

	expect(func() {
		packages.Load("foo")
	}).To.Panic()

	dirs := packages.Load(".")
	expect(dirs).To.Have.Len(1)
	wd, err := os.Getwd()
	expect(err).To.Be.Nil()
	expect(dirs[0].Path()).To.Equal(wd)
	expect(dirs[0].Packages()).To.Have.Keys("packages", "packages_test")

	dirs = packages.Load("github.com/nelsam/hel/mocks")
	expect(dirs).To.Have.Len(1)
	expectedPath := strings.TrimSuffix(wd, "packages") + "mocks"
	expect(dirs[0].Path()).To.Equal(expectedPath)

	dirs = packages.Load("github.com/nelsam/hel/...")
	expect(dirs).To.Have.Len(4)

	pkg, err := dirs[0].Import("path/filepath", "filepath")
	expect(err).To.Be.Nil()
	expect(pkg).Not.To.Be.Nil()

	_, err = dirs[0].Import("path/filepath", "foo")
	expect(err).Not.To.Be.Nil()
	expect(err.Error()).To.Equal("Could not find package foo")
}
开发者ID:jasonkeene,项目名称:hel,代码行数:30,代码来源:packages_test.go


示例3: TestMockMethodLocalTypeNesting

func TestMockMethodLocalTypeNesting(t *testing.T) {
	expect := expect.New(t)

	spec := typeSpec(expect, `
 type Foo interface {
   Foo(bar []Bar, bacon map[Foo]Bar) (baz []Baz, eggs map[Foo]Bar)
 }`)
	mock, err := mocks.For(spec)
	expect(err).To.Be.Nil().Else.FailNow()
	method := mocks.MethodFor(mock, "Foo", method(expect, spec))
	method.PrependLocalPackage("foo")

	expected, err := format.Source([]byte(`
 package foo

 func (m *mockFoo) Foo(bar []foo.Bar, bacon map[foo.Foo]foo.Bar) (baz []foo.Baz, eggs map[foo.Foo]foo.Bar) {
   m.FooCalled <- true
   m.FooInput.Bar <- bar
   m.FooInput.Bacon <- bacon
   return <-m.FooOutput.Baz, <-m.FooOutput.Eggs
 }`))
	expect(err).To.Be.Nil().Else.FailNow()

	src := source(expect, "foo", []ast.Decl{method.Ast()}, nil)
	expect(src).To.Equal(string(expected))
}
开发者ID:nelsam,项目名称:hel,代码行数:26,代码来源:method_test.go


示例4: TestUnicode

func TestUnicode(t *testing.T) {
	expect := expect.New(t)

	src := `
package foo

func µ() string {
	var þ = "Ωð"
	return þ
}
`
	s := syntax.New(syntax.DefaultTheme)
	err := s.Parse(src)
	expect(err).To.Be.Nil()

	layers := s.Layers()
	keywords := layers[syntax.DefaultTheme.Colors.Keyword]
	expect(keywords.Spans()).To.Have.Len(4)
	expect(keywords.Spans()[2]).To.Pass(position{src: src, match: "var"})
	expect(keywords.Spans()[3]).To.Pass(position{src: src, match: "return"})

	strings := layers[syntax.DefaultTheme.Colors.String]
	expect(strings.Spans()).To.Have.Len(1)
	expect(strings.Spans()[0]).To.Pass(position{src: src, match: `"Ωð"`})
}
开发者ID:nelsam,项目名称:vidar,代码行数:25,代码来源:general_test.go


示例5: TestMockConstructor_VariadicParams

func TestMockConstructor_VariadicParams(t *testing.T) {
	expect := expect.New(t)

	spec := typeSpec(expect, `
 type Foo interface {
  Foo(foo ...int)
 }
 `)
	m, err := mocks.For(spec)
	expect(err).To.Be.Nil().Else.FailNow()

	expected, err := format.Source([]byte(`
 package foo

 func newMockFoo() *mockFoo {
  m := &mockFoo{}
  m.FooCalled = make(chan bool, 200)
  m.FooInput.Foo = make(chan []int, 200)
  return m
 }
 `))
	expect(err).To.Be.Nil().Else.FailNow()

	src := source(expect, "foo", []ast.Decl{m.Constructor(200)}, nil)
	expect(src).To.Equal(string(expected))
}
开发者ID:nelsam,项目名称:hel,代码行数:26,代码来源:mock_test.go


示例6: TestMockTypeDecl_DirectionalChansGetParens

func TestMockTypeDecl_DirectionalChansGetParens(t *testing.T) {
	expect := expect.New(t)

	spec := typeSpec(expect, `
 type Foo interface {
  Foo(foo chan<- int) <-chan int
 }
 `)
	m, err := mocks.For(spec)
	expect(err).To.Be.Nil().Else.FailNow()

	expected, err := format.Source([]byte(`
 package foo

 type mockFoo struct {
  FooCalled chan bool
  FooInput struct {
   Foo chan (chan<- int)
  }
  FooOutput struct {
   Ret0 chan (<-chan int)
  }
 }
 `))
	expect(err).To.Be.Nil().Else.FailNow()

	src := source(expect, "foo", []ast.Decl{m.Decl()}, nil)
	expect(src).To.Equal(string(expected))
}
开发者ID:nelsam,项目名称:hel,代码行数:29,代码来源:mock_test.go


示例7: TestMockConstructor

func TestMockConstructor(t *testing.T) {
	expect := expect.New(t)

	spec := typeSpec(expect, `
 type Foo interface {
  Foo(foo string) int
  Bar(bar int) string
 }
 `)
	m, err := mocks.For(spec)
	expect(err).To.Be.Nil().Else.FailNow()

	expected, err := format.Source([]byte(`
 package foo

 func newMockFoo() *mockFoo {
  m := &mockFoo{}
  m.FooCalled = make(chan bool, 300)
  m.FooInput.Foo = make(chan string, 300)
  m.FooOutput.Ret0 = make(chan int, 300)
  m.BarCalled = make(chan bool, 300)
  m.BarInput.Bar = make(chan int, 300)
  m.BarOutput.Ret0 = make(chan string, 300)
  return m
 }`))
	expect(err).To.Be.Nil().Else.FailNow()

	src := source(expect, "foo", []ast.Decl{m.Constructor(300)}, nil)
	expect(src).To.Equal(string(expected))
}
开发者ID:nelsam,项目名称:hel,代码行数:30,代码来源:mock_test.go


示例8: TestMockConstructor_DirectionalChansGetParens

func TestMockConstructor_DirectionalChansGetParens(t *testing.T) {
	expect := expect.New(t)

	spec := typeSpec(expect, `
 type Foo interface {
  Foo(foo chan<- int) <-chan int
 }
 `)
	m, err := mocks.For(spec)
	expect(err).To.Be.Nil().Else.FailNow()

	expected, err := format.Source([]byte(`
 package foo

 func newMockFoo() *mockFoo {
  m := &mockFoo{}
  m.FooCalled = make(chan bool, 200)
  m.FooInput.Foo = make(chan (chan<- int), 200)
  m.FooOutput.Ret0 = make(chan (<-chan int), 200)
  return m
 }
 `))
	expect(err).To.Be.Nil().Else.FailNow()

	src := source(expect, "foo", []ast.Decl{m.Constructor(200)}, nil)
	expect(src).To.Equal(string(expected))
}
开发者ID:nelsam,项目名称:hel,代码行数:27,代码来源:mock_test.go


示例9: TestMockSimpleMethod

func TestMockSimpleMethod(t *testing.T) {
	expect := expect.New(t)

	spec := typeSpec(expect, `
 type Foo interface {
         Foo()
 }`)
	mock, err := mocks.For(spec)
	expect(err).To.Be.Nil().Else.FailNow()
	method := mocks.MethodFor(mock, "Foo", method(expect, spec))

	expected, err := format.Source([]byte(`
 package foo

 func (m *mockFoo) Foo() {
   m.FooCalled <- true
 }`))
	expect(err).To.Be.Nil().Else.FailNow()

	src := source(expect, "foo", []ast.Decl{method.Ast()}, nil)
	expect(src).To.Equal(string(expected))

	fields := method.Fields()
	expect(fields).To.Have.Len(1).Else.FailNow()

	expect(fields[0].Names[0].Name).To.Equal("FooCalled")
	ch, ok := fields[0].Type.(*ast.ChanType)
	expect(ok).To.Be.Ok().Else.FailNow()
	expect(ch.Dir).To.Equal(ast.SEND | ast.RECV)
	ident, ok := ch.Value.(*ast.Ident)
	expect(ident.Name).To.Equal("bool")
}
开发者ID:nelsam,项目名称:hel,代码行数:32,代码来源:method_test.go


示例10: Array

func Array(t *testing.T) {
	expect := expect.New(t)

	src := `
	package foo
	
	func main() {
		var v [3]string
		v := [...]string{"foo"}
	}
	`
	s := syntax.New(syntax.DefaultTheme)
	err := s.Parse(src)
	expect(err).To.Be.Nil().Else.FailNow()

	layers := s.Layers()

	// Ditch the function color
	syntax.DefaultTheme.Rainbow.New()

	arrParens := layers[syntax.DefaultTheme.Rainbow.New()]
	expect(arrParens.Spans()).To.Have.Len(6).Else.FailNow()
	expect(arrParens.Spans()[0]).To.Pass(position{src: src, match: "["})
	expect(arrParens.Spans()[1]).To.Pass(position{src: src, match: "]"})
	expect(arrParens.Spans()[2]).To.Pass(position{src: src, match: "[", idx: 1})
	expect(arrParens.Spans()[3]).To.Pass(position{src: src, match: "]", idx: 1})
	expect(arrParens.Spans()[4]).To.Pass(position{src: src, match: "{", idx: 1})
	expect(arrParens.Spans()[5]).To.Pass(position{src: src, match: "}"})

	typs := layers[syntax.DefaultTheme.Colors.Type]
	expect(typs.Spans()).To.Have.Len(2).Else.FailNow()
	expect(typs.Spans()[0]).To.Pass(position{src: src, match: "string"})
	expect(typs.Spans()[1]).To.Pass(position{src: src, match: "string", idx: 1})
}
开发者ID:nelsam,项目名称:vidar,代码行数:34,代码来源:parens_test.go


示例11: AssignStmt

func AssignStmt(t *testing.T) {
	expect := expect.New(t)

	src := `
package foo
	
func main() {
	x := 0.1
	y = "foo"
}`

	s := syntax.New(syntax.DefaultTheme)
	err := s.Parse(src)
	expect(err).To.Be.Nil()

	layers := s.Layers()
	expect(layers).To.Have.Len(6)

	nums := layers[syntax.DefaultTheme.Colors.Num]
	expect(nums.Spans()).To.Have.Len(1)
	expect(nums.Spans()[0]).To.Pass(position{src: src, match: "0.1"})

	strings := layers[syntax.DefaultTheme.Colors.String]
	expect(strings.Spans()).To.Have.Len(1)
	expect(strings.Spans()[0]).To.Pass(position{src: src, match: `"foo"`})
}
开发者ID:nelsam,项目名称:vidar,代码行数:26,代码来源:stmt_test.go


示例12: TestMockTypeDecl_VariadicMethods

func TestMockTypeDecl_VariadicMethods(t *testing.T) {
	expect := expect.New(t)

	spec := typeSpec(expect, `
type Foo interface {
 Foo(foo ...int)
}
`)
	m, err := mocks.For(spec)
	expect(err).To.Be.Nil()
	expect(m).Not.To.Be.Nil()

	expected, err := format.Source([]byte(`
 package foo

 type mockFoo struct {
  FooCalled chan bool
  FooInput struct {
   Foo chan []int
  }
 }
 `))
	expect(err).To.Be.Nil()

	src := source(expect, "foo", []ast.Decl{m.Decl()}, nil)
	expect(src).To.Equal(string(expected))
}
开发者ID:jasonkeene,项目名称:hel,代码行数:27,代码来源:mock_test.go


示例13: FuncBody

func FuncBody(t *testing.T) {
	expect := expect.New(t)

	src := `
	package foo

	func (*Foo) Foo(baz Baz) {
		baz.Bar()
	}
	`
	s := syntax.New(syntax.DefaultTheme)
	err := s.Parse(src)
	expect(err).To.Be.Nil().Else.FailNow()

	layers := s.Layers()

	firstParens := layers[syntax.DefaultTheme.Rainbow.New()]
	expect(firstParens.Spans()).To.Have.Len(6).Else.FailNow()

	expect(firstParens.Spans()[0]).To.Pass(position{src: src, match: "("})
	expect(firstParens.Spans()[1]).To.Pass(position{src: src, match: ")"})
	expect(firstParens.Spans()[2]).To.Pass(position{src: src, match: "(", idx: 1})
	expect(firstParens.Spans()[3]).To.Pass(position{src: src, match: ")", idx: 1})
	expect(firstParens.Spans()[4]).To.Pass(position{src: src, match: "{"})
	expect(firstParens.Spans()[5]).To.Pass(position{src: src, match: "}"})

	secondParens := layers[syntax.DefaultTheme.Rainbow.New()]
	expect(secondParens.Spans()).To.Have.Len(2).Else.FailNow()
	expect(secondParens.Spans()[0]).To.Pass(position{src: src, match: "(", idx: 2})
	expect(secondParens.Spans()[1]).To.Pass(position{src: src, match: ")", idx: 2})
}
开发者ID:nelsam,项目名称:vidar,代码行数:31,代码来源:parens_test.go


示例14: TestMockMethodParams

func TestMockMethodParams(t *testing.T) {
	expect := expect.New(t)

	spec := typeSpec(expect, `
 type Foo interface {
         Foo(foo, bar string, baz int)
 }`)
	mock, err := mocks.For(spec)
	expect(err).To.Be.Nil()
	method := mocks.MethodFor(mock, "Foo", method(expect, spec))

	expected, err := format.Source([]byte(`
 package foo

 func (m *mockFoo) Foo(foo, bar string, baz int) {
   m.FooCalled <- true
   m.FooInput.Foo <- foo
   m.FooInput.Bar <- bar
   m.FooInput.Baz <- baz
 }`))
	expect(err).To.Be.Nil()

	src := source(expect, "foo", []ast.Decl{method.Ast()}, nil)
	expect(src).To.Equal(string(expected))
}
开发者ID:jasonkeene,项目名称:hel,代码行数:25,代码来源:method_test.go


示例15: TestLoad_TestFilesInTestPackage

func TestLoad_TestFilesInTestPackage(t *testing.T) {
	expect := expect.New(t)

	mockGoDir := newMockGoDir()
	mockGoDir.PathOutput.Path <- "/some/path"
	mockGoDir.PackagesOutput.Packages <- map[string]*ast.Package{
		"foo": {
			Name: "foo",
			Files: map[string]*ast.File{
				"foo.go": parse(expect, "type Foo interface{}"),
			},
		},
		"foo_test": {
			Name: "foo_test",
			Files: map[string]*ast.File{
				"foo_test.go": parse(expect, "type Bar interface{}"),
			},
		},
	}
	found := types.Load(mockGoDir)
	expect(found).To.Have.Len(1).Else.FailNow()
	expect(found[0].Len()).To.Equal(1)
	expect(found[0].Package()).To.Equal("foo")
	expect(found[0].TestPackage()).To.Equal("foo_test")
}
开发者ID:nelsam,项目名称:hel,代码行数:25,代码来源:types_test.go


示例16: TestAnonymousError

// TestAnonymousError is testing the only case (as of go 1.7) where
// a builtin is an interface type.
func TestAnonymousError(t *testing.T) {
	expect := expect.New(t)

	mockGoDir := newMockGoDir()
	mockGoDir.PathOutput.Path <- "/some/path"
	mockGoDir.PackagesOutput.Packages <- map[string]*ast.Package{
		"foo": {
			Name: "foo",
			Files: map[string]*ast.File{
				"foo.go": parse(expect, `
    type Foo interface{
        error
    }`),
			},
		},
	}
	found := types.Load(mockGoDir)
	expect(found).To.Have.Len(1).Else.FailNow()

	typs := found[0].ExportedTypes()
	expect(typs).To.Have.Len(1).Else.FailNow()

	spec := typs[0]
	expect(spec).Not.To.Be.Nil().Else.FailNow()

	inter := spec.Type.(*ast.InterfaceType)
	expect(inter.Methods.List).To.Have.Len(1).Else.FailNow()
	err := inter.Methods.List[0]
	expect(err.Names[0].String()).To.Equal("Error")
	_, isFunc := err.Type.(*ast.FuncType)
	expect(isFunc).To.Be.Ok()
}
开发者ID:nelsam,项目名称:hel,代码行数:34,代码来源:types_test.go


示例17: TestMockTypeDecl_ParamsWithoutTypes

func TestMockTypeDecl_ParamsWithoutTypes(t *testing.T) {
	expect := expect.New(t)

	spec := typeSpec(expect, `
type Foo interface {
 Foo(foo, bar string)
}
`)
	m, err := mocks.For(spec)
	expect(err).To.Be.Nil().Else.FailNow()

	expected, err := format.Source([]byte(`
package foo

type mockFoo struct {
 FooCalled chan bool
 FooInput struct {
  Foo, Bar chan string
 }
}
`))
	expect(err).To.Be.Nil().Else.FailNow()

	src := source(expect, "foo", []ast.Decl{m.Decl()}, nil)
	expect(src).To.Equal(string(expected))
}
开发者ID:nelsam,项目名称:hel,代码行数:26,代码来源:mock_test.go


示例18: TestMockMethodUnnamedValues

func TestMockMethodUnnamedValues(t *testing.T) {
	expect := expect.New(t)

	spec := typeSpec(expect, `
 type Foo interface {
   Foo(int, string) (string, error)
 }`)
	mock, err := mocks.For(spec)
	expect(err).To.Be.Nil()
	method := mocks.MethodFor(mock, "Foo", method(expect, spec))

	expected, err := format.Source([]byte(`
 package foo

 func (m *mockFoo) Foo(arg0 int, arg1 string) (string, error) {
   m.FooCalled <- true
   m.FooInput.Arg0 <- arg0
   m.FooInput.Arg1 <- arg1
   return <-m.FooOutput.Ret0, <-m.FooOutput.Ret1
 }`))
	expect(err).To.Be.Nil()

	src := source(expect, "foo", []ast.Decl{method.Ast()}, nil)
	expect(src).To.Equal(string(expected))
}
开发者ID:jasonkeene,项目名称:hel,代码行数:25,代码来源:method_test.go


示例19: TestAliasedImportedDependencies

func TestAliasedImportedDependencies(t *testing.T) {
	expect := expect.New(t)

	mockGoDir := newMockGoDir()
	mockGoDir.PathOutput.Path <- "/some/path"
	mockGoDir.PackagesOutput.Packages <- map[string]*ast.Package{
		"bar": {
			Name: "bar",
			Files: map[string]*ast.File{
				"foo.go": parse(expect, `

    import baz "some/path/to/foo"

    type Bar interface{
        Bar(baz.Foo) baz.Bar
    }`),
			},
		},
	}

	close(mockGoDir.ImportOutput.Err)
	pkgName := "foo"
	pkg := &ast.Package{
		Name: pkgName,
		Files: map[string]*ast.File{
			"foo.go": parse(expect, `
    type Foo interface {
        Foo()
    }

	type Bar interface {
		Bar()
	}`),
		},
	}
	mockGoDir.ImportOutput.Pkg <- pkg
	mockGoDir.ImportOutput.Name <- pkgName
	mockGoDir.ImportOutput.Pkg <- pkg
	mockGoDir.ImportOutput.Name <- pkgName

	found := types.Load(mockGoDir)
	expect(mockGoDir.ImportCalled).To.Have.Len(2)
	expect(<-mockGoDir.ImportInput.Path).To.Equal("some/path/to/foo")

	expect(found).To.Have.Len(1).Else.FailNow()
	mockables := found[0].ExportedTypes()
	expect(mockables).To.Have.Len(1)

	dependencies := found[0].Dependencies(mockables[0].Type.(*ast.InterfaceType))
	expect(dependencies).To.Have.Len(2)

	names := make(map[string]bool)
	for _, dependent := range dependencies {
		expect(dependent.PkgName).To.Equal("baz")
		expect(dependent.PkgPath).To.Equal("some/path/to/foo")
		names[dependent.Type.Name.String()] = true
	}
	expect(names).To.Equal(map[string]bool{"Foo": true, "Bar": true})
}
开发者ID:nelsam,项目名称:hel,代码行数:59,代码来源:types_test.go


示例20: TestMockName

func TestMockName(t *testing.T) {
	expect := expect.New(t)

	spec := typeSpec(expect, "type Foo interface{}")
	m, err := mocks.For(spec)
	expect(err).To.Be.Nil().Else.FailNow()
	expect(m.Name()).To.Equal("mockFoo")
}
开发者ID:nelsam,项目名称:hel,代码行数:8,代码来源:mock_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang objects.Blob函数代码示例发布时间:2022-05-24
下一篇:
Golang environments.Environment类代码示例发布时间: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