-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjotter_test.go
109 lines (85 loc) · 2.14 KB
/
jotter_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package jot
import (
"reflect"
"testing"
)
type TestPrinter struct {
printCalled bool
printValues []interface{}
printfCalled bool
printfFormat string
printfValues []interface{}
printlnCalled bool
printlnValues []interface{}
}
func (t *TestPrinter) Print(v ...interface{}) {
t.printValues = v
t.printCalled = true
}
func (t *TestPrinter) Printf(format string, v ...interface{}) {
t.printfFormat = format
t.printfValues = v
t.printfCalled = true
}
func (t *TestPrinter) Println(v ...interface{}) {
t.printlnValues = v
t.printlnCalled = true
}
func TestPrintEnabled(t *testing.T) {
p := &TestPrinter{}
j := New(p)
j.Enable()
expected := []interface{}{"Some", "values", "passed", "in"}
j.Print(expected...)
if !reflect.DeepEqual(expected, p.printValues) {
t.Fatal("Passed values do not match", expected, p.printValues)
}
}
func TestPrintfEnabled(t *testing.T) {
p := &TestPrinter{}
j := New(p)
j.Enable()
format := "format %s %s %s %s"
expected := []interface{}{"Some", "values", "passed", "in"}
j.Printf(format, expected...)
if format != p.printfFormat {
t.Fatal("Passed format does not match", format, p.printfFormat)
}
if !reflect.DeepEqual(expected, p.printfValues) {
t.Fatal("Passed values do not match", expected, p.printfValues)
}
}
func TestPrintlnEnabled(t *testing.T) {
p := &TestPrinter{}
j := New(p)
j.Enable()
expected := []interface{}{"Some", "values", "passed", "in"}
j.Println(expected...)
if !reflect.DeepEqual(expected, p.printlnValues) {
t.Fatal("Passed values do not match", expected, p.printlnValues)
}
}
func TestPrintDisabled(t *testing.T) {
p := &TestPrinter{}
j := New(p)
j.Print("Some", "values", "passed", "in")
if p.printCalled {
t.Fatal("Expected printer to not be called")
}
}
func TestPrintfDisabled(t *testing.T) {
p := &TestPrinter{}
j := New(p)
j.Printf("format %s %s %s %s", "Some", "values", "passed", "in")
if p.printfCalled {
t.Fatal("Expected printer to not be called")
}
}
func TestPrintlnDisabled(t *testing.T) {
p := &TestPrinter{}
j := New(p)
j.Println("Some", "values", "passed", "in")
if p.printlnCalled {
t.Fatal("Expected printer to not be called")
}
}