Skip to content

Commit efeb92e

Browse files
committed
feat: test updation for StringPointerFrom
1 parent fd92c28 commit efeb92e

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/strings/strings.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,5 @@ func CutSuffix(s, suffix string) (before string, found bool) {
13031303
// This is specifically useful when we are writing test cases,
13041304
// such as passing a string pointer to a struct field from a string constant.
13051305
func StringPointerFrom(s string) *string {
1306-
newString := Join([]string{s}, "")
1307-
return &newString
1306+
return &s
13081307
}

src/strings/strings_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -2051,3 +2051,27 @@ func BenchmarkReplaceAll(b *testing.B) {
20512051
stringSink = ReplaceAll("banana", "a", "<>")
20522052
}
20532053
}
2054+
2055+
func TestStringPointerFrom(t *testing.T) {
2056+
type args struct {
2057+
s string
2058+
}
2059+
tests := []struct {
2060+
args args
2061+
want string
2062+
}{
2063+
{
2064+
args: args{
2065+
s: "test",
2066+
},
2067+
want: "test",
2068+
},
2069+
}
2070+
for _, tt := range tests {
2071+
t.Run(tt.name, func(t *testing.T) {
2072+
if got := StringPointerFrom(tt.args.s); *got != tt.want {
2073+
t.Errorf("StringPointerFrom() = %v, want %v", *got, tt.want)
2074+
}
2075+
})
2076+
}
2077+
}

0 commit comments

Comments
 (0)