github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zvalid/format_test.go (about) 1 package zvalid 2 3 import ( 4 "testing" 5 6 "github.com/sohaha/zlsgo" 7 ) 8 9 func TestFormat(t *testing.T) { 10 tt := zlsgo.NewTest(t) 11 str := Text(" is test ").Trim().Value() 12 tt.Equal("is test", str) 13 14 str = Text(" is test ").RemoveSpace().Value() 15 tt.Equal("istest", str) 16 17 str = Text("is test is").Replace("is", "yes", 1).Value() 18 tt.Equal("yes test is", str) 19 20 str = Text("is test is").ReplaceAll("is", "yes").Value() 21 tt.Equal("yes test yes", str) 22 23 str = Text("is <script> alert(666); </script> js").XSSClean().Value() 24 tt.Equal("is js", str) 25 26 str = Text("hello_world").SnakeCaseToCamelCase(false).Value() 27 tt.Equal("helloWorld", str) 28 29 str = Text("hello_world").SnakeCaseToCamelCase(true).Value() 30 tt.Equal("HelloWorld", str) 31 32 str = Text("hello-world").SnakeCaseToCamelCase(true, "-").Value() 33 tt.Equal("HelloWorld", str) 34 35 str = Text("HelloWorld").CamelCaseToSnakeCase().Value() 36 tt.Equal("hello_world", str) 37 38 str = Text("helloWorld").CamelCaseToSnakeCase().Value() 39 tt.Equal("hello_world", str) 40 41 str = Text("helloWorld").CamelCaseToSnakeCase("-").Value() 42 tt.Equal("hello-world", str) 43 }