代码拉取完成,页面将自动刷新
package lua
import (
"fmt"
"path/filepath"
"regexp"
"runtime"
"testing"
)
func positionString(level int) string {
_, file, line, _ := runtime.Caller(level + 1)
return fmt.Sprintf("%v:%v:", filepath.Base(file), line)
}
func errorIfNotEqual(t *testing.T, v1, v2 interface{}) {
if v1 != v2 {
t.Errorf("%v '%v' expected, but got '%v'", positionString(1), v1, v2)
}
}
func errorIfFalse(t *testing.T, cond bool, msg string, args ...interface{}) {
if !cond {
if len(args) > 0 {
t.Errorf("%v %v", positionString(1), fmt.Sprintf(msg, args...))
} else {
t.Errorf("%v %v", positionString(1), msg)
}
}
}
func errorIfNotNil(t *testing.T, v1 interface{}) {
if fmt.Sprint(v1) != "<nil>" {
t.Errorf("%v nil expected, but got '%v'", positionString(1), v1)
}
}
func errorIfNil(t *testing.T, v1 interface{}) {
if fmt.Sprint(v1) == "<nil>" {
t.Errorf("%v non-nil value expected, but got nil", positionString(1))
}
}
func errorIfScriptFail(t *testing.T, L *LState, script string) {
if err := L.DoString(script); err != nil {
t.Errorf("%v %v", positionString(1), err.Error())
}
}
func errorIfGFuncFail(t *testing.T, L *LState, f LGFunction) {
if err := L.GPCall(f, LNil); err != nil {
t.Errorf("%v %v", positionString(1), err.Error())
}
}
func errorIfScriptNotFail(t *testing.T, L *LState, script string, pattern string) {
if err := L.DoString(script); err != nil {
reg := regexp.MustCompile(pattern)
if len(reg.FindStringIndex(err.Error())) == 0 {
t.Errorf("%v error message '%v' does not contains given pattern string '%v'.", positionString(1), err.Error(), pattern)
return
}
return
}
t.Errorf("%v script should fail", positionString(1))
}
func errorIfGFuncNotFail(t *testing.T, L *LState, f LGFunction, pattern string) {
if err := L.GPCall(f, LNil); err != nil {
reg := regexp.MustCompile(pattern)
if len(reg.FindStringIndex(err.Error())) == 0 {
t.Errorf("%v error message '%v' does not contains given pattern string '%v'.", positionString(1), err.Error(), pattern)
return
}
return
}
t.Errorf("%v LGFunction should fail", positionString(1))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。