示例#1
0
func TestGetCellValue(t *testing.T) {
	mtest.RegTest(t)
	fn := "testdata/demo.xlsx"
	in := GetCellValue(fn, "Sheet1", "A1", "")
	//println(in)
	mtest.AssertEqual(in, "ID")
}
示例#2
0
func TestStringValidator(t *testing.T) {
	mtest.RegTest(t)

	//test email
	mtest.Equal(String("*****@*****.**").IsEmail(), true, "[email protected] is a email")
	mtest.Equal(String("demo.com").IsEmail(), false, "demo.com is not a email")

	//test english
	mtest.Equal(String("你好").IsChinese(), true, "你好 is no Engllish")
	mtest.Equal(String("Hello").IsEnglish(), true, "Hello is English")

	//test chinese
	mtest.Equal(String("你好").IsChinese(), true, "你好 is Chinese")
	mtest.Equal(String("Hello").IsEnglish(), true, "Hello is not Chinese")

	//test Idcard
	mtest.Equal(String("110110198801018721").IsIdCardNo(), true, "Is a IdCard number")
	mtest.Equal(String("hello").IsIdCardNo(), false, "Not a IdCard number")

	//test Phone number
	mtest.Equal(String("13900910001").IsPhoneNumber(), true, "Is a phone number")
	mtest.Equal(String("139sss00910001").IsPhoneNumber(), false, "Not a phone number")

	mtest.Equal(String("asdf").IsNumber(), false, "not a number")
	mtest.Equal(String("1012,312.12").IsNumber(), true, "not a number")

}
示例#3
0
func TestXXX(t *testing.T) {
	m := Model{}
	m.Id = "1"
	m.Email = "*****@*****.**"
	mtest.RegTest(t)
	mtest.AssertEqual(true, true)
	PrintValidate(m)
}
示例#4
0
func TestArgsA(t *testing.T) {
	mtest.RegTest(t)

	s := "-d -f=demo.txt Hello Demo"
	a := NewArgsFromString(s)

	mtest.Equal(4, a.NArgs())
}
示例#5
0
func TestStrBuffer(t *testing.T) {
	mtest.RegTest(t)

	sb := NewStringBuffer()
	sb.Append("Hello")

	mtest.Equal("Hello", sb.String())
}
示例#6
0
func TestSepEnd(t *testing.T) {
	mtest.RegTest(t)
	mtest.AssertEqual("def", String("/aaa/abc.def").SepEnd("."))
	mtest.AssertEqual("def", String("/aaa/abc/def").SepEnd("/"))
	mtest.AssertEqual("def", String("/aaa/abc\\def").SepEnd("\\"))
	mtest.AssertEqual("def", String("/aaa/[email protected]").SepEnd("@"))
	mtest.AssertEqual("", String("/aaa/[email protected]").SepEnd("#"))
}
示例#7
0
func TestKeyValueConfig(t *testing.T) {
	mtest.RegTest(t)
	c := NewConfig(&TestLoader{})

	mtest.AssertEqual(true, c.IsContain("a"))
	mtest.AssertEqual("a", c.GetString("a"))
	mtest.AssertEqual(false, c.GetBool("b"))
	mtest.AssertEqual(c.GetInt("c"), 5)
}
示例#8
0
func TestReadConfigFromString(t *testing.T) {
	mtest.RegTest(t)

	s := `
hello=hello from string
name=demo
	`
	c, err := ReadConfigFromString(s)
	mcore.CheckError(err)

	v, _ := c.String("", "hello")
	mtest.Equal("hello from string", v)
}
示例#9
0
func TestRound(t *testing.T) {
	mtest.RegTest(t)
	mtest.AssertTrue(RoundInt(3.14159) == 3)
	mtest.AssertTrue(RoundInt(3.54159) == 4)

	mtest.AssertTrue(Round(3.54159, 1) == 3.5)
	mtest.AssertTrue(Round(3.54159, 2) == 3.54)
	mtest.AssertTrue(Round(3.54159, 3) == 3.542)
	mtest.AssertTrue(Round(13.54159, -1) == 10)

	mtest.AssertTrue(RoundUp(3.54159, 1) == 3.6)
	mtest.AssertTrue(RoundUp(3.54159, 2) == 3.55)
	mtest.AssertTrue(RoundUp(3.54159, 3) == 3.542)
	mtest.AssertTrue(RoundUp(13.54159, -1) == 20)

	mtest.AssertTrue(RoundDown(3.54159, 1) == 3.5)
	mtest.AssertTrue(RoundDown(3.54159, 2) == 3.54)
	mtest.AssertTrue(RoundDown(3.54159, 3) == 3.541)
	mtest.AssertTrue(RoundDown(13.54159, -1) == 10)

}
示例#10
0
func TestIsMapHasKey(t *testing.T) {
	mtest.RegTest(t)
	InitMap()
	mtest.AssertTrue(IsMapHasKey(m, "a"))
	mtest.AssertTrue(!IsMapHasKey(m, "none"))
}
示例#11
0
func TestTrimEndIndex(t *testing.T) {
	mtest.RegTest(t)

	mtest.AssertEqual(String("/a/b/c.txt").TrimEndIndex("/"), "/a/b")
}
示例#12
0
func TestGetFields(t *testing.T) {
	mtest.RegTest(t)
	mtest.AssertTrue(true)
}
示例#13
0
func TestIsHasMethod(t *testing.T) {
	mtest.RegTest(t)
	mtest.AssertTrue(IsHasMethod(demo, "Hello"))
	mtest.AssertFalse(IsHasMethod(demo, "None"))
}
示例#14
0
func TestUpper(t *testing.T) {
	mtest.RegTest(t)
}
示例#15
0
func TestPlainEncode(t *testing.T) {
	mtest.RegTest(t)
	mtest.AssertEqual(plain.Encode("demo"), "demo")
}
示例#16
0
func TestGetLetterIndex(t *testing.T) {
	mtest.RegTest(t)
	mtest.AssertEqual(GetLetterIndex("a"), 0)
	mtest.AssertEqual(GetLetterIndex("aa"), 26)
	mtest.AssertEqual(GetLetterIndex("zz"), 25+26*26)
}
示例#17
0
// DemoDemo  > demo_demo
func TestToTableName(t *testing.T) {
	mtest.RegTest(t)
	mtest.AssertEqual("demo_demo", ToTableName("DemoDemo"))
}
示例#18
0
func TestGetLocation(t *testing.T) {
	mtest.RegTest(t)
	mtest.AssertEqual("abc/def.go", GetLocation("abc", "def.go"))
	mtest.AssertEqual("abc/def.go", GetLocation("abc/", "def.go"))
}
示例#19
0
func TestGetRowColIndex(t *testing.T) {
	mtest.RegTest(t)
	row, col := GetRowColIndex("AA23")
	mtest.AssertEqual(col, 26, "AA23 row should be 26")
	mtest.AssertEqual(row, 22, "AA23 col should be 22")
}
示例#20
0
func TestWriteLines(t *testing.T) {
	mtest.RegTest(t)
	lines := []string{"line 1", "line 2", "line 3"}
	WriteLines(os.Stdout, lines)
}
示例#21
0
func TestWriteStrings(t *testing.T) {
	mtest.RegTest(t)
	WriteStrings(os.Stdout, "hello,", "demo write strings.")
}
示例#22
0
func TestWriteText(t *testing.T) {
	mtest.RegTest(t)
	WriteText(os.Stdout, "test write to os.Stdout\n")
	WriteText(os.Stderr, "test write to os.Stderr\n")
}
示例#23
0
func TestTrimBeginIndex(t *testing.T) {
	mtest.RegTest(t)

	mtest.AssertEqual(String("a/b/c.txt").TrimBeginIndex("/"), "b/c.txt")
}
示例#24
0
func TestAppConf(t *testing.T) {
	mtest.RegTest(t)
	mtest.AssertEqual(false, NewDefaultAppConf("none").IsExist())
	mtest.AssertEqual(dbcConf.GetVendorName(), "Mabetle")
}
示例#25
0
func TestIsContain(t *testing.T) {
	mtest.RegTest(t)
	mtest.AssertEqual(true, skv.IsContain("a"))
	mtest.AssertEqual(true, skv.GetBool("c"))
}
示例#26
0
func TestToCamel(t *testing.T) {
	mtest.RegTest(t)
	mtest.AssertEqual("DemoDemo", ToCamel("demo_demo"))
}