本文整理匯總了Golang中github.com/nordsieck/defect.Equal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Equal函數的具體用法?Golang Equal怎麽用?Golang Equal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Equal函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestConvertDir
func TestConvertDir(t *testing.T) {
bFile := `package bar
`
dFile := `package c
`
root := path.Join("foo", "bar")
files := map[string]*testutil.FakeFile{
path.Join(root, "a"): &testutil.FakeFile{Buffer: *bytes.NewBufferString("a")},
path.Join(root, "b"+fExt): &testutil.FakeFile{Buffer: *bytes.NewBufferString(bFile)},
path.Join(root, "b"+fExt+goExt): &testutil.FakeFile{},
path.Join(root, "c", "d"+fExt): &testutil.FakeFile{Buffer: *bytes.NewBufferString(dFile)},
path.Join(root, "c", "d"+fExt+goExt): &testutil.FakeFile{},
}
infos := map[string][]os.FileInfo{
root: []os.FileInfo{
&FileInfo{name: "a", size: 1},
&FileInfo{name: "b" + fExt, size: int64(len(bFile))},
&FileInfo{name: "c", isDir: true},
},
path.Join(root, "c"): []os.FileInfo{
&FileInfo{name: "d" + fExt, size: int64(len(dFile))},
},
}
readDir := func(s string) ([]os.FileInfo, error) { return infos[s], nil }
open := func(s string) (io.ReadWriteCloser, error) { return files[s], nil }
create := func(s string) (io.ReadWriteCloser, error) { return files[s], nil }
err := convertDir(root, readDir, open, create)
defect.Equal(t, err, nil)
defect.Equal(t, files[path.Join(root, "b"+fExt+goExt)].String(), header+bFile)
defect.Equal(t, files[path.Join(root, "c", "d"+fExt+goExt)].String(), header+dFile)
}
示例2: TestLexer_Token
func TestLexer_Token(t *testing.T) {
l := Lexer{Lexer: util.Lexer{
Reader: util.NewReader(`123 + 456
2 - 78
4569
a = 1 + 2 * (3 / 4 - b)`),
IsWhitespace: util.IsWhitespaceST,
}}
for _, expected := range []struct {
Token Token
Kind int
}{
{"123", NUM}, {"+", '+'}, {"456", NUM}, {"\n", '\n'},
{"2", NUM}, {"-", '-'}, {"78", NUM}, {"\n", '\n'},
{"4569", NUM}, {"\n", '\n'},
{"a", VAR}, {"=", '='}, {"1", NUM}, {"+", '+'}, {"2", NUM},
{"*", '*'}, {"(", '('}, {"3", NUM}, {"/", '/'},
{"4", NUM}, {"-", '-'}, {"b", VAR}, {")", ')'},
} {
token, kind, err := l.Token()
defect.Equal(t, err, nil)
defect.Equal(t, kind, expected.Kind)
defect.Equal(t, token, expected.Token)
}
}
示例3: TestIsWhitespaceSTNL
func TestIsWhitespaceSTNL(t *testing.T) {
l := Lexer{
Reader: NewReader("1 2\t3\n4"),
IsWhitespace: IsWhitespaceSTNL,
}
for _, expected := range []rune{'1', '2', '3', '4', EOF} {
r, err := l.Scan()
defect.Equal(t, err, nil)
defect.Equal(t, r, expected)
}
}
示例4: TestLexer_Scan
func TestLexer_Scan(t *testing.T) {
l := Lexer{
Reader: NewReader("1 + 2"),
IsWhitespace: IsWhitespaceST,
}
for _, expected := range []rune{'1', '+', '2', EOF} {
r, err := l.Scan()
defect.Equal(t, err, nil)
defect.Equal(t, r, expected)
}
}
示例5: TestParseDancer
func TestParseDancer(t *testing.T) {
dancer := &Dancer{}
err := dancer.Parse([]string{})
defect.Equal(t, err, ErrWrongNumFields)
err = dancer.Parse([]string{"12132", "Cohen", "Miles"})
defect.Equal(t, err, nil)
defect.Equal(t, *dancer, Dancer{
Number: 12132,
First: "Miles",
Last: "Cohen",
})
}
示例6: TestConvert
func TestConvert(t *testing.T) {
fn := func(buffSize int, s string) {
out := strings.NewReader(s)
in := &bytes.Buffer{}
err := convert(out, in, buffSize)
defect.Equal(t, err, nil)
defect.Equal(t, string(in.Bytes()), header+s)
}
fn(4, "foo") // 1 pass
fn(3, "baz") // exact
fn(2, "bar") // 2 passes
}
示例7: TestReadRune
func TestReadRune(t *testing.T) {
r := NewReader("foo")
fn := func(expected rune) {
rn, err := readRune(r)
defect.Equal(t, err, nil)
defect.Equal(t, rn, expected)
}
fn('f')
fn('o')
fn('o')
fn(EOF)
}
示例8: TestParseCompetition
func TestParseCompetition(t *testing.T) {
comp := &Competition{}
err := comp.Parse([]string{})
defect.Equal(t, err, ErrWrongNumFields)
err = comp.Parse([]string{"56", "Easter Swing", "Bellevue, WA", "Apr 2015"})
defect.Equal(t, err, nil)
defect.Equal(t, *comp, Competition{
Number: 56,
Name: "Easter Swing",
Location: "Bellevue, WA",
Date: time.Date(2015, 4, 1, 0, 0, 0, 0, time.UTC),
})
}
示例9: TestScanner_Scan
func TestScanner_Scan(t *testing.T) {
s := Scanner{}
expected := map[string][]token.Token{
`package main
`: {token.PACKAGE, token.IDENT, token.SEMICOLON},
`package main
import "fmt"
func main(){
fmt.Println("hello world")
}
`: {token.PACKAGE, token.IDENT, token.SEMICOLON,
token.IMPORT, token.STRING, token.SEMICOLON,
token.FUNC, token.IDENT, token.LPAREN, token.RPAREN, token.LBRACE,
token.IDENT, token.PERIOD, token.IDENT, token.LPAREN, token.STRING, token.RPAREN, token.SEMICOLON,
token.RBRACE, token.SEMICOLON},
}
for text, symbols := range expected {
s.Init([]byte(text))
i := 0
_, tok, _ := s.Scan()
for tok != token.EOF {
defect.Equal(t, tok, symbols[i])
_, tok, _ = s.Scan()
i++
}
}
}
示例10: TestLexer
func TestLexer(t *testing.T) {
l := Lexer{Lexer: util.Lexer{Reader: util.NewReader("12")}}
fn := func(get func() (rune, error), expected rune) {
r, err := get()
defect.Equal(t, err, nil)
defect.Equal(t, r, expected)
}
fn(l.Peek, '1')
fn(l.Peek, '1')
fn(l.Next, '1')
fn(l.Peek, '2')
fn(l.Next, '2')
fn(l.Peek, util.EOF)
fn(l.Next, util.EOF)
}
示例11: TestIsFenec
func TestIsFenec(t *testing.T) {
tests := map[string]bool{
"foo": false,
"foo" + goExt: false,
"foo" + fExt: true,
"foo" + fExt + goExt: false,
}
for k, v := range tests {
defect.Equal(t, IsFenec(k), v)
}
}
示例12: TestEmptyGenerics_literals
func TestEmptyGenerics_literals(t *testing.T) {
src := []string{
"struct{}{}", // empty struct
"struct[]{}{}", // empty generic struct
"func(){}", // empty function
"func[](){}", // empty generic function
}
for _, s := range src {
_, err := ParseExpr(s)
defect.Equal(t, err, nil)
}
}
示例13: TestLexer_PeekAndScan
func TestLexer_PeekAndScan(t *testing.T) {
fn := func(get func() (rune, error), expected rune) {
r, err := get()
defect.Equal(t, err, nil)
defect.Equal(t, r, expected)
}
// empty
l := Lexer{Reader: NewReader("")}
fn(l.Peek, EOF)
fn(l.Next, EOF)
// basic
l = Lexer{Reader: NewReader("12")}
fn(l.Peek, '1')
fn(l.Peek, '1')
fn(l.Next, '1')
fn(l.Peek, '2')
fn(l.Next, '2')
fn(l.Peek, EOF)
fn(l.Next, EOF)
}
示例14: TestScanner_Peek
func TestScanner_Peek(t *testing.T) {
s := Scanner{}
s.Init([]byte(`package main
func main(){}
`))
expected := []token.Token{
token.PACKAGE, token.IDENT, token.SEMICOLON,
token.FUNC, token.IDENT, token.LPAREN, token.RPAREN, token.LBRACE, token.RBRACE, token.SEMICOLON,
}
for _, e := range expected {
_, tok, _ := s.Peek()
defect.Equal(t, tok, e)
s.Scan()
}
}
示例15: TestInDir
func TestInDir(t *testing.T) {
readDir := func(string) ([]os.FileInfo, error) {
return []os.FileInfo{
&FileInfo{name: "foo" + goExt, size: 12, isDir: false},
&FileInfo{name: "bar" + fExt, size: int64(len(basicFile)), isDir: false},
&FileInfo{name: "baz", size: 0, isDir: true},
&FileInfo{name: "quux" + fExt, size: 0, isDir: true},
}, nil
}
p := path.Join("foo", "bar", "baz")
files, dirs, err := inDir(p, readDir)
defect.Equal(t, err, nil)
defect.DeepEqual(t, files, []string{path.Join(p, "bar"+fExt)})
defect.DeepEqual(t, dirs, []string{
path.Join(p, "baz"),
path.Join(p, "quux"+fExt),
})
}