本文整理汇总了Golang中github.com/a8m/expect.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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",
})
}
示例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")
}
示例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))
}
示例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: `"Ωð"`})
}
示例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))
}
示例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))
}
示例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))
}
示例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))
}
示例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")
}
示例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})
}
示例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"`})
}
示例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))
}
示例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})
}
示例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))
}
示例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")
}