MCPcopy Create free account
hub / github.com/cli/cli / replaceAll

Function replaceAll

pkg/cmd/auth/status/status_test.go:1150–1160  ·  view source on GitHub ↗

replaceAll replaces all instances of old with new in s, as well as all instances of the JSON-escaped version of old with the JSON-escaped version of new. This is because when the test is run on Windows the paths will have backslashes escaped in JSON and a simple strings.ReplaceAll won't catch them.

(s string, old string, new string)

Source from the content-addressed store, hash-verified

1148// This is because when the test is run on Windows the paths will have backslashes
1149// escaped in JSON and a simple strings.ReplaceAll won't catch them.
1150func replaceAll(s string, old string, new string) string {
1151 jsonEscapedOld, _ := json.Marshal(old)
1152 jsonEscapedOld = jsonEscapedOld[1 : len(jsonEscapedOld)-1]
1153
1154 jsonEscapedNew, _ := json.Marshal(new)
1155 jsonEscapedNew = jsonEscapedNew[1 : len(jsonEscapedNew)-1]
1156
1157 replaced := strings.ReplaceAll(s, string(jsonEscapedOld), string(jsonEscapedNew))
1158 replaced = strings.ReplaceAll(replaced, old, new)
1159 return replaced
1160}
1161
1162func TestMaskToken(t *testing.T) {
1163 tests := []struct {

Callers 1

Test_statusRunFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected