github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/isc/test/string_test.go (about) 1 package test 2 3 import ( 4 "testing" 5 6 "github.com/go-playground/assert/v2" 7 "github.com/isyscore/isc-gobase/isc" 8 ) 9 10 func TestString(t *testing.T) { 11 var s isc.ISCString = "abcdefg" 12 ss := s.Insert(3, "xyz") 13 // ss := s.SubStringAfterLast(",") 14 t.Logf("%v\n", ss) // abcxyzdefg 15 16 sss := ss.Delete(3, 3) 17 t.Logf("%v\n", sss) // abcdefg 18 19 } 20 21 func TestStringConvert(t *testing.T) { 22 originalStr := "dataBaseUser" 23 newStr := isc.BigCamel(originalStr) 24 assert.Equal(t, "DataBaseUser", newStr) 25 } 26 27 func TestMiddleLine(t *testing.T) { 28 originalStr := "dataBaseUser" 29 newStr := isc.MiddleLine(originalStr) 30 assert.Equal(t, "data-base-user", newStr) 31 } 32 33 func TestBigCamelToMiddleLine(t *testing.T) { 34 originalStr := "DataBaseUser" 35 newStr := isc.BigCamelToMiddleLine(originalStr) 36 assert.Equal(t, "data-base-user", newStr) 37 } 38 39 func TestBigCamelToSmallCamel(t *testing.T) { 40 originalStr := "DataBaseUser" 41 newStr := isc.BigCamelToSmallCamel(originalStr) 42 assert.Equal(t, "dataBaseUser", newStr) 43 } 44 45 func TestBigCamelToPostUnder(t *testing.T) { 46 originalStr := "DataBaseUser" 47 newStr := isc.BigCamelToPostUnder(originalStr) 48 assert.Equal(t, "data_base_user_", newStr) 49 } 50 51 func TestPostUnder(t *testing.T) { 52 originalStr := "dataBaseUser" 53 newStr := isc.PostUnder(originalStr) 54 assert.Equal(t, "data_base_user_", newStr) 55 } 56 57 func TestPrePostUnder(t *testing.T) { 58 originalStr := "dataBaseUser" 59 newStr := isc.PrePostUnder(originalStr) 60 assert.Equal(t, "_data_base_user_", newStr) 61 } 62 63 func TestBigCamelToPrePostUnder(t *testing.T) { 64 originalStr := "DataBaseUser" 65 newStr := isc.BigCamelToPrePostUnder(originalStr) 66 assert.Equal(t, "_data_base_user_", newStr) 67 } 68 69 func TestPreUnder(t *testing.T) { 70 originalStr := "dataBaseUser" 71 newStr := isc.PreUnder(originalStr) 72 assert.Equal(t, "_data_base_user", newStr) 73 } 74 75 func TestBigCamelToPreUnder(t *testing.T) { 76 originalStr := "DataBaseUser" 77 newStr := isc.BigCamelToPreUnder(originalStr) 78 assert.Equal(t, "_data_base_user", newStr) 79 } 80 81 func TestBigCamelToUnderLine(t *testing.T) { 82 originalStr := "DataBaseUser" 83 newStr := isc.BigCamelToUnderLine(originalStr) 84 assert.Equal(t, "data_base_user", newStr) 85 } 86 87 func TestBigCamelToUpperMiddle(t *testing.T) { 88 originalStr := "DataBaseUser" 89 newStr := isc.BigCamelToUpperMiddle(originalStr) 90 assert.Equal(t, "DATA-BASE-USER", newStr) 91 } 92 93 func TestUpperUnderMiddle(t *testing.T) { 94 originalStr := "dataBaseUser" 95 newStr := isc.UpperUnderMiddle(originalStr) 96 assert.Equal(t, "DATA-BASE-USER", newStr) 97 } 98 99 func TestUpperUnder(t *testing.T) { 100 originalStr := "dataBaseUser" 101 newStr := isc.UpperUnder(originalStr) 102 assert.Equal(t, "DATA_BASE_USER", newStr) 103 } 104 105 func TestBigCamelToUpperUnder(t *testing.T) { 106 originalStr := "DataBaseUser" 107 newStr := isc.BigCamelToUpperUnder(originalStr) 108 assert.Equal(t, "DATA_BASE_USER", newStr) 109 } 110 111 func TestMiddleLineToSmallCamel(t *testing.T) { 112 originalStr := "data-base-user" 113 newStr := isc.MiddleLineToSmallCamel(originalStr) 114 assert.Equal(t, "dataBaseUser", newStr) 115 } 116 117 func TestMiddleLineToBigCamel(t *testing.T) { 118 originalStr := "data-base-user" 119 newStr := isc.MiddleLineToBigCamel(originalStr) 120 assert.Equal(t, "DataBaseUser", newStr) 121 } 122 123 func TestPreFixUnderLine(t *testing.T) { 124 originalStr := "dataBaseUser" 125 newStr := isc.PreFixUnderLine(originalStr, "pre_") 126 assert.Equal(t, "pre_data_base_user", newStr) 127 } 128 129 func TestUnderLineToSmallCamel(t *testing.T) { 130 originalStr1 := "data_base_user" 131 newStr1 := isc.UnderLineToSmallCamel(originalStr1) 132 assert.Equal(t, "dataBaseUser", newStr1) 133 134 originalStr2 := "_data_base_user" 135 newStr2 := isc.UnderLineToSmallCamel(originalStr2) 136 assert.Equal(t, "dataBaseUser", newStr2) 137 138 originalStr3 := "data_base_user_" 139 newStr3 := isc.UnderLineToSmallCamel(originalStr3) 140 assert.Equal(t, "dataBaseUser", newStr3) 141 } 142 143 func TestPreFixUnderToSmallCamel(t *testing.T) { 144 originalStr := "pre_data_base_user" 145 newStr := isc.PreFixUnderToSmallCamel(originalStr, "pre_") 146 assert.Equal(t, "dataBaseUser", newStr) 147 } 148 149 func TestUnderLineToBigCamel(t *testing.T) { 150 originalStr1 := "data_base_user" 151 newStr1 := isc.UnderLineToBigCamel(originalStr1) 152 assert.Equal(t, "DataBaseUser", newStr1) 153 154 originalStr2 := "_data_base_user" 155 newStr2 := isc.UnderLineToBigCamel(originalStr2) 156 assert.Equal(t, "DataBaseUser", newStr2) 157 158 originalStr3 := "_data_base_user_" 159 newStr3 := isc.UnderLineToBigCamel(originalStr3) 160 assert.Equal(t, "DataBaseUser", newStr3) 161 162 originalStr4 := "data_base_user_" 163 newStr4 := isc.UnderLineToBigCamel(originalStr4) 164 assert.Equal(t, "DataBaseUser", newStr4) 165 } 166 167 func TestUpperUnderMiddleToSmallCamel(t *testing.T) { 168 originalStr := "DATA-BASE-USER" 169 newStr := isc.UpperUnderMiddleToSmallCamel(originalStr) 170 assert.Equal(t, "dataBaseUser", newStr) 171 } 172 173 func TestUpperUnderToSmallCamel(t *testing.T) { 174 originalStr := "DATA_BASE_USER" 175 newStr := isc.UpperUnderToSmallCamel(originalStr) 176 assert.Equal(t, "dataBaseUser", newStr) 177 } 178 179 func TestUpperUnderToBigCamel(t *testing.T) { 180 originalStr := "DATA_BASE_USER" 181 newStr := isc.UpperUnderToBigCamel(originalStr) 182 assert.Equal(t, "DataBaseUser", newStr) 183 } 184 185 func TestUpperMiddleToBigCamel(t *testing.T) { 186 originalStr := "DATA-BASE-USER" 187 newStr := isc.UpperMiddleToBigCamel(originalStr) 188 assert.Equal(t, "DataBaseUser", newStr) 189 }