-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstring_test.go
50 lines (39 loc) · 1.17 KB
/
string_test.go
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
40
41
42
43
44
45
46
47
48
49
50
package goption
import (
"testing"
)
type IsStringer struct{}
func (IsStringer) String() string {
return "haha"
}
func (IsStringer) GoString() string {
return `"haha"`
}
func TestStringer(t *testing.T) {
if str := Some(IsStringer{}).String(); str != "haha" {
t.Errorf("Failed wrapping stringer: %s", str)
}
if str := None[IsStringer]().String(); str != "null" {
t.Errorf("Failed stringer for empty option: %s", str)
}
if str := Some(struct{}{}).String(); str != "{}" {
t.Errorf("Failed wrapping struct{}: %s", str)
}
if str := None[struct{}]().String(); str != "null" {
t.Errorf("Failed wrapping struct{}: %s", str)
}
}
func TestGoStringer(t *testing.T) {
if str := Some(IsStringer{}).GoString(); str != `"haha"` {
t.Errorf("Failed wrapping go stringer: %s", str)
}
if str := None[IsStringer]().GoString(); str != "Option[goption.IsStringer]{ok: false}" {
t.Errorf("Failed go stringer for empty option: %s", str)
}
if str := Some(struct{}{}).GoString(); str != "struct {}{}" {
t.Errorf("Failed wrapping struct{}: %s", str)
}
if str := None[struct{}]().GoString(); str != "Option[struct {}]{ok: false}" {
t.Errorf("Failed wrapping struct{}: %s", str)
}
}