forked from MemeLabs/chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
users_test.go
117 lines (105 loc) · 2.34 KB
/
users_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
110
111
112
113
114
115
116
117
package main
import (
"testing"
)
func init() {
initDatabase(":memory:", true)
}
/*
// this needs to be fixed along with `nicklookup`
func TestUserLookup(t *testing.T) {
uid := Userid(1)
nick := "testnick"
u := &User{}
u.id = uid
u.nick = nick
usertools.addUser(u, true)
if r, _ := usertools.getUseridForNick(nick); r != uid {
t.Error("usertools.adduser failed, returned uid was: ", r, "(expected:", uid, ") for nick: ", nick)
}
nick = "TESTNICK"
if r, _ := usertools.getUseridForNick(nick); r != uid {
t.Error("usertools.adduser failed, returned uid was: ", r, "(expected:", uid, ") for nick: ", nick)
}
}
*/
func TestFeatures(t *testing.T) {
uid := Userid(1)
nick := "testnick"
u := &User{}
u.id = uid
u.nick = nick
if u.featureGet(ISPROTECTED) {
t.Error("feature should not be set")
}
if u.featureGet(ISSUBSCRIBER) {
t.Error("feature should not be set")
}
if u.featureGet(ISVIP) {
t.Error("feature should not be set")
}
if u.featureGet(ISMODERATOR) {
t.Error("feature should not be set")
}
if u.featureGet(ISADMIN) {
t.Error("feature should not be set")
}
if u.featureGet(ISBOT) {
t.Error("feature should not be set")
}
for i := uint8(6); i <= 28; i++ {
if u.featureGet(1 << i) {
t.Error("feature should not be set")
}
}
if u.isProtected() {
t.Error("should not be protected")
}
if u.isBot() {
t.Error("should not be bot")
}
if u.isSubscriber() {
t.Error("should not be subscriber")
}
if u.isModerator() {
t.Error("should not be moderator")
}
//--------
features := []string{"admin", "moderator", "protected", "subscriber", "vip", "bot"}
u.setFeatures(features)
if !u.featureGet(ISPROTECTED) {
t.Error("feature should be set")
}
if !u.featureGet(ISSUBSCRIBER) {
t.Error("feature should be set")
}
if !u.featureGet(ISVIP) {
t.Error("feature should be set")
}
if !u.featureGet(ISMODERATOR) {
t.Error("feature should be set")
}
if !u.featureGet(ISADMIN) {
t.Error("feature should be set")
}
if !u.featureGet(ISBOT) {
t.Error("feature should be set")
}
for i := uint8(6); i <= 28; i++ {
if u.featureGet(1 << i) {
t.Error("feature should not be set")
}
}
if !u.isProtected() {
t.Error("should be protected")
}
if !u.isBot() {
t.Error("should be bot")
}
if !u.isSubscriber() {
t.Error("should be subscriber")
}
if !u.isModerator() {
t.Error("should be moderator")
}
}