本文整理汇总了Golang中github.com/reflexionhealth/vanilla/expect.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestComparisons
func TestComparisons(t *testing.T) {
examples := []struct {
A, B Version
Lt, Lte bool
Gt, Gte bool
}{
// TODO: Constraint based testing (ie. https://golang.org/pkg/testing/quick)
{Version{0, 0, 0}, Version{0, 0, 0}, false, true, false, true},
{Version{0, 0, 1}, Version{0, 0, 0}, false, false, true, true},
{Version{0, 1, 0}, Version{0, 0, 0}, false, false, true, true},
{Version{1, 0, 0}, Version{0, 0, 0}, false, false, true, true},
{Version{0, 0, 0}, Version{1, 0, 0}, true, true, false, false},
{Version{0, 0, 1}, Version{1, 0, 0}, true, true, false, false},
{Version{0, 1, 0}, Version{1, 0, 0}, true, true, false, false},
{Version{1, 0, 0}, Version{1, 0, 0}, false, true, false, true},
{Version{1, 2, 3}, Version{3, 2, 1}, true, true, false, false},
{Version{0, 3, 1}, Version{0, 1, 3}, false, false, true, true},
{Version{1, 1, 4}, Version{1, 1, 6}, true, true, false, false},
}
for _, ex := range examples {
expect.Equal(t, ex.A.LessThan(ex.B), ex.Lt, ex.A.String()+" < "+ex.B.String())
expect.Equal(t, ex.A.GreaterThan(ex.B), ex.Gt, ex.A.String()+" > "+ex.B.String())
expect.Equal(t, ex.A.AtMost(ex.B), ex.Lte, ex.A.String()+" <= "+ex.B.String())
expect.Equal(t, ex.A.AtLeast(ex.B), ex.Gte, ex.A.String()+" >= "+ex.B.String())
}
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:28,代码来源:version_test.go
示例2: TestUnmarshalJSON
func TestUnmarshalJSON(t *testing.T) {
examples := []struct {
Json string
Version Version
}{
{`"5.0.0"`, Version{5, 0, 0}},
{`"v2.4.12"`, Version{2, 4, 12}},
{`"3.5.0ab"`, Version{3, 5, 0}},
{`"8.22"`, Version{8, 22, 0}},
}
var v Version
for _, ex := range examples {
err := json.Unmarshal([]byte(ex.Json), &v)
expect.Nil(t, err, ex.Json)
expect.Equal(t, v, ex.Version, ex.Json)
}
badExamples := []struct {
Json string
Error string
}{
{`null`, "semver: cannot parse version from non-string JSON value"},
{`""`, "semver: json string is not a valid version"},
{`"bogus"`, "semver: json string is not a valid version"},
}
for _, ex := range badExamples {
err := json.Unmarshal([]byte(ex.Json), &v)
if expect.NotNil(t, err, ex.Json) {
expect.Equal(t, err.Error(), ex.Error, ex.Json)
}
}
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:34,代码来源:version_test.go
示例3: TestLookup
func TestLookup(t *testing.T) {
// an arbitrary string
expect.Equal(t, Lookup("something"), IDENT)
// all keyword tokens and no non-keyword tokens
for i, name := range tokens {
if len(name) > 0 {
tok := Token(i)
if tok.IsKeyword() {
expect.Equal(t, Lookup(name), tok)
} else {
expect.Equal(t, Lookup(name), IDENT)
}
}
}
// case-insensitive
expect.Equal(t, Lookup("SELECT"), SELECT)
expect.Equal(t, Lookup("Select"), SELECT)
expect.Equal(t, Lookup("select"), SELECT)
expect.Equal(t, Lookup("sElECt"), SELECT)
expect.Equal(t, Lookup("selecT"), SELECT)
expect.Equal(t, Lookup("WHERE"), WHERE)
expect.Equal(t, Lookup("where"), WHERE)
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:25,代码来源:token_test.go
示例4: TestScanNullTime
func TestScanNullTime(t *testing.T) {
var rawTime = time.Now()
var mysqlTime = "2010-07-03 13:24:33"
var byteTime = []byte(mysqlTime)
var notTime = 3
var n Time
var err error
err = n.Scan(rawTime)
expect.Nil(t, err)
expect.True(t, n.Valid)
expect.NotEmpty(t, n.Time.Format("2006-01-02 15:04:05"))
err = n.Scan(mysqlTime)
expect.Nil(t, err)
expect.True(t, n.Valid)
expect.Equal(t, n.Time.Format("2006-01-02 15:04:05"), mysqlTime)
err = n.Scan(byteTime)
expect.Nil(t, err)
expect.True(t, n.Valid)
expect.Equal(t, n.Time.Format("2006-01-02 15:04:05"), mysqlTime)
err = n.Scan(notTime)
expect.NotNil(t, err)
expect.False(t, n.Valid)
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:27,代码来源:null_test.go
示例5: TestUnmarshalNullDate
func TestUnmarshalNullDate(t *testing.T) {
var jsonNull string = `null`
var jsonEmpty string = `""`
var stringDate string = `"2010-07-03"`
var stringTime string = `"2010-07-03T13:24:33"`
var stringBogus string = `"bogus"`
var n Date
var err error
err = json.Unmarshal([]byte(jsonNull), &n)
expect.Nil(t, err)
expect.False(t, n.Valid)
err = json.Unmarshal([]byte(jsonEmpty), &n)
expect.Nil(t, err)
expect.False(t, n.Valid)
err = json.Unmarshal([]byte(stringDate), &n)
expect.Nil(t, err)
expect.True(t, n.Valid)
expect.Equal(t, n.Date.Year, 2010)
expect.Equal(t, n.Date.Month, time.July)
expect.Equal(t, n.Date.Day, 3)
err = json.Unmarshal([]byte(stringTime), &n)
expect.NotNil(t, err)
expect.False(t, n.Valid)
err = json.Unmarshal([]byte(stringBogus), &n)
expect.NotNil(t, err)
expect.False(t, n.Valid)
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:32,代码来源:null_test.go
示例6: TestUnmarshalNullString
func TestUnmarshalNullString(t *testing.T) {
var jsonNull string = `null`
var jsonNumber string = `3`
var jsonEmpty string = `""`
var validString string = `"foo"`
var n String
var err error
err = json.Unmarshal([]byte(jsonNull), &n)
expect.Nil(t, err)
expect.False(t, n.Valid)
err = json.Unmarshal([]byte(jsonNumber), &n)
expect.NotNil(t, err)
expect.False(t, n.Valid)
err = json.Unmarshal([]byte(jsonEmpty), &n)
expect.Nil(t, err)
expect.True(t, n.Valid)
expect.Equal(t, n.String, "")
err = json.Unmarshal([]byte(validString), &n)
expect.Nil(t, err)
expect.True(t, n.Valid)
expect.Equal(t, n.String, "foo")
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:27,代码来源:null_test.go
示例7: TestSelect
func TestSelect(t *testing.T) {
query := `SELECT * FROM users WHERE id = 3`
failOnError := func(pos token.Position, msg string) {
t.Errorf("At Line %d, Col %d: %s", pos.Line, pos.Column, msg)
}
s := Scanner{}
s.Init([]byte(query), failOnError, Ruleset{})
var tokens []token.Token
MAX_ITER := 200 // Don't loop forever
for i := 0; i < MAX_ITER; i++ {
_, tok, _ := s.Scan()
tokens = append(tokens, tok)
if tok == token.INVALID || tok == token.EOS {
break
}
}
expect.Equal(t, s.ErrorCount, 0)
expect.Equal(t, tokens, []token.Token{
// SELECT * FROM users
token.SELECT, token.ASTERISK, token.FROM, token.IDENT,
// WHERE id = 3
token.WHERE, token.IDENT, token.EQUALS, token.NUMBER,
token.EOS,
})
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:29,代码来源:scanner_test.go
示例8: TestMarshalJSON
func TestMarshalJSON(t *testing.T) {
b1, err1 := json.Marshal(Version{1, 0, 0})
expect.Nil(t, err1)
expect.Equal(t, string(b1), `"1.0.0"`)
b2, err2 := json.Marshal(Version{2, 0, 30})
expect.Nil(t, err2)
expect.Equal(t, string(b2), `"2.0.30"`)
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:8,代码来源:version_test.go
示例9: TestErrorsRespectWhitespace
func TestErrorsRespectWhitespace(t *testing.T) {
scan, err := scanOnce("\n\n ~\n")
expect.Equal(t, token.INVALID, scan.tok)
if expect.NotNil(t, err) {
expect.Equal(t, err.pos.Offset, 6)
expect.Equal(t, err.pos.Line, 3)
expect.Equal(t, err.pos.Column, 5)
expect.Equal(t, err.msg, `unexpected character U+007E '~'`)
}
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:10,代码来源:scanner_test.go
示例10: TestPositionString
func TestPositionString(t *testing.T) {
var pos Position
pos = Position{"", 0, 0, 0}
expect.Equal(t, pos.String(), "-")
pos = Position{"Src", 0, 1, 1}
expect.Equal(t, pos.String(), "Src:1:1")
pos = Position{"Name", 15, 7, 16}
expect.Equal(t, pos.String(), "Name:7:16")
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:12,代码来源:token_test.go
示例11: TestScannerNextCharacter
func TestScannerNextCharacter(t *testing.T) {
var err *scanError
err = scanAll("SELECT * FROM candies\r\n WHERE sweetness = 11\n\r\r")
expect.Nil(t, err)
err = scanAll(string([]byte{0x00, 0xFF}))
if expect.NotNil(t, err) {
expect.Equal(t, err.pos.Offset, 0)
expect.Equal(t, err.pos.Line, 1)
expect.Equal(t, err.pos.Column, 1)
expect.Equal(t, err.msg, `unexpected character U+0000`)
}
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:14,代码来源:scanner_test.go
示例12: TestParseErrors
func TestParseErrors(t *testing.T) {
examples := []struct {
Input string
Error string
}{
{Input: `mytable`,
Error: `sql:1:8: expected 'SELECT, INSERT, or UPDATE' but received 'Identifier'`},
{Input: `SELECT * WHERE`,
Error: `sql:1:15: expected 'FROM' but received 'WHERE'`},
{Input: `SELECT * FROM *`,
Error: `sql:1:16: expected 'a table name' but received '*'`},
{Input: "SELECT `mycolumn` FROM mytable", // backticks (w/ ansi ruleset)
Error: "sql:1:8: unexpected character U+0060 '`'"},
{Input: `SELECT DISTINCTROW * FROM mytable`, // distinctrow (w/ ansi ruleset)
Error: `sql:1:19: statement includes SELECT "DISTINCTROW", but CanSelectDistinctRow is false`},
{Input: `~`,
Error: `sql:1:1: unexpected character U+007E '~'`},
{Input: `SELECT * FROM foos; SELECT * FROM bars;`,
Error: `sql:1:27: statement does not end at semicolon`},
{Input: `SELECT * FROM mytable PROCEDURE compute(foo)`, // with HasLiteral
Error: `sql:1:32: cannot parse statement; reached unimplemented clause at 'PROCEDURE'`},
{Input: `SELECT * FROM mytable +`, // without HasLiteral
Error: `sql:1:24: cannot parse statement; reached unimplemented clause at '+'`},
}
for _, example := range examples {
parser := New([]byte(example.Input), Ruleset{})
stmt, err := parser.ParseStatement()
expect.Nil(t, stmt)
if expect.NotNil(t, err, "expected a parsing error") {
expect.Equal(t, err.Error(), example.Error)
}
}
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:34,代码来源:parser_test.go
示例13: TestTraceParser
func TestTraceParser(t *testing.T) {
output := bytes.Buffer{}
parser := New([]byte(`SELECT * FROM table_with_long_name WHERE ♫`), Ruleset{})
parser.Trace = &output
stmt, err := parser.ParseStatement()
expect.NotNil(t, err, "expected a parsing error")
expect.Nil(t, stmt)
expected := []string{
regexp.QuoteMeta(` SELECT : SELECT @ Parser.parseSelect:`) + "[0-9]+",
regexp.QuoteMeta(` : * @ Parser.parseSelect:`) + "[0-9]+",
regexp.QuoteMeta(` FROM : FROM @ Parser.parseSelect:`) + "[0-9]+",
regexp.QuoteMeta(` table_~ : Identifier @ Parser.parseSelect:`) + "[0-9]+",
regexp.QuoteMeta(` WHERE : WHERE @ Parser.parseSelect:`) + "[0-9]+",
regexp.QuoteMeta(` (error) sql:1:42: unexpected character U+266B '♫'`),
"$", // string ends with newline
}
// compare trace output, ignoring the source line numbers
lines := strings.Split(output.String(), "\n")
if expect.Equal(t, len(lines), len(expected)) {
maxSafe := utils.MinInt(len(expected), len(lines))
for i := 0; i < maxSafe; i++ {
expect.Regexp(t, lines[i], "^"+expected[i])
}
} else {
t.Log("Error:", err)
t.Log("Full trace output:\n", output.String())
}
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:31,代码来源:parser_test.go
示例14: TestUnmarshalNullTime
func TestUnmarshalNullTime(t *testing.T) {
var jsonNull string = `null`
var jsonEmpty string = `""`
var stringTime string = `"2010-07-03T13:24:33Z"`
var stringBogus string = `"bogus"`
var n Time
var err error
err = json.Unmarshal([]byte(jsonNull), &n)
expect.Nil(t, err)
expect.False(t, n.Valid)
err = json.Unmarshal([]byte(jsonEmpty), &n)
expect.Nil(t, err)
expect.False(t, n.Valid)
err = json.Unmarshal([]byte(stringTime), &n)
expect.Nil(t, err)
expect.True(t, n.Valid)
expect.Equal(t, n.Time.Format("2006-01-02 15:04:05"), "2010-07-03 13:24:33")
err = json.Unmarshal([]byte(stringBogus), &n)
expect.NotNil(t, err)
expect.False(t, n.Valid)
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:25,代码来源:null_test.go
示例15: TestParseInsert
func TestParseInsert(t *testing.T) {
parser := New([]byte(`INSERT INTO mytable`), Ruleset{})
stmt, err := parser.ParseStatement()
expect.Nil(t, stmt)
if expect.NotNil(t, err) {
expect.Equal(t, err.Error(), `sql:1:20: cannot parse statement; reached unimplemented clause at 'mytable'`)
}
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:8,代码来源:parser_test.go
示例16: TestParseUpdate
func TestParseUpdate(t *testing.T) {
parser := New([]byte(`UPDATE mytable SET a = 1`), Ruleset{})
stmt, err := parser.ParseStatement()
expect.Nil(t, stmt)
if expect.NotNil(t, err) {
expect.Equal(t, err.Error(), `sql:1:15: cannot parse statement; reached unimplemented clause at 'mytable'`)
}
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:8,代码来源:parser_test.go
示例17: TestSqlParseError
func TestSqlParseError(t *testing.T) {
db, err := sql.Open("sqltest", "")
expect.Nil(t, err)
_, err = db.Query("SELECT * FROM")
expect.NotNil(t, err)
expect.Equal(t, err.Error(), "sql:1:14: expected 'a table name' but received 'End of statement'")
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:8,代码来源:driver_test.go
示例18: TestCreateTable
func TestCreateTable(t *testing.T) {
tbl := Table{
Name: "testers",
Columns: []Column{
{"name", "text", []string{"NOT NULL"}},
{"experience", "integer", []string{"DEFAULT 0"}},
{"pet_name", "text", nil},
},
}
var expected string
expected = `CREATE TABLE "testers" ("name" text NOT NULL, "experience" integer DEFAULT 0, "pet_name" text)`
expect.Equal(t, tbl.Create().Sql(), expected)
expected = `CREATE TABLE IF NOT EXISTS "testers" ("name" text NOT NULL, "experience" integer DEFAULT 0, "pet_name" text)`
expect.Equal(t, tbl.Create().IfNotExists().Sql(), expected)
expect.Equal(t, len(tbl.Create().Args()), 0)
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:18,代码来源:sql_test.go
示例19: TestSkipsWhitesace
func TestSkipsWhitesace(t *testing.T) {
scan, err := scanOnce("\n SELECT\n")
expect.Nil(t, err)
expect.Equal(t, scan.tok, token.SELECT)
expect.Equal(t, scan.pos, 5)
expect.Equal(t, scan.lit, "SELECT")
// scan, err = scanOnce("\n --comment\n SELECT--comment\n")
// expect.Nil(t, err)
// expect.Equal(t, scan.tok, token.SELECT)
// expect.Equal(t, scan.pos, 18)
// expect.Equal(t, scan.lit, "SELECT")
//
// scan, err = scanOnce("\n --comment\r\n SELECT--comment\n")
// expect.Nil(t, err)
// expect.Equal(t, scan.tok, token.SELECT)
// expect.Equal(t, scan.pos, 19)
// expect.Equal(t, scan.lit, "SELECT")
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:19,代码来源:scanner_test.go
示例20: TestReportsUsefulunknownCharacter
func TestReportsUsefulunknownCharacter(t *testing.T) {
scan, err := scanOnce("\u203B")
expect.Equal(t, scan.tok, token.INVALID)
if expect.NotNil(t, err) {
expect.Equal(t, err.pos.Offset, 0)
expect.Equal(t, err.pos.Line, 1)
expect.Equal(t, err.pos.Column, 1)
expect.Equal(t, err.msg, "unexpected character U+203B '\u203B'")
}
scan, err = scanOnce("\u200b")
expect.Equal(t, scan.tok, token.INVALID)
if expect.NotNil(t, err) {
expect.Equal(t, err.pos.Offset, 0)
expect.Equal(t, err.pos.Line, 1)
expect.Equal(t, err.pos.Column, 1)
expect.Equal(t, err.msg, `unexpected character U+200B`)
}
}
开发者ID:reflexionhealth,项目名称:vanilla,代码行数:19,代码来源:scanner_test.go
注:本文中的github.com/reflexionhealth/vanilla/expect.Equal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论