github.com/gop9/olt@v0.0.0-20200202132135-d956aad50b08/framework/strinsdel_test.go (about) 1 package framework 2 3 import ( 4 "testing" 5 ) 6 7 func asserteq(t *testing.T, s []rune, tgt []rune) { 8 if len(s) != len(tgt) { 9 t.Fatalf("mismatched length %d %d", len(s), len(tgt)) 10 } 11 12 for i := range s { 13 if s[i] != tgt[i] { 14 t.Fatalf("mismatch at character %d output: %q target: %q", i, string(s), string(tgt)) 15 } 16 } 17 18 } 19 20 func TestInsertEnd(t *testing.T) { 21 s := []rune("something") 22 s = strInsertText(s, len(s), []rune("zap")) 23 asserteq(t, s, []rune("somethingzap")) 24 } 25 26 func TestInsertMid(t *testing.T) { 27 s := []rune("something") 28 s = strInsertText(s, 3, []rune("zap")) 29 asserteq(t, s, []rune("somzapething")) 30 } 31 32 func TestInsertStart(t *testing.T) { 33 s := []rune("something") 34 s = strInsertText(s, 0, []rune("zap")) 35 asserteq(t, s, []rune("zapsomething")) 36 } 37 38 func TestDeleteEnd(t *testing.T) { 39 s := []rune("something") 40 s = strDeleteText(s, len(s)-3, 3) 41 asserteq(t, s, []rune("someth")) 42 } 43 44 func TestDeleteMid(t *testing.T) { 45 s := []rune("something") 46 s = strDeleteText(s, 3, 2) 47 asserteq(t, s, []rune("somhing")) 48 } 49 50 func TestDeleteStart(t *testing.T) { 51 s := []rune("something") 52 s = strDeleteText(s, 0, 2) 53 asserteq(t, s, []rune("mething")) 54 } 55 56 func TestInsertFromNone(t *testing.T) { 57 s := []rune{} 58 s = strInsertText(s, 0, []rune("something")) 59 asserteq(t, s, []rune("something")) 60 } 61 62 func TestDeleteAll(t *testing.T) { 63 s := []rune("something") 64 s = strDeleteText(s, 0, len(s)) 65 asserteq(t, s, []rune{}) 66 }