Пример #1
0
func TestStrBuffer(t *testing.T) {
	mtest.RegTest(t)

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

	mtest.Equal("Hello", sb.String())
}
Пример #2
0
func TestArgsA(t *testing.T) {
	mtest.RegTest(t)

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

	mtest.Equal(4, a.NArgs())
}
Пример #3
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)
}
Пример #4
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")

}