-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnull_pointer_test.go
More file actions
39 lines (32 loc) · 1009 Bytes
/
null_pointer_test.go
File metadata and controls
39 lines (32 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package fmt
import "testing"
// TestNullPointerProtection tests null pointer verification for *string
func TestNullPointerProtection(t *testing.T) {
// Test null string pointer
var nullStrPtr *string = nil
// This should not panic and should set an error
c := Convert(nullStrPtr)
if !c.hasContent(BuffErr) {
t.Error("Convert with null *string should set an error")
}
// String() should return empty due to error
result := c.String()
if result != "" {
t.Errorf("Convert with null *string should return empty string, got: %q", result)
}
}
// TestValidPointerHandling tests that valid pointers still work
func TestValidPointerHandling(t *testing.T) {
str := "test string"
strPtr := &str
// This should work normally
c := Convert(strPtr)
if c.hasContent(BuffErr) {
t.Error("Convert with valid *string should not set an error")
}
result := c.String()
expected := "test string"
if result != expected {
t.Errorf("Convert with valid *string: got %q, want %q", result, expected)
}
}