PageRenderTime 72ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/state.rb

https://bitbucket.org/tagoh/prune
Ruby | 1046 lines | 908 code | 98 blank | 40 comment | 2 complexity | 71a48a2f0f6b20bf4a7674ff46f34629 MD5 | raw file
Possible License(s): GPL-2.0
  1. # state.rb
  2. # Copyright (C) 2009 Akira TAGOH
  3. # Authors:
  4. # Akira TAGOH <akira@tagoh.org>
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 59 Temple Place - Suite 330,
  16. # Boston, MA 02111-1307, USA.
  17. require 'rubygems'
  18. gem 'test-unit'
  19. require 'test/unit/testcase'
  20. require 'prune/state'
  21. class TestPRUNE__NickList < Test::Unit::TestCase
  22. class << self
  23. def set_msg(msg)
  24. @@msg = msg
  25. end # def set_msg
  26. def get_msg
  27. @@msg
  28. end # def get_msg
  29. end
  30. def setup
  31. @@msg = nil
  32. def PRUNE._output(msg)
  33. TestPRUNE__NickList.set_msg(msg)
  34. end # def
  35. end # def setup
  36. def teardown
  37. raise StandardError, sprintf("%s", @@msg) unless @@msg.nil?
  38. def PRUNE._output(msg)
  39. Kernel.printf("%s\n", msg)
  40. end # def
  41. end # def teardown
  42. def test_add
  43. t = PRUNE::NickList.new
  44. assert_equal(nil, t.add(1))
  45. assert_match(Regexp.new("\\[BUG\\] Found an unexpected object in `PRUNE::NickList:#<PRUNE::NickList:0x[0-9a-f]+>': 1"), TestPRUNE__NickList.get_msg)
  46. TestPRUNE__NickList.set_msg(nil)
  47. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("foo"))}
  48. assert_equal(1, t.size)
  49. end # def test_add
  50. def test_delete
  51. t = PRUNE::NickList.new
  52. assert_equal(nil, t.add(1))
  53. TestPRUNE__NickList.set_msg(nil)
  54. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("foo"))}
  55. assert_equal(1, t.size)
  56. assert_nothing_raised {t.delete("bar")}
  57. TestPRUNE__NickList.set_msg(nil)
  58. assert_equal(1, t.size)
  59. assert_nothing_raised {t.delete("Foo")}
  60. assert_equal(0, t.size)
  61. end # def test_delete
  62. def test_include
  63. t = PRUNE::NickList.new
  64. assert_equal(nil, t.add(1))
  65. TestPRUNE__NickList.set_msg(nil)
  66. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("foo"))}
  67. assert_equal(true, t.include?("foo"))
  68. assert_equal(true, t.include?("Foo"))
  69. assert_equal(true, t.include?("fOo"))
  70. assert_equal(false, t.include?(:foo))
  71. assert_equal(false, t.include?("bar"))
  72. end # def test_include
  73. def test_nicks
  74. t = PRUNE::NickList.new
  75. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("fOo"))}
  76. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("baR"))}
  77. assert_equal(["fOo", "baR"], t.nicks)
  78. end # def test_nicks
  79. def test_has_oper
  80. t = PRUNE::NickList.new
  81. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("foo"))}
  82. assert_equal(false, t.has_oper?("foO"))
  83. assert_equal(false, t.has_oper?("Foo"))
  84. assert_equal(false, t.has_oper?("foo"))
  85. assert_nothing_raised {t.set_oper("FOO", true)}
  86. assert_equal(true, t.has_oper?("foO"))
  87. assert_equal(true, t.has_oper?("Foo"))
  88. assert_equal(true, t.has_oper?("foo"))
  89. assert_nothing_raised {t.set_oper("foo", false)}
  90. assert_equal(false, t.has_oper?("foO"))
  91. assert_equal(false, t.has_oper?("Foo"))
  92. assert_equal(false, t.has_oper?("foo"))
  93. end # def test_has_oper
  94. def test_set_oper
  95. # should be done in test_has_oper
  96. end # def test_set_oper
  97. def test_clear_oper
  98. t = PRUNE::NickList.new
  99. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("foo"))}
  100. assert_equal(false, t.has_oper?("foO"))
  101. assert_equal(false, t.has_oper?("Foo"))
  102. assert_equal(false, t.has_oper?("foo"))
  103. assert_nothing_raised {t.set_oper("FOO", true)}
  104. assert_equal(true, t.has_oper?("foO"))
  105. assert_equal(true, t.has_oper?("Foo"))
  106. assert_equal(true, t.has_oper?("foo"))
  107. assert_nothing_raised {t.clear_oper}
  108. assert_equal(false, t.has_oper?("foO"))
  109. assert_equal(false, t.has_oper?("Foo"))
  110. assert_equal(false, t.has_oper?("foo"))
  111. end # def test_clear_oper
  112. def test_opers
  113. t = PRUNE::NickList.new
  114. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("foo"))}
  115. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("bAr"))}
  116. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("baZ"))}
  117. assert_equal(true, t.set_oper("baR", true))
  118. assert_equal(true, t.set_oper("bAz", true))
  119. assert_equal(["bAr", "baZ"], t.opers.sort)
  120. end # def test_opers
  121. def test_has_voice
  122. t = PRUNE::NickList.new
  123. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("foo"))}
  124. assert_equal(false, t.has_voice?("foO"))
  125. assert_equal(false, t.has_voice?("Foo"))
  126. assert_equal(false, t.has_voice?("foo"))
  127. assert_nothing_raised {t.set_voice("FOO", true)}
  128. assert_equal(true, t.has_voice?("foO"))
  129. assert_equal(true, t.has_voice?("Foo"))
  130. assert_equal(true, t.has_voice?("foo"))
  131. assert_nothing_raised {t.set_voice("foo", false)}
  132. assert_equal(false, t.has_voice?("foO"))
  133. assert_equal(false, t.has_voice?("Foo"))
  134. assert_equal(false, t.has_voice?("foo"))
  135. end # def test_has_voice
  136. def test_set_voice
  137. # should be done in test_has_voice
  138. end # def test_set_voice
  139. def test_clear_voice
  140. t = PRUNE::NickList.new
  141. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("foo"))}
  142. assert_equal(false, t.has_voice?("foO"))
  143. assert_equal(false, t.has_voice?("Foo"))
  144. assert_equal(false, t.has_voice?("foo"))
  145. assert_nothing_raised {t.set_voice("FOO", true)}
  146. assert_equal(true, t.has_voice?("foO"))
  147. assert_equal(true, t.has_voice?("Foo"))
  148. assert_equal(true, t.has_voice?("foo"))
  149. assert_nothing_raised {t.clear_voice}
  150. assert_equal(false, t.has_voice?("foO"))
  151. assert_equal(false, t.has_voice?("Foo"))
  152. assert_equal(false, t.has_voice?("foo"))
  153. end # def test_clear_voice
  154. def test_voices
  155. t = PRUNE::NickList.new
  156. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("foo"))}
  157. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("bAr"))}
  158. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("baZ"))}
  159. assert_equal(true, t.set_voice("foo", true))
  160. assert_equal(true, t.set_voice("bAz", true))
  161. assert_equal(["baZ", "foo"], t.voices.sort)
  162. end # def test_voices
  163. def test_change_nick
  164. t = PRUNE::NickList.new
  165. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("foo"))}
  166. assert_nothing_raised {t.add(PRUNE::TYPE::NickInfoStruct.new("baR"))}
  167. assert_equal(nil, t.change_nick("baz", "foo"))
  168. assert_equal(true, t.include?("fOo"))
  169. assert_equal(true, t.include?("foo"))
  170. assert_nothing_raised {t.change_nick("Foo", "fOo2")}
  171. assert_equal(false, t.include?("fOo"))
  172. assert_equal(false, t.include?("foo"))
  173. assert_equal(nil, t.change_nick("bar", "foo2"))
  174. TestPRUNE__NickList.set_msg(nil)
  175. end # def test_change_nick
  176. end # class TestPRUNE__NickList
  177. class TestPRUNE__ModeList < Test::Unit::TestCase
  178. class << self
  179. def set_msg(msg)
  180. @@msg = msg
  181. end # def set_msg
  182. def get_msg
  183. @@msg
  184. end # def get_msg
  185. end
  186. def setup
  187. @@msg = nil
  188. def PRUNE._output(msg)
  189. TestPRUNE__ModeList.set_msg(msg)
  190. end # def
  191. end # def setup
  192. def teardown
  193. raise StandardError, sprintf("%s", @@msg) unless @@msg.nil?
  194. def PRUNE._output(msg)
  195. Kernel.printf("%s\n", msg)
  196. end # def
  197. end # def teardown
  198. def test_base__modename
  199. t = PRUNE::ModeList.new
  200. assert_equal([], t.modename(0))
  201. assert_equal([nil], t.modename(PRUNE::ModeList::MODE_UNINITIALIZED))
  202. assert_equal(["AWAY"], t.modename(PRUNE::ModeList::MODE_AWAY))
  203. assert_equal(["INVISIBLE"], t.modename(PRUNE::ModeList::MODE_INVISIBLE))
  204. assert_equal(["WALLOPS"], t.modename(PRUNE::ModeList::MODE_WALLOPS))
  205. assert_equal(["RESTRICTED"], t.modename(PRUNE::ModeList::MODE_RESTRICTED))
  206. assert_equal(["OPER"], t.modename(PRUNE::ModeList::MODE_OPER))
  207. assert_equal(["LOCAL_OPER"], t.modename(PRUNE::ModeList::MODE_LOCAL_OPER))
  208. assert_equal(["SERVER_NOTICE"], t.modename(PRUNE::ModeList::MODE_SERVER_NOTICE))
  209. assert_equal(["AWAY", "OPER"], t.modename(PRUNE::ModeList::MODE_AWAY|PRUNE::ModeList::MODE_OPER))
  210. end # def test_base__modename
  211. def test_base__to_s
  212. # basically should be done in test_set_mode
  213. end # def test_base__to_s
  214. def test_base__clear
  215. # basically should be done in test_set_mode
  216. end # def test_base__clear
  217. def test_base__modeinfo
  218. t = PRUNE::ModeList.new
  219. assert_equal(nil, t.modeinfo(0))
  220. assert_equal(PRUNE::ModeList::MODE_AWAY, t.modeinfo('a'))
  221. assert_equal(PRUNE::ModeList::MODE_INVISIBLE, t.modeinfo('i'))
  222. assert_equal(PRUNE::ModeList::MODE_WALLOPS, t.modeinfo('w'))
  223. assert_equal(PRUNE::ModeList::MODE_RESTRICTED, t.modeinfo('r'))
  224. assert_equal(PRUNE::ModeList::MODE_OPER, t.modeinfo('o'))
  225. assert_equal(PRUNE::ModeList::MODE_LOCAL_OPER, t.modeinfo('O'))
  226. assert_equal(PRUNE::ModeList::MODE_SERVER_NOTICE, t.modeinfo('s'))
  227. end # def test_base__modeinfo
  228. def test_availmode
  229. assert_equal("aCeEiIQwroOs".split(//).sort.join, PRUNE::ModeList.availmode.split(//).sort.join)
  230. end # def test_availmode
  231. def test_set_mode
  232. t = PRUNE::ModeList.new
  233. assert_equal(nil, t.set_mode(0, true))
  234. assert_equal(nil, t.mode[0])
  235. assert_equal(nil, t.set_mode(0, false))
  236. assert_equal(nil, t.mode[0])
  237. assert_equal(nil, t.set_mode(PRUNE::ModeList::MODE_UNINITIALIZED, true))
  238. assert_equal(nil, t.mode[PRUNE::ModeList::MODE_UNINITIALIZED])
  239. assert_equal("+", t.to_s)
  240. assert_equal(nil, t.set_mode(PRUNE::ModeList::MODE_UNINITIALIZED, false))
  241. assert_equal(nil, t.mode[PRUNE::ModeList::MODE_UNINITIALIZED])
  242. assert_equal("+", t.to_s)
  243. assert_equal(true, t.set_mode(PRUNE::ModeList::MODE_AWAY, true))
  244. assert_equal(true, t.mode[PRUNE::ModeList::MODE_AWAY])
  245. assert_equal("+a", t.to_s)
  246. assert_equal(false, t.set_mode(PRUNE::ModeList::MODE_OPER, false))
  247. assert_equal(false, t.mode[PRUNE::ModeList::MODE_OPER])
  248. assert_equal("+a", t.to_s)
  249. assert_equal(true, t.set_mode(PRUNE::ModeList::MODE_LOCAL_OPER, true))
  250. assert_equal(true, t.mode[PRUNE::ModeList::MODE_LOCAL_OPER])
  251. assert_equal("+aO", t.to_s)
  252. assert_equal(nil, t.set_mode(0xffff, true))
  253. assert_equal("[BUG] unknown mode: 57345", TestPRUNE__ModeList.get_msg)
  254. TestPRUNE__ModeList.set_msg(nil)
  255. assert_equal(true, t.mode[PRUNE::ModeList::MODE_AWAY])
  256. assert_equal(true, t.mode[PRUNE::ModeList::MODE_INVISIBLE])
  257. assert_equal(true, t.mode[PRUNE::ModeList::MODE_WALLOPS])
  258. assert_equal(true, t.mode[PRUNE::ModeList::MODE_RESTRICTED])
  259. assert_equal(true, t.mode[PRUNE::ModeList::MODE_OPER])
  260. assert_equal(true, t.mode[PRUNE::ModeList::MODE_LOCAL_OPER])
  261. assert_equal(true, t.mode[PRUNE::ModeList::MODE_SERVER_NOTICE])
  262. assert_equal(["+" << PRUNE::ModeList.availmode.split(//).sort.join].join(' '), t.to_s.split(/ /)[0].split(//).delete_if{|x|x=='+'}.sort.unshift('+').join)
  263. assert_equal(nil, t.mode[65281])
  264. assert_equal(nil, t.set_mode(PRUNE::ModeList::MODE_UNINITIALIZED|PRUNE::ModeList::MODE_WALLOPS, false))
  265. assert_equal(true, t.mode[PRUNE::ModeList::MODE_AWAY])
  266. assert_equal(true, t.mode[PRUNE::ModeList::MODE_INVISIBLE])
  267. assert_equal(false, t.mode[PRUNE::ModeList::MODE_WALLOPS])
  268. assert_equal(true, t.mode[PRUNE::ModeList::MODE_RESTRICTED])
  269. assert_equal(true, t.mode[PRUNE::ModeList::MODE_OPER])
  270. assert_equal(true, t.mode[PRUNE::ModeList::MODE_LOCAL_OPER])
  271. assert_equal(true, t.mode[PRUNE::ModeList::MODE_SERVER_NOTICE])
  272. assert_equal(nil, t.mode[1])
  273. assert_equal("[BUG] unknown mode: 1", TestPRUNE__ModeList.get_msg)
  274. TestPRUNE__ModeList.set_msg(nil)
  275. assert_equal(false, t.set_mode(PRUNE::ModeList::MODE_AWAY, 0))
  276. assert_equal(false, t.mode[PRUNE::ModeList::MODE_AWAY])
  277. assert_nothing_raised {t.clear}
  278. assert_equal("+", t.to_s)
  279. end # def test_set_mode
  280. def test_base__mode
  281. # basically should be done in test_set_mode
  282. t = PRUNE::ModeList.new
  283. assert_raises(NoMethodError) {t.mode = 0}
  284. end # def test_base__mode
  285. end # class TestPRUNE__ModeList
  286. class TestPRUNE__ChannelModeList < Test::Unit::TestCase
  287. class << self
  288. def set_msg(msg)
  289. @@msg = msg
  290. end # def set_msg
  291. def get_msg
  292. @@msg
  293. end # def get_msg
  294. end
  295. def setup
  296. @@msg = nil
  297. def PRUNE._output(msg)
  298. TestPRUNE__ChannelModeList.set_msg(msg)
  299. end # def
  300. end # def setup
  301. def teardown
  302. raise StandardError, sprintf("%s", @@msg) unless @@msg.nil?
  303. def PRUNE._output(msg)
  304. Kernel.printf("%s\n", msg)
  305. end # def
  306. end # def teardown
  307. def test_functional
  308. assert_raises(ArgumentError) {t = PRUNE::ChannelModeList.new(0)}
  309. end # def test_functional
  310. def test_base__modename
  311. t = PRUNE::ChannelModeList.new(PRUNE::ChannelState.new("#foo"))
  312. assert_equal([], t.modename(0))
  313. assert_equal([nil], t.modename(PRUNE::ChannelModeList::MODE_UNINITIALIZED))
  314. assert_equal(["INVITE"], t.modename(PRUNE::ChannelModeList::MODE_INVITE))
  315. assert_equal(["MODERATED"], t.modename(PRUNE::ChannelModeList::MODE_MODERATED))
  316. assert_equal(["AUTO_INVITE"], t.modename(PRUNE::ChannelModeList::MODE_AUTO_INVITE))
  317. assert_equal(["OPER"], t.modename(PRUNE::ChannelModeList::MODE_OPER))
  318. assert_equal(["VOICE"], t.modename(PRUNE::ChannelModeList::MODE_VOICE))
  319. assert_equal(["SECRET"], t.modename(PRUNE::ChannelModeList::MODE_SECRET))
  320. assert_equal(["KEY"], t.modename(PRUNE::ChannelModeList::MODE_KEY))
  321. assert_equal(["LIMIT"], t.modename(PRUNE::ChannelModeList::MODE_LIMIT))
  322. assert_equal(["BAN"], t.modename(PRUNE::ChannelModeList::MODE_BAN))
  323. assert_equal(["EXCEPT"], t.modename(PRUNE::ChannelModeList::MODE_EXCEPT))
  324. assert_equal(["TOPIC"], t.modename(PRUNE::ChannelModeList::MODE_TOPIC))
  325. assert_equal(["PRIVATE"], t.modename(PRUNE::ChannelModeList::MODE_PRIVATE))
  326. assert_equal(["ANONYMOUS"], t.modename(PRUNE::ChannelModeList::MODE_ANONYMOUS))
  327. assert_equal(["NO_EXTERNAL_MSGS"], t.modename(PRUNE::ChannelModeList::MODE_NO_EXTERNAL_MSGS))
  328. assert_equal(["TOPIC", "NO_EXTERNAL_MSGS"], t.modename(PRUNE::ChannelModeList::MODE_TOPIC|PRUNE::ChannelModeList::MODE_NO_EXTERNAL_MSGS))
  329. end # def test_base__modename
  330. def test_base__to_s
  331. # basically should be done in test_set_mode
  332. end # def test_base__to_s
  333. def test_base__clear
  334. # basically should be done in test_set_mode
  335. end # def test_base__clear
  336. def test_availmode
  337. assert_equal("imIovsklbetpancdfgjJLPqQrRz".split(//).sort.join, PRUNE::ChannelModeList.availmode.split(//).sort.join)
  338. end # def test_availmode
  339. def test_modeinfo
  340. t = PRUNE::ChannelModeList.new(PRUNE::ChannelState.new("#foo"))
  341. assert_equal(nil, t.modeinfo(0))
  342. assert_equal([PRUNE::ChannelModeList::MODE_INVITE, false], t.modeinfo('i'))
  343. assert_equal([PRUNE::ChannelModeList::MODE_MODERATED, false], t.modeinfo('m'))
  344. assert_equal([PRUNE::ChannelModeList::MODE_AUTO_INVITE, true], t.modeinfo('I'))
  345. assert_equal([PRUNE::ChannelModeList::MODE_OPER, true], t.modeinfo('o'))
  346. assert_equal([PRUNE::ChannelModeList::MODE_VOICE, true], t.modeinfo('v'))
  347. assert_equal([PRUNE::ChannelModeList::MODE_SECRET, false], t.modeinfo('s'))
  348. assert_equal([PRUNE::ChannelModeList::MODE_KEY, true], t.modeinfo('k'))
  349. assert_equal([PRUNE::ChannelModeList::MODE_LIMIT, true], t.modeinfo('l'))
  350. assert_equal([PRUNE::ChannelModeList::MODE_BAN, true], t.modeinfo('b'))
  351. assert_equal([PRUNE::ChannelModeList::MODE_EXCEPT, true], t.modeinfo('e'))
  352. assert_equal([PRUNE::ChannelModeList::MODE_TOPIC, false], t.modeinfo('t'))
  353. assert_equal([PRUNE::ChannelModeList::MODE_PRIVATE, false], t.modeinfo('p'))
  354. assert_equal([PRUNE::ChannelModeList::MODE_ANONYMOUS, false], t.modeinfo('a'))
  355. assert_equal([PRUNE::ChannelModeList::MODE_NO_EXTERNAL_MSGS, false], t.modeinfo('n'))
  356. end # def test_modeinfo
  357. def test_set_mode
  358. t = PRUNE::ChannelModeList.new(x = PRUNE::ChannelState.new("#foo"))
  359. assert_equal(nil, t.set_mode(0, true))
  360. assert_equal(nil, t.mode[0])
  361. assert_equal(nil, t.set_mode(0, false))
  362. assert_equal(nil, t.mode[0])
  363. assert_equal(nil, t.set_mode(PRUNE::ChannelModeList::MODE_UNINITIALIZED, true))
  364. assert_equal(nil, t.mode[PRUNE::ChannelModeList::MODE_UNINITIALIZED])
  365. assert_equal("+", t.to_s)
  366. assert_equal(nil, t.set_mode(PRUNE::ChannelModeList::MODE_UNINITIALIZED, false))
  367. assert_equal(nil, t.mode[PRUNE::ChannelModeList::MODE_UNINITIALIZED])
  368. assert_equal("+", t.to_s)
  369. assert_equal(true, t.set_mode(PRUNE::ChannelModeList::MODE_INVITE, true))
  370. assert_equal(true, t.mode[PRUNE::ChannelModeList::MODE_INVITE])
  371. assert_equal("+i", t.to_s)
  372. assert_equal(true, t.set_mode(PRUNE::ChannelModeList::MODE_MODERATED, true))
  373. assert_equal(true, t.mode[PRUNE::ChannelModeList::MODE_MODERATED])
  374. assert_equal("+im", t.to_s)
  375. assert_equal(false, t.set_mode(PRUNE::ChannelModeList::MODE_MODERATED, false))
  376. assert_equal(false, t.mode[PRUNE::ChannelModeList::MODE_MODERATED])
  377. assert_equal("+i", t.to_s)
  378. assert_raises(ArgumentError) {t.set_mode(PRUNE::ChannelModeList::MODE_AUTO_INVITE, true, 0)}
  379. assert_raises(ArgumentError) {t.set_mode(PRUNE::ChannelModeList::MODE_AUTO_INVITE, true, :foo)}
  380. assert_equal(true, t.set_mode(PRUNE::ChannelModeList::MODE_AUTO_INVITE, true, "foo"))
  381. assert_equal(["foo!*@*"], t.mode[PRUNE::ChannelModeList::MODE_AUTO_INVITE])
  382. assert_equal("+iI foo!*@*", t.to_s)
  383. assert_nothing_raised {x.join("bar")}
  384. assert_equal(true, t.set_mode(PRUNE::ChannelModeList::MODE_OPER, true, "bar"))
  385. assert_equal(["bar"], x.opers)
  386. assert_equal(["bar"], t.mode[PRUNE::ChannelModeList::MODE_OPER])
  387. assert_equal("+iIo foo!*@* bar", t.to_s)
  388. assert_nothing_raised {x.join("foo")}
  389. assert_equal(true, t.set_mode(PRUNE::ChannelModeList::MODE_VOICE, true, "foo"))
  390. assert_equal(["foo"], t.mode[PRUNE::ChannelModeList::MODE_VOICE])
  391. assert_equal("+iIov foo!*@* bar foo", t.to_s)
  392. assert_equal(false, t.set_mode(PRUNE::ChannelModeList::MODE_SECRET, false))
  393. assert_equal(false, t.mode[PRUNE::ChannelModeList::MODE_SECRET])
  394. assert_equal("+iIov foo!*@* bar foo", t.to_s)
  395. assert_equal(true, t.set_mode(PRUNE::ChannelModeList::MODE_KEY, true, "blahblahblah"))
  396. assert_raises(ArgumentError) {t.set_mode(PRUNE::ChannelModeList::MODE_KEY, true, 0)}
  397. assert_raises(ArgumentError) {t.set_mode(PRUNE::ChannelModeList::MODE_KEY, true, :foo)}
  398. assert_equal("blahblahblah", t.mode[PRUNE::ChannelModeList::MODE_KEY])
  399. assert_equal("+iIovk foo!*@* bar foo blahblahblah", t.to_s)
  400. assert_equal(true, t.set_mode(PRUNE::ChannelModeList::MODE_LIMIT, true, 10))
  401. assert_equal(10, t.mode[PRUNE::ChannelModeList::MODE_LIMIT])
  402. assert_equal("+iIovkl foo!*@* bar foo blahblahblah 10", t.to_s)
  403. assert_equal(true, t.set_mode(PRUNE::ChannelModeList::MODE_BAN, true, "*!foo@*.com"))
  404. assert_equal(["*!foo@*.com"], t.mode[PRUNE::ChannelModeList::MODE_BAN])
  405. assert_equal("+iIovklb foo!*@* bar foo blahblahblah 10 *!foo@*.com", t.to_s)
  406. assert_equal(true, t.set_mode(PRUNE::ChannelModeList::MODE_BAN, true, "spam*@*.com"))
  407. assert_equal(["*!foo@*.com", "spam*!*@*.com"], t.mode[PRUNE::ChannelModeList::MODE_BAN])
  408. assert_equal("+iIovklbb foo!*@* bar foo blahblahblah 10 *!foo@*.com spam*!*@*.com", t.to_s)
  409. assert_equal(true, t.set_mode(PRUNE::ChannelModeList::MODE_BAN, true, "*spam"))
  410. assert_equal(["*!foo@*.com", "spam*!*@*.com", "*spam!*@*"], t.mode[PRUNE::ChannelModeList::MODE_BAN])
  411. assert_equal("+iIovklbbb foo!*@* bar foo blahblahblah 10 *!foo@*.com spam*!*@*.com *spam!*@*", t.to_s)
  412. assert_equal(false, t.set_mode(PRUNE::ChannelModeList::MODE_TOPIC, false))
  413. assert_equal(false, t.mode[PRUNE::ChannelModeList::MODE_TOPIC])
  414. assert_equal("+iIovklbbb foo!*@* bar foo blahblahblah 10 *!foo@*.com spam*!*@*.com *spam!*@*", t.to_s)
  415. assert_equal(true, t.set_mode(PRUNE::ChannelModeList::MODE_PRIVATE, true))
  416. assert_equal(true, t.mode[PRUNE::ChannelModeList::MODE_PRIVATE])
  417. assert_equal("+iIovklbbbp foo!*@* bar foo blahblahblah 10 *!foo@*.com spam*!*@*.com *spam!*@*", t.to_s)
  418. assert_equal(false, t.set_mode(PRUNE::ChannelModeList::MODE_ANONYMOUS, false))
  419. assert_equal(false, t.mode[PRUNE::ChannelModeList::MODE_ANONYMOUS])
  420. assert_equal("+iIovklbbbp foo!*@* bar foo blahblahblah 10 *!foo@*.com spam*!*@*.com *spam!*@*", t.to_s)
  421. assert_equal(true, t.set_mode(PRUNE::ChannelModeList::MODE_NO_EXTERNAL_MSGS, true))
  422. assert_equal(true, t.mode[PRUNE::ChannelModeList::MODE_NO_EXTERNAL_MSGS])
  423. assert_equal("+iIovklbbbpn foo!*@* bar foo blahblahblah 10 *!foo@*.com spam*!*@*.com *spam!*@*", t.to_s)
  424. TestPRUNE__ChannelModeList.set_msg(nil)
  425. assert_equal(nil, t.set_mode(0xffff, true))
  426. # we don't support the multiple mode set
  427. assert_equal("[BUG] unknown mode: 65535", TestPRUNE__ChannelModeList.get_msg)
  428. TestPRUNE__ChannelModeList.set_msg(nil)
  429. assert_nothing_raised {t.clear}
  430. assert_equal("+ov bar foo", t.to_s)
  431. assert_equal(nil, t.mode[PRUNE::ChannelModeList::MODE_AUTO_INVITE])
  432. assert_equal(["bar"], t.mode[PRUNE::ChannelModeList::MODE_OPER])
  433. assert_equal(["foo"], t.mode[PRUNE::ChannelModeList::MODE_VOICE])
  434. assert_equal(nil, t.mode[PRUNE::ChannelModeList::MODE_KEY])
  435. assert_equal(nil, t.mode[PRUNE::ChannelModeList::MODE_BAN])
  436. assert_equal(nil, t.mode[PRUNE::ChannelModeList::MODE_EXCEPT])
  437. end # def test_set_mode
  438. def test_base__mode
  439. # basically should be done in test_set_mode
  440. t = PRUNE::ChannelModeList.new(PRUNE::ChannelState.new("#foo"))
  441. assert_raises(NoMethodError) {t.mode = 0}
  442. end # def test_base__mode
  443. end # class TestPRUNE__ChannelModeList
  444. class TestPRUNE__ChannelState < Test::Unit::TestCase
  445. class << self
  446. def set_msg(msg)
  447. @@msg = msg
  448. end # def set_msg
  449. def get_msg
  450. @@msg
  451. end # def get_msg
  452. end
  453. def setup
  454. @@msg = nil
  455. def PRUNE._output(msg)
  456. TestPRUNE__ChannelState.set_msg(msg)
  457. end # def
  458. end # def setup
  459. def teardown
  460. raise StandardError, sprintf("%s", @@msg) unless @@msg.nil?
  461. def PRUNE._output(msg)
  462. Kernel.printf("%s\n", msg)
  463. end # def
  464. end # def teardown
  465. def test_functional
  466. assert_raises(ArgumentError) {t = PRUNE::ChannelState.new(:foo)}
  467. assert_raises(ArgumentError) {t = PRUNE::ChannelState.new(0)}
  468. assert_raises(ArgumentError) {t = PRUNE::ChannelState.new("foo")}
  469. assert_nothing_raised {t = PRUNE::ChannelState.new("#foo")}
  470. assert_nothing_raised {t = PRUNE::ChannelState.new("%foo")}
  471. assert_nothing_raised {t = PRUNE::ChannelState.new("&foo")}
  472. assert_nothing_raised {t = PRUNE::ChannelState.new("!foo")}
  473. end # def test_functional
  474. def test_topic
  475. # should be done in test_set_topic
  476. end # def test_topic
  477. def test_set_topic
  478. t = PRUNE::ChannelState.new("#foo")
  479. assert_nothing_raised {t.topic = "foo"}
  480. assert_equal("foo", t.topic)
  481. end # def test_set_topic
  482. def test_joined_
  483. # should be done in test_join
  484. end # def test_joined_
  485. def test_join
  486. t = PRUNE::ChannelState.new("#foo")
  487. assert_equal(false, t.joined?("foo"))
  488. assert_nothing_raised {t.join("Foo")}
  489. assert_equal(true, t.joined?("foo"))
  490. assert_nothing_raised {t.leave("fOO")}
  491. assert_equal(false, t.joined?("foO"))
  492. end # def test_join
  493. def test_leave
  494. # should be done in test_join
  495. end # def test_leave
  496. def test_has_oper_
  497. # should be done in test_set_oper
  498. end # def test_has_oper_
  499. def test_set_oper
  500. t = PRUNE::ChannelState.new("#foo")
  501. assert_nothing_raised {t.join("Foo")}
  502. assert_nothing_raised {t.join("bAr")}
  503. assert_nothing_raised {t.set_oper("foo", true)}
  504. assert_equal(["Foo"], t.opers)
  505. assert_equal(true, t.has_oper?("fOo"))
  506. assert_equal(true, t.has_oper?("foo"))
  507. assert_equal(true, t.has_oper?("Foo"))
  508. assert_nothing_raised {t.set_oper("bar", false)}
  509. assert_equal(["Foo"], t.opers)
  510. assert_nothing_raised {t.set_oper("bar", 0)}
  511. assert_equal(["Foo"], t.opers)
  512. assert_nothing_raised {t.set_oper("bar", 1)}
  513. assert_equal(["Foo"], t.opers)
  514. assert_equal(false, t.has_oper?("BAR"))
  515. assert_equal(false, t.has_oper?("bar"))
  516. assert_nothing_raised {t.clear_oper}
  517. assert_equal([], t.opers)
  518. end # def test_set_oper
  519. def test_clear_oper
  520. # should be done in test_set_oper
  521. end # def test_clear_oper
  522. def test_opers
  523. # should be done in test_set_oper
  524. end # def test_opers
  525. def test_has_voice_
  526. # should be done in test_set_voice
  527. end # def test_has_voice_
  528. def test_set_voice
  529. t = PRUNE::ChannelState.new("#foo")
  530. assert_nothing_raised {t.join("Foo")}
  531. assert_nothing_raised {t.join("bAr")}
  532. assert_nothing_raised {t.set_voice("foo", true)}
  533. assert_equal(["Foo"], t.voices)
  534. assert_equal(true, t.has_voice?("foo"))
  535. assert_equal(true, t.has_voice?("fOo"))
  536. assert_equal(true, t.has_voice?("Foo"))
  537. assert_nothing_raised {t.set_voice("bar", false)}
  538. assert_equal(["Foo"], t.voices)
  539. assert_nothing_raised {t.set_voice("bar", 0)}
  540. assert_equal(["Foo"], t.voices)
  541. assert_nothing_raised {t.set_voice("bar", 1)}
  542. assert_equal(["Foo"], t.voices)
  543. assert_equal(false, t.has_voice?("BAR"))
  544. assert_equal(false, t.has_voice?("bar"))
  545. assert_nothing_raised {t.clear_voice}
  546. assert_equal([], t.voices)
  547. end # def test_set_voice
  548. def test_clear_voice
  549. # should be done in test_set_voice
  550. end # def test_clear_voice
  551. def test_voices
  552. # should be done in test_set_voice
  553. end # def test_voices
  554. def test_change_nick
  555. t = PRUNE::ChannelState.new("#foo")
  556. assert_nothing_raised {t.join("Foo")}
  557. assert_nothing_raised {t.join("bAr")}
  558. assert_nothing_raised {t.change_nick("foo", "bar")}
  559. assert_equal("WARNING ***: The nick name `\"bar\"' has already been in use.", TestPRUNE__ChannelState.get_msg)
  560. TestPRUNE__ChannelState.set_msg(nil)
  561. assert_equal(["Foo", "bAr"], t.nicks.sort)
  562. assert_nothing_raised {t.change_nick("baz", "foo")}
  563. assert_match(Regexp.new("\\[BUG\\] No such nick name in PRUNE::NickList:#<PRUNE::NickList:0x[0-9a-f]+>: \"baz\""), TestPRUNE__ChannelState.get_msg)
  564. TestPRUNE__ChannelState.set_msg(nil)
  565. assert_nothing_raised {t.change_nick("fOo", "baZ")}
  566. assert_equal(["bAr", "baZ"], t.nicks.sort)
  567. end # def test_change_nick
  568. def test_has_mode_
  569. t = PRUNE::ChannelState.new("#foo")
  570. assert_nothing_raised {t.join("Foo")}
  571. assert_nothing_raised {t.join("baR")}
  572. assert_equal(false, t.has_mode?(PRUNE::ChannelModeList::MODE_INVITE))
  573. assert_nothing_raised {t.set_mode("+i")}
  574. assert_equal(true, t.has_mode?(PRUNE::ChannelModeList::MODE_INVITE))
  575. assert_equal("+i", t.mode_string)
  576. assert_nothing_raised {t.set_mode("-i")}
  577. assert_equal(false, t.has_mode?(PRUNE::ChannelModeList::MODE_INVITE))
  578. assert_equal("+", t.mode_string)
  579. assert_nothing_raised {t.set_mode("+o", "foo")}
  580. assert_equal(true, t.has_mode?(PRUNE::ChannelModeList::MODE_OPER))
  581. assert_equal(true, t.has_oper?("Foo"))
  582. assert_equal("+o Foo", t.mode_string)
  583. assert_nothing_raised {t.set_mode("+be", "bar", "foo")}
  584. assert_equal(true, t.has_mode?(PRUNE::ChannelModeList::MODE_BAN))
  585. assert_equal(true, t.has_mode?(PRUNE::ChannelModeList::MODE_EXCEPT))
  586. assert_equal("+obe Foo bar!*@* foo!*@*", t.mode_string)
  587. assert_equal(["OPER:Foo", "BAN:bar!*@*", "EXCEPT:foo!*@*"], t.mode)
  588. assert_equal(["Foo"], t.mode(PRUNE::ChannelModeList::MODE_OPER))
  589. assert_nothing_raised {t.set_mode("+o", "bar")}
  590. assert_equal(["Foo", "baR"], t.mode(PRUNE::ChannelModeList::MODE_OPER))
  591. assert_nothing_raised {t.clear_mode}
  592. assert_equal("+oo Foo baR", t.mode_string)
  593. t = PRUNE::ChannelState.new("#foo")
  594. assert_nothing_raised {t.set_mode("+c-s")}
  595. assert_equal("+c", t.mode_string)
  596. t = PRUNE::ChannelState.new("#foo")
  597. assert_nothing_raised {t.set_mode("+c+b", "foo!*@*", "+i")}
  598. assert_equal("+ibc foo!*@*", t.mode_string)
  599. end # def test_has_mode_
  600. def test_mode
  601. # should be done in test_has_mode_
  602. end # def test_mode
  603. def test_mode_string
  604. # should be done in test_has_mode_
  605. t = PRUNE::ChannelState.new("#foo")
  606. assert_nothing_raised {t.join("foo")}
  607. assert_nothing_raised {t.set_oper("foo", true)}
  608. assert_equal(["foo"], t.opers)
  609. assert_equal("+o foo", t.mode_string)
  610. end # def test_mode_string
  611. def test_set_mode
  612. # should be done in test_has_mode_
  613. end # def test_set_mode
  614. def test_clear_mode
  615. # should be done in test_has_mode_
  616. end # def test_clear_mode
  617. end # class TestPRUNE__ChannelState
  618. class TestPRUNE__IRCState < Test::Unit::TestCase
  619. class << self
  620. def set_msg(msg)
  621. @@msg = msg
  622. end # def set_msg
  623. def get_msg
  624. @@msg
  625. end # def get_msg
  626. end
  627. def setup
  628. @@msg = nil
  629. def PRUNE._output(msg)
  630. TestPRUNE__IRCState.set_msg(msg)
  631. end # def
  632. end # def setup
  633. def teardown
  634. def PRUNE._output(msg)
  635. Kernel.printf("%s\n", msg)
  636. end # def
  637. end # def teardown
  638. def test_functional
  639. assert_nothing_raised {t = PRUNE::IRCState.new("nick", "user", "name", "host")}
  640. assert_raises(ArgumentError, "Invalid nick name: nick") {t = PRUNE::IRCState.new(0, "user", "name", "host")}
  641. assert_raises(ArgumentError, "Invalid user name: user") {t = PRUNE::IRCState.new("nick", 0, "name", "host")}
  642. assert_raises(TypeError, "Can't convert Fixnum into String") {t = PRUNE::IRCState.new("nick", "user", 0, "host")}
  643. assert_raises(TypeError, "Can't convert Symbol into String") {t = PRUNE::IRCState.new("nick", "user", :name, "host")}
  644. assert_raises(TypeError, "Can't convert Fixnum into String") {t = PRUNE::IRCState.new("nick", "user", "name", 0)}
  645. assert_raises(TypeError, "Can't convert Symbol into String") {t = PRUNE::IRCState.new("nick", "user", "name", :host)}
  646. end # def test_functional
  647. def test_nick
  648. t = PRUNE::IRCState.new("foo", "bar", "blahblahblah", "example.com")
  649. assert_equal("foo", t.nick)
  650. assert_equal("bar", t.user)
  651. assert_equal("blahblahblah", t.name)
  652. assert_equal("example.com", t.host)
  653. end # def test_nick
  654. def test_nick_
  655. # should be done in test_nick
  656. end # def test_nick_
  657. def test_user
  658. # should be done in test_nick
  659. end # def test_user
  660. def test_name
  661. # should be done in test_nick
  662. end # def test_name
  663. def test_host
  664. # should be done in test_nick
  665. end # def test_host
  666. def test_connected
  667. t = PRUNE::IRCState.new("nick", "user", "name", "host")
  668. assert_equal(false, t.connected?)
  669. assert_nothing_raised {t.connected = true}
  670. assert_equal(true, t.connected?)
  671. assert_nothing_raised {t.connected = false}
  672. assert_equal(false, t.connected?)
  673. end # def test_connected
  674. def test_connected_
  675. # should be done in test_connected
  676. end # def test_connected_
  677. def test_listen
  678. t = PRUNE::IRCState.new("nick", "user", "name", "host")
  679. assert_equal(false, t.listen?)
  680. assert_nothing_raised {t.listened = true}
  681. assert_equal(true, t.listen?)
  682. assert_nothing_raised {t.listened = false}
  683. assert_equal(false, t.listen?)
  684. end # def test_listen
  685. def test_listened_
  686. # should be done in test_listen
  687. end # def test_listened_
  688. def test_authenticated
  689. t = PRUNE::IRCState.new("nick", "user", "name", "host")
  690. assert_equal(false, t.authenticated?)
  691. assert_raises(PRUNE::Error::NotYetConnected) {t.authenticated = true}
  692. assert_equal(false, t.authenticated?)
  693. assert_nothing_raised {t.connected = true}
  694. assert_nothing_raised {t.authenticated = true}
  695. assert_equal(true, t.authenticated?)
  696. assert_nothing_raised {t.authenticated = false}
  697. assert_nothing_raised {t.loggedin = true}
  698. assert_raises(PRUNE::Error::AlreadyLoggedIn) {t.authenticated = true}
  699. assert_nothing_raised {t.connected = false}
  700. assert_equal(false, t.loggedin?)
  701. assert_equal(false, t.authenticated?)
  702. assert_nothing_raised {t.listened = true}
  703. assert_nothing_raised {t.authenticated = true}
  704. assert_equal(true, t.authenticated?)
  705. assert_nothing_raised {t.authenticated = false}
  706. assert_nothing_raised {t.loggedin = true}
  707. assert_raises(PRUNE::Error::AlreadyLoggedIn) {t.authenticated = true}
  708. assert_nothing_raised {t.listened = false}
  709. assert_equal(false, t.loggedin?)
  710. assert_equal(false, t.authenticated?)
  711. end # def test_authenticated
  712. def test_authenticated_
  713. # should be done in test_authenticated
  714. end # def test_authenticated_
  715. def test_loggedin
  716. t = PRUNE::IRCState.new("nick", "user", "name", "host")
  717. assert_equal(false, t.loggedin?)
  718. assert_raises(PRUNE::Error::NotYetConnected) {t.loggedin = true}
  719. assert_equal(false, t.loggedin?)
  720. assert_nothing_raised {t.connected = true}
  721. assert_nothing_raised {t.loggedin = true}
  722. assert_equal(true, t.loggedin?)
  723. assert_raises(PRUNE::Error::UnableToLogOut) {t.loggedin = false}
  724. assert_nothing_raised {t.connected = false}
  725. assert_equal(false, t.connected?)
  726. assert_equal(false, t.loggedin?)
  727. end # def test_loggedin
  728. def test_loggedin_
  729. # should be done in test_loggedin
  730. end # def test_loggedin_
  731. def test_channel
  732. t = PRUNE::IRCState.new("foo", "bar", "blahblahblah", "example.com")
  733. assert_raises(NoMethodError) {t.channel = 0}
  734. assert_nothing_raised {t.channel(0)}
  735. assert_match(Regexp.new("\\[BUG\\] No such channel `0' available in PRUNE::IRCState:#<PRUNE::IRCState:0x[0-9a-f]+ .*>"), TestPRUNE__IRCState.get_msg)
  736. TestPRUNE__IRCState.set_msg(nil)
  737. end # def test_channel
  738. def test_channels
  739. # should be done in test_join
  740. end # def test_channels
  741. def test_join
  742. t = PRUNE::IRCState.new("nick", "user", "name", "host")
  743. assert_nothing_raised {t.join("#foo", "nick")}
  744. assert_nothing_raised {t.join("#foo", "nick")}
  745. assert_match(Regexp.new("\\[BUG\\] `\"nick\"' has already joined a channel `\"#foo\"'"), TestPRUNE__IRCState.get_msg)
  746. TestPRUNE__IRCState.set_msg(nil)
  747. assert_nothing_raised {t.join("#bar", "nick")}
  748. assert_equal(["#bar", "#foo"], t.channels.sort)
  749. assert_nothing_raised {t.join("#foo", "bar")}
  750. assert_equal(["bar", "nick"], t.channel("#foo").nicks.sort)
  751. assert_nothing_raised {t.leave("#foo", "nick")}
  752. assert_equal(false, t.joined?("#foo", "nick"))
  753. t = PRUNE::IRCState.new("nick", "user", "name", "host")
  754. assert_nothing_raised {t.join("#foo", "nick")}
  755. assert_nothing_raised {t.join("#Foo", "baz")}
  756. assert_equal(["baz", "nick"], t.channel("#foo").nicks.sort)
  757. assert_equal(["baz", "nick"], t.channel("#Foo").nicks.sort)
  758. assert_equal(["#foo"], t.channels.sort)
  759. assert_equal(true, t.channels.include?("#Foo"))
  760. end # def test_join
  761. def test_leave
  762. # should be done in test_join
  763. end # def test_leave
  764. def test_quit
  765. t = PRUNE::IRCState.new("nick", "user", "name", "host")
  766. assert_nothing_raised {t.join("#foo", "nick")}
  767. assert_nothing_raised {t.join("#bar", "nick")}
  768. assert_nothing_raised {t.join("#foo", "bar")}
  769. assert_nothing_raised {t.join("#bar", "baz")}
  770. assert_equal(["bar", "nick"], t.channel("#foo").nicks.sort)
  771. assert_equal(["baz", "nick"], t.channel("#bar").nicks.sort)
  772. assert_nothing_raised {t.quit("bar")}
  773. assert_equal(["nick"], t.channel("#foo").nicks.sort)
  774. assert_equal(["baz", "nick"], t.channel("#bar").nicks.sort)
  775. assert_nothing_raised {t.quit("nick")}
  776. t = PRUNE::IRCState.new("nick", "user", "name", "host")
  777. assert_nothing_raised {t.join("#foo@suffix", "nick")}
  778. assert_nothing_raised {t.join("#bar@suffix", "nick")}
  779. assert_nothing_raised {t.join("#foo@suffix", "bar")}
  780. assert_nothing_raised {t.join("#bar@suffix", "baz")}
  781. assert_nothing_raised {t.join("#foo@suffix2", "nick")}
  782. assert_nothing_raised {t.join("#foo@suffix3", "nick")}
  783. assert_nothing_raised {t.join("#foo@suffix2", "bar")}
  784. assert_equal(["bar", "nick"], t.channel("#foo@suffix").nicks.sort)
  785. assert_equal(["baz", "nick"], t.channel("#bar@suffix").nicks.sort)
  786. assert_equal(["bar", "nick"], t.channel("#foo@suffix2").nicks.sort)
  787. assert_equal(["nick"], t.channel("#foo@suffix3").nicks.sort)
  788. assert_nothing_raised {t.quit("bar", "suffix")}
  789. assert_equal(["nick"], t.channel("#foo@suffix").nicks.sort)
  790. assert_equal(["bar", "nick"], t.channel("#foo@suffix2").nicks.sort)
  791. assert_equal(["baz", "nick"], t.channel("#bar@suffix").nicks.sort)
  792. assert_equal(["nick"], t.channel("#foo@suffix3").nicks.sort)
  793. end # def test_quit
  794. def test_has_mode
  795. # should be done in test_set_mode
  796. end # def test_has_mode
  797. def test_mode
  798. # should be done in test_set_mode
  799. end # def test_mode
  800. def test_mode_string
  801. # should be done in test_set_mode
  802. end # def test_mode_string
  803. def test_set_mode
  804. t = PRUNE::IRCState.new("nick", "user", "name", "host")
  805. assert_nothing_raised {t.set_mode("+ai")}
  806. assert_equal(true, t.has_mode?(PRUNE::ModeList::MODE_AWAY))
  807. assert_equal(true, t.has_mode?(PRUNE::ModeList::MODE_INVISIBLE))
  808. assert_equal("+ai", t.mode_string)
  809. assert_equal(["AWAY", "INVISIBLE"], t.mode)
  810. assert_equal(["AWAY"], t.mode(PRUNE::ModeList::MODE_AWAY))
  811. assert_equal([], t.mode(PRUNE::ModeList::MODE_WALLOPS))
  812. assert_nothing_raised {t.set_mode("-i")}
  813. assert_nothing_raised {t.has_mode?(PRUNE::ModeList::MODE_INVISIBLE)}
  814. assert_nothing_raised {t.set_mode("-!")}
  815. assert_equal("[BUG] unknown nick mode: \"!\"", TestPRUNE__IRCState.get_msg)
  816. TestPRUNE__IRCState.set_msg(nil)
  817. assert_nothing_raised {t.clear_mode}
  818. assert_equal("+", t.mode_string)
  819. assert_equal([], t.mode(PRUNE::ModeList::MODE_AWAY))
  820. end # def test_set_mode
  821. def test_clear_mode
  822. # should be done in test_set_mode
  823. end # def test_clear_mode
  824. end # class TestPRUNE__IRCState
  825. class TestPRUNE__ChannelStateReadOnly < Test::Unit::TestCase
  826. class << self
  827. def set_msg(msg)
  828. @@msg = msg
  829. end # def set_msg
  830. def get_msg
  831. @@msg
  832. end # def get_msg
  833. end
  834. def setup
  835. @@msg = nil
  836. def PRUNE._output(msg)
  837. TestPRUNE__ChannelStateReadOnly.set_msg(msg)
  838. end # def
  839. end # def setup
  840. def teardown
  841. def PRUNE._output(msg)
  842. Kernel.printf("%s\n", msg)
  843. end # def
  844. end # def teardown
  845. def test_functional
  846. assert_nothing_raised {t = PRUNE::ChannelStateReadOnly.new(PRUNE::ChannelState.new("#foo"))}
  847. assert_raises(ArgumentError) {t = PRUNE::ChannelStateReadOnly.new(0)}
  848. o = PRUNE::ChannelState.new("#foo")
  849. t = PRUNE::ChannelStateReadOnly.new(o)
  850. assert_equal(nil, t.topic)
  851. assert_raises(NoMethodError) {t.topic = "foo"}
  852. assert_nothing_raised {o.topic = "foo"}
  853. assert_equal("foo", t.topic)
  854. assert_raises(NoMethodError) {t.join("foo")}
  855. assert_nothing_raised {o.join("foo")}
  856. assert_raises(NoMethodError) {t.leave("foo")}
  857. assert_raises(NoMethodError) {t.set_oper("foo", true)}
  858. assert_equal(false, t.has_oper?("foo"))
  859. assert_nothing_raised {o.set_oper("foo", true)}
  860. assert_equal(true, t.has_oper?("foo"))
  861. assert_raises(NoMethodError) {t.clear_oper}
  862. assert_raises(NoMethodError) {t.set_voice("foo", true)}
  863. assert_equal(false, t.has_voice?("foo"))
  864. assert_nothing_raised {o.set_voice("foo", true)}
  865. assert_equal(true, t.has_voice?("foo"))
  866. assert_raises(NoMethodError) {t.clear_voice}
  867. assert_raises(NoMethodError) {t.change_nick("foo","bar")}
  868. assert_raises(NoMethodError) {t.set_mode("+t")}
  869. assert_raises(NoMethodError) {t.clear_mode}
  870. assert_nothing_raised {o.set_mode("+tn")}
  871. assert_equal("+ovtn foo foo", t.mode_string)
  872. end # def test_functional
  873. end # class TestPRUNE__ChannelStateReadOnly
  874. class TestPRUNE__IRCStateReadOnly < Test::Unit::TestCase
  875. class << self
  876. def set_msg(msg)
  877. @@msg = msg
  878. end # def set_msg
  879. def get_msg
  880. @@msg
  881. end # def get_msg
  882. end
  883. def setup
  884. @@msg = nil
  885. def PRUNE._output(msg)
  886. TestPRUNE__IRCStateReadOnly.set_msg(msg)
  887. end # def
  888. end # def setup
  889. def teardown
  890. def PRUNE._output(msg)
  891. Kernel.printf("%s\n", msg)
  892. end # def
  893. end # def teardown
  894. def test_functional
  895. assert_nothing_raised {t = PRUNE::IRCStateReadOnly.new(PRUNE::IRCState.new("nick", "user", "name", "host"))}
  896. assert_raises(ArgumentError) {t = PRUNE::IRCStateReadOnly.new(0)}
  897. o = PRUNE::IRCState.new("nick", "user", "name", "host")
  898. t = PRUNE::IRCStateReadOnly.new(o)
  899. assert_equal("nick", t.nick)
  900. assert_raises(NoMethodError) {t.nick = "bar"}
  901. assert_nothing_raised {o.nick = "bar"}
  902. assert_equal("bar", t.nick)
  903. assert_raises(NoMethodError) {t.connected = true}
  904. assert_raises(NoMethodError) {t.listened = true}
  905. assert_raises(NoMethodError) {t.authenticated = true}
  906. assert_raises(NoMethodError) {t.loggedin = true}
  907. assert_raises(NoMethodError) {t.quit("foo")}
  908. assert_raises(NoMethodError) {t.set_mode("+a")}
  909. assert_raises(NoMethodError) {t.clear_mode}
  910. assert_equal("+", t.mode_string)
  911. assert_nothing_raised {o.set_mode("+a")}
  912. assert_equal("+a", t.mode_string)
  913. end # def test_functional
  914. end # class TestPRUNE__IRCStateReadOnly
  915. if $0 == __FILE__ then
  916. begin
  917. require 'main'
  918. rescue LoadError
  919. require 'tests/main'
  920. end
  921. end