github.com/mailru/activerecord@v1.12.2/pkg/iproto/util/text/text_test.go (about) 1 package text 2 3 import ( 4 "testing" 5 ) 6 7 func TestSplit2(t *testing.T) { 8 for i, test := range []struct { 9 In, L, R string 10 }{ 11 {"blabla,qqq", "blabla", "qqq"}, 12 13 {"", "", ""}, 14 {",", "", ""}, 15 16 {"blabla", "blabla", ""}, 17 {"blabla,", "blabla", ""}, 18 {",blabla", "", "blabla"}, 19 } { 20 l, r := Split2(test.In, ',') 21 if l != test.L || r != test.R { 22 t.Errorf("[%v] Split(%v) = %v, %v; want %v, %v", i, test.In, l, r, test.L, test.R) 23 } 24 } 25 26 } 27 28 func TestCamelToSnake(t *testing.T) { 29 for i, test := range []struct { 30 In, Out string 31 }{ 32 {"", ""}, 33 {"A", "a"}, 34 {"SimpleExample", "simple_example"}, 35 {"internalField", "internal_field"}, 36 37 {"SomeHTTPStuff", "some_http_stuff"}, 38 {"WriteJSON", "write_json"}, 39 {"HTTP2Server", "http2_server"}, 40 {"Some_Mixed_Case", "some_mixed_case"}, 41 {"do_nothing", "do_nothing"}, 42 43 {"JSONHTTPRPCServer", "jsonhttprpc_server"}, // nothing can be done here without a dictionary 44 } { 45 got := ToSnakeCase(test.In) 46 if got != test.Out { 47 t.Errorf("[%d] camelToSnake(%s) = %s; want %s", i, test.In, got, test.Out) 48 } 49 } 50 }