|
@@ -6,7 +6,6 @@ import com.dmdirc.ktirc.io.CaseMapping
|
6
|
6
|
import com.dmdirc.ktirc.model.*
|
7
|
7
|
import com.nhaarman.mockitokotlin2.doReturn
|
8
|
8
|
import com.nhaarman.mockitokotlin2.mock
|
9
|
|
-import kotlinx.coroutines.runBlocking
|
10
|
9
|
import org.junit.jupiter.api.Assertions.*
|
11
|
10
|
import org.junit.jupiter.api.Test
|
12
|
11
|
|
|
@@ -22,19 +21,19 @@ internal class ChannelStateHandlerTest {
|
22
|
21
|
}
|
23
|
22
|
|
24
|
23
|
@Test
|
25
|
|
- fun `ChannelStateHandler creates new state object for local joins`() = runBlocking {
|
|
24
|
+ fun `ChannelStateHandler creates new state object for local joins`() {
|
26
|
25
|
handler.processEvent(ircClient, ChannelJoined(TestConstants.time, User("acidburn", "libby", "root.localhost"), "#thegibson"))
|
27
|
26
|
assertTrue("#thegibson" in channelStateMap)
|
28
|
27
|
}
|
29
|
28
|
|
30
|
29
|
@Test
|
31
|
|
- fun `ChannelStateHandler does not create new state object for remote joins`() = runBlocking {
|
|
30
|
+ fun `ChannelStateHandler does not create new state object for remote joins`() {
|
32
|
31
|
handler.processEvent(ircClient, ChannelJoined(TestConstants.time, User("zerocool", "dade", "root.localhost"), "#thegibson"))
|
33
|
32
|
assertFalse("#thegibson" in channelStateMap)
|
34
|
33
|
}
|
35
|
34
|
|
36
|
35
|
@Test
|
37
|
|
- fun `ChannelStateHandler adds joiners to channel state`() = runBlocking {
|
|
36
|
+ fun `ChannelStateHandler adds joiners to channel state`() {
|
38
|
37
|
channelStateMap += ChannelState("#thegibson") { CaseMapping.Rfc }
|
39
|
38
|
|
40
|
39
|
handler.processEvent(ircClient, ChannelJoined(TestConstants.time, User("zerocool", "dade", "root.localhost"), "#thegibson"))
|
|
@@ -43,7 +42,7 @@ internal class ChannelStateHandlerTest {
|
43
|
42
|
}
|
44
|
43
|
|
45
|
44
|
@Test
|
46
|
|
- fun `ChannelStateHandler clears existing users when getting a new list`() = runBlocking {
|
|
45
|
+ fun `ChannelStateHandler clears existing users when getting a new list`() {
|
47
|
46
|
val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
|
48
|
47
|
channel.users += ChannelUser("acidBurn")
|
49
|
48
|
channel.users += ChannelUser("thePlague")
|
|
@@ -56,7 +55,7 @@ internal class ChannelStateHandlerTest {
|
56
|
55
|
}
|
57
|
56
|
|
58
|
57
|
@Test
|
59
|
|
- fun `ChannelStateHandler adds users from multiple name received events`() = runBlocking {
|
|
58
|
+ fun `ChannelStateHandler adds users from multiple name received events`() {
|
60
|
59
|
val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
|
61
|
60
|
channelStateMap += channel
|
62
|
61
|
|
|
@@ -71,7 +70,7 @@ internal class ChannelStateHandlerTest {
|
71
|
70
|
}
|
72
|
71
|
|
73
|
72
|
@Test
|
74
|
|
- fun `ChannelStateHandler clears and readds users on additional names received`() = runBlocking {
|
|
73
|
+ fun `ChannelStateHandler clears and readds users on additional names received`() {
|
75
|
74
|
val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
|
76
|
75
|
channelStateMap += channel
|
77
|
76
|
|
|
@@ -86,7 +85,7 @@ internal class ChannelStateHandlerTest {
|
86
|
85
|
}
|
87
|
86
|
|
88
|
87
|
@Test
|
89
|
|
- fun `ChannelStateHandler adds users with mode prefixes`() = runBlocking {
|
|
88
|
+ fun `ChannelStateHandler adds users with mode prefixes`() {
|
90
|
89
|
val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
|
91
|
90
|
channelStateMap += channel
|
92
|
91
|
serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
|
|
@@ -102,7 +101,7 @@ internal class ChannelStateHandlerTest {
|
102
|
101
|
}
|
103
|
102
|
|
104
|
103
|
@Test
|
105
|
|
- fun `ChannelStateHandler adds users with full hosts`() = runBlocking {
|
|
104
|
+ fun `ChannelStateHandler adds users with full hosts`() {
|
106
|
105
|
val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
|
107
|
106
|
channelStateMap += channel
|
108
|
107
|
serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
|
|
@@ -116,7 +115,7 @@ internal class ChannelStateHandlerTest {
|
116
|
115
|
}
|
117
|
116
|
|
118
|
117
|
@Test
|
119
|
|
- fun `ChannelStateHandler removes state object for local parts`() = runBlocking {
|
|
118
|
+ fun `ChannelStateHandler removes state object for local parts`() {
|
120
|
119
|
val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
|
121
|
120
|
channelStateMap += channel
|
122
|
121
|
|
|
@@ -126,7 +125,7 @@ internal class ChannelStateHandlerTest {
|
126
|
125
|
}
|
127
|
126
|
|
128
|
127
|
@Test
|
129
|
|
- fun `ChannelStateHandler removes user from channel member list for remote parts`() = runBlocking {
|
|
128
|
+ fun `ChannelStateHandler removes user from channel member list for remote parts`() {
|
130
|
129
|
val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
|
131
|
130
|
channel.users += ChannelUser("ZeroCool")
|
132
|
131
|
channelStateMap += channel
|
|
@@ -137,7 +136,7 @@ internal class ChannelStateHandlerTest {
|
137
|
136
|
}
|
138
|
137
|
|
139
|
138
|
@Test
|
140
|
|
- fun `ChannelStateHandler removes user from all channel member lists for quits`() = runBlocking {
|
|
139
|
+ fun `ChannelStateHandler removes user from all channel member lists for quits`() {
|
141
|
140
|
with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
|
142
|
141
|
users += ChannelUser("ZeroCool")
|
143
|
142
|
channelStateMap += this
|
|
@@ -163,7 +162,7 @@ internal class ChannelStateHandlerTest {
|
163
|
162
|
|
164
|
163
|
|
165
|
164
|
@Test
|
166
|
|
- fun `ChannelStateHandler raises ChannelQuit event for each channel a user quits from`() = runBlocking {
|
|
165
|
+ fun `ChannelStateHandler raises ChannelQuit event for each channel a user quits from`() {
|
167
|
166
|
with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
|
168
|
167
|
users += ChannelUser("ZeroCool")
|
169
|
168
|
channelStateMap += this
|
|
@@ -196,4 +195,48 @@ internal class ChannelStateHandlerTest {
|
196
|
195
|
assertTrue("#dumpsterdiving" in names)
|
197
|
196
|
}
|
198
|
197
|
|
|
198
|
+ @Test
|
|
199
|
+ fun `sets mode discovered flag when discovered mode event received`() {
|
|
200
|
+ val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
|
|
201
|
+ channelStateMap += channel
|
|
202
|
+ serverState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
|
|
203
|
+
|
|
204
|
+ handler.processEvent(ircClient, ModeChanged(TestConstants.time, "#thegibson", "+", emptyArray(), true))
|
|
205
|
+
|
|
206
|
+ assertTrue(channel.modesDiscovered)
|
|
207
|
+ }
|
|
208
|
+
|
|
209
|
+ @Test
|
|
210
|
+ fun `adds modes when discovered mode event received`() {
|
|
211
|
+ val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
|
|
212
|
+ channelStateMap += channel
|
|
213
|
+ serverState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
|
|
214
|
+
|
|
215
|
+ handler.processEvent(ircClient, ModeChanged(TestConstants.time, "#thegibson", "+ceg", arrayOf("CCC", "EEE"), true))
|
|
216
|
+
|
|
217
|
+ assertEquals("CCC", channel.modes['c'])
|
|
218
|
+ assertEquals("EEE", channel.modes['e'])
|
|
219
|
+ assertEquals("", channel.modes['g'])
|
|
220
|
+ }
|
|
221
|
+
|
|
222
|
+ @Test
|
|
223
|
+ fun `adjusts complex modes when mode change event received`() {
|
|
224
|
+ val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
|
|
225
|
+ channel.modes['c'] = "CCC"
|
|
226
|
+ channel.modes['e'] = "EEE"
|
|
227
|
+ channel.modes['h'] = ""
|
|
228
|
+ channelStateMap += channel
|
|
229
|
+ serverState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
|
|
230
|
+
|
|
231
|
+ handler.processEvent(ircClient, ModeChanged(TestConstants.time, "#thegibson", "-c+d-eh+fg", arrayOf("CCC", "DDD", "FFF"), true))
|
|
232
|
+
|
|
233
|
+ assertNull(channel.modes['c'])
|
|
234
|
+ assertEquals("DDD", channel.modes['d'])
|
|
235
|
+ assertNull(channel.modes['e'])
|
|
236
|
+ assertEquals("FFF", channel.modes['f'])
|
|
237
|
+ assertEquals("", channel.modes['g'])
|
|
238
|
+ assertNull(channel.modes['h'])
|
|
239
|
+ }
|
|
240
|
+
|
|
241
|
+
|
199
|
242
|
}
|