MCPcopy
hub / github.com/google/mangle / TestStringReplace

Function TestStringReplace

functional/functional_test.go:782–812  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

780}
781
782func TestStringReplace(t *testing.T) {
783 tests := []struct {
784 provided string
785 old string
786 new string
787 count int64
788 want ast.Constant
789 }{
790 {"borked", "o", "0", 1, ast.String("b0rked")},
791 {"aaa", "a", "b", 2, ast.String("bba")},
792 {"aaa", "a", "b", -1, ast.String("bbb")},
793 {"/a/b/c", "/", "", -1, ast.String("abc")},
794 }
795 for _, test := range tests {
796 term := ast.ApplyFn{
797 symbols.StringReplace,
798 []ast.BaseTerm{
799 ast.String(test.provided),
800 ast.String(test.old),
801 ast.String(test.new),
802 ast.Number(test.count),
803 }}
804 got, err := EvalExpr(term, ast.ConstSubstMap{})
805 if err != nil {
806 t.Fatal(err)
807 }
808 if got != test.want {
809 t.Errorf("EvalExpr(%v)=%v want %v.", term, got, test.want)
810 }
811 }
812}
813
814func TestStringConcatenateForNameConstant(t *testing.T) {
815 name, err := ast.Name("/named/constant")

Callers

nothing calls this directly

Calls 3

StringFunction · 0.92
NumberFunction · 0.92
EvalExprFunction · 0.85

Tested by

no test coverage detected