You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ISupportProcessorTest.kt 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package com.dmdirc.ktirc.messages
  2. import com.dmdirc.ktirc.io.CaseMapping
  3. import com.dmdirc.ktirc.io.IrcMessage
  4. import com.dmdirc.ktirc.model.ServerFeature
  5. import com.dmdirc.ktirc.model.ServerFeatureMap
  6. import org.junit.jupiter.api.Assertions.*
  7. import org.junit.jupiter.api.Test
  8. internal class ISupportProcessorTest {
  9. private val processor = ISupportProcessor()
  10. @Test
  11. fun `ISupportProcessor can handle 005s`() {
  12. assertTrue(processor.commands.contains("005")) { "ISupportProcessor should handle 005 messages" }
  13. }
  14. @Test
  15. fun `ISupportProcessor handles multiple numeric arguments`() {
  16. val events = processor.process(IrcMessage(null, "server.com".toByteArray(), "005",
  17. listOf("nickname", "CHANLIMIT=123", "CHANNELLEN=456", "are supported blah blah").map { it.toByteArray() }))
  18. assertEquals(123, events[0].serverFeatures[ServerFeature.MaximumChannels])
  19. assertEquals(456, events[0].serverFeatures[ServerFeature.MaximumChannelNameLength])
  20. }
  21. @Test
  22. fun `ISupportProcessor handles string arguments`() {
  23. val events = processor.process(IrcMessage(null, "server.com".toByteArray(), "005",
  24. listOf("nickname", "CHANMODES=abcd", "are supported blah blah").map { it.toByteArray() }))
  25. assertEquals("abcd", events[0].serverFeatures[ServerFeature.ChannelModes])
  26. }
  27. @Test
  28. fun `ISupportProcessor handles resetting arguments`() {
  29. val events = processor.process(IrcMessage(null, "server.com".toByteArray(), "005",
  30. listOf("nickname", "-CHANMODES", "are supported blah blah").map { it.toByteArray() }))
  31. val oldFeatures = ServerFeatureMap()
  32. oldFeatures[ServerFeature.ChannelModes] = "abc"
  33. oldFeatures.setAll(events[0].serverFeatures)
  34. assertNull(oldFeatures[ServerFeature.ChannelModes])
  35. }
  36. @Test
  37. fun `ISupportProcessor handles case mapping arguments`() {
  38. val events = processor.process(IrcMessage(null, "server.com".toByteArray(), "005",
  39. listOf("nickname", "CASEMAPPING=rfc1459-strict", "are supported blah blah").map { it.toByteArray() }))
  40. assertEquals(CaseMapping.RfcStrict, events[0].serverFeatures[ServerFeature.ServerCaseMapping])
  41. }
  42. @Test
  43. fun `ISupportProcessor handles boolean features with no arguments`() {
  44. val events = processor.process(IrcMessage(null, "server.com".toByteArray(), "005",
  45. listOf("nickname", "WHOX", "are supported blah blah").map { it.toByteArray() }))
  46. assertEquals(true, events[0].serverFeatures[ServerFeature.WhoxSupport])
  47. }
  48. }