-
Notifications
You must be signed in to change notification settings - Fork 1
/
swearjar_test.go
106 lines (79 loc) · 1.69 KB
/
swearjar_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
package swearjar_test
import (
"github.com/snicol/swearjar-go"
"reflect"
"testing"
)
func TestLoadSwears(t *testing.T) {
swears, err := swearjar.Load()
if err != nil {
t.Error(err)
}
if swears == nil {
t.Error("Swears could not be loaded")
}
}
func TestLoadSwearsWithNonexistentFile(t *testing.T) {
swears, err := swearjar.Load("nonexistent.json")
if err == nil {
t.Error(err)
}
if swears != nil {
t.Error("Swears could be loaded when they should not")
}
}
func TestLoadSwearsWithBadJSON(t *testing.T) {
swears, err := swearjar.Load("swearjar_test_bad.json")
if err == nil {
t.Error(err)
}
if swears != nil {
t.Error("Swears could be loaded when they should not")
}
}
func TestProfane(t *testing.T) {
swears, err := swearjar.Load()
if err != nil {
t.Error(err)
}
profane, err := swears.Profane("fuck is a word")
if err != nil {
t.Error(err)
}
if profane == false {
t.Error("fuck is profane")
}
}
func TestScorecard(t *testing.T) {
swears, err := swearjar.Load()
if err != nil {
t.Error(err)
}
profane, reasons, err := swears.Scorecard("what an asslick")
if err != nil {
t.Error(err)
}
if profane == false {
t.Error("asslick is profane")
}
expectedReasons := []string{"insult"}
if !reflect.DeepEqual(reasons, expectedReasons) {
t.Error("does not match reason")
}
}
func TestScorecardNoMatch(t *testing.T) {
swears, err := swearjar.Load()
if err != nil {
t.Error(err)
}
profane, reasons, err := swears.Scorecard("this is a lovfuckely sentshitence with no foul languassge")
if err != nil {
t.Error(err)
}
if profane == true {
t.Error("this is not profane")
}
if len(reasons) > 0 {
t.Error("should not have a reason")
}
}