func TestGetCellValue(t *testing.T) { mtest.RegTest(t) fn := "testdata/demo.xlsx" in := GetCellValue(fn, "Sheet1", "A1", "") //println(in) mtest.AssertEqual(in, "ID") }
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") }
func TestXXX(t *testing.T) { m := Model{} m.Id = "1" m.Email = "*****@*****.**" mtest.RegTest(t) mtest.AssertEqual(true, true) PrintValidate(m) }
func TestArgsA(t *testing.T) { mtest.RegTest(t) s := "-d -f=demo.txt Hello Demo" a := NewArgsFromString(s) mtest.Equal(4, a.NArgs()) }
func TestStrBuffer(t *testing.T) { mtest.RegTest(t) sb := NewStringBuffer() sb.Append("Hello") mtest.Equal("Hello", sb.String()) }
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/abc@def").SepEnd("@")) mtest.AssertEqual("", String("/aaa/abc@def").SepEnd("#")) }
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) }
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) }
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) }
func TestIsMapHasKey(t *testing.T) { mtest.RegTest(t) InitMap() mtest.AssertTrue(IsMapHasKey(m, "a")) mtest.AssertTrue(!IsMapHasKey(m, "none")) }
func TestTrimEndIndex(t *testing.T) { mtest.RegTest(t) mtest.AssertEqual(String("/a/b/c.txt").TrimEndIndex("/"), "/a/b") }
func TestGetFields(t *testing.T) { mtest.RegTest(t) mtest.AssertTrue(true) }
func TestIsHasMethod(t *testing.T) { mtest.RegTest(t) mtest.AssertTrue(IsHasMethod(demo, "Hello")) mtest.AssertFalse(IsHasMethod(demo, "None")) }
func TestUpper(t *testing.T) { mtest.RegTest(t) }
func TestPlainEncode(t *testing.T) { mtest.RegTest(t) mtest.AssertEqual(plain.Encode("demo"), "demo") }
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) }
// DemoDemo > demo_demo func TestToTableName(t *testing.T) { mtest.RegTest(t) mtest.AssertEqual("demo_demo", ToTableName("DemoDemo")) }
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")) }
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") }
func TestWriteLines(t *testing.T) { mtest.RegTest(t) lines := []string{"line 1", "line 2", "line 3"} WriteLines(os.Stdout, lines) }
func TestWriteStrings(t *testing.T) { mtest.RegTest(t) WriteStrings(os.Stdout, "hello,", "demo write strings.") }
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") }
func TestTrimBeginIndex(t *testing.T) { mtest.RegTest(t) mtest.AssertEqual(String("a/b/c.txt").TrimBeginIndex("/"), "b/c.txt") }
func TestAppConf(t *testing.T) { mtest.RegTest(t) mtest.AssertEqual(false, NewDefaultAppConf("none").IsExist()) mtest.AssertEqual(dbcConf.GetVendorName(), "Mabetle") }
func TestIsContain(t *testing.T) { mtest.RegTest(t) mtest.AssertEqual(true, skv.IsContain("a")) mtest.AssertEqual(true, skv.GetBool("c")) }
func TestToCamel(t *testing.T) { mtest.RegTest(t) mtest.AssertEqual("DemoDemo", ToCamel("demo_demo")) }