PageRenderTime 37ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/parser.rb

https://bitbucket.org/tagoh/prune
Ruby | 150 lines | 119 code | 14 blank | 17 comment | 8 complexity | 65302a297cf76a044941bf063493a667 MD5 | raw file
Possible License(s): GPL-2.0
  1. # -*- encoding: utf-8 -*-
  2. # parser.rb
  3. # Copyright (C) 2009 Akira TAGOH
  4. # Authors:
  5. # Akira TAGOH <tagoh@redhat.com>
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 59 Temple Place - Suite 330,
  17. # Boston, MA 02111-1307, USA.
  18. require 'rubygems'
  19. gem 'test-unit'
  20. require 'test/unit/testcase'
  21. require 'prune/parser'
  22. class TestPRUNE__Parser < Test::Unit::TestCase
  23. def setup
  24. @t = PRUNE::Parser.new
  25. def @t.raw_parse(data)
  26. msg = parse(data)
  27. raw = msg.__send__(:instance_variable_get, "@message")
  28. raw.delete(:time)
  29. raw
  30. end
  31. end # def setup
  32. def teardown
  33. end # def teardown
  34. def test_functional
  35. assert_nothing_raised {t = PRUNE::Parser.new}
  36. end # def test_functional
  37. def test_parse
  38. assert_nothing_raised {@t.raw_parse(":freenode-connect!freenode@freenode/bot/connect PRIVMSG prunetest :VERSION\r\n")}
  39. assert_equal({
  40. :prefix=>{
  41. :nick=>'freenode-connect',
  42. :user=>'freenode',
  43. :host=>'freenode/bot/connect'},
  44. :command=>'PRIVMSG',
  45. :params=>["prunetest", "VERSION"],
  46. :suffix=>''},
  47. @t.raw_parse(":freenode-connect!freenode@freenode/bot/connect PRIVMSG prunetest :VERSION\r\n"))
  48. assert_nothing_raised {@t.raw_parse(":minori.linux.or.jp 252 prunetest 1 :flagged staff members\r\n")}
  49. assert_equal({
  50. :prefix=>{
  51. :nick=>nil,
  52. :user=>nil,
  53. :host=>'minori.linux.or.jp'},
  54. :command=>'252',
  55. :params=>["prunetest", "1", "flagged staff members"],
  56. :suffix=>''},
  57. @t.raw_parse(":minori.linux.or.jp 252 prunetest 1 :flagged staff members\r\n"))
  58. assert_nothing_raised {@t.raw_parse(":christel!i=christel@freenode/staff/exherbo.christel NOTICE $* :[Global Notice] Hi all, unfortunately one of our former developers has left behind a memory leak in our ircd software which means we'll need to restart several ircds over the next few days. We're going to stagger it to reduce disruption, and the first round will be happening very shortly. Affected users for now will be about 1300. Apologies for the inconvenience!\r\n")}
  59. assert_equal({
  60. :prefix=>{
  61. :nick=>'christel',
  62. :user=>'christel',
  63. :host=>'freenode/staff/exherbo.christel'},
  64. :command=>'NOTICE',
  65. :params=>["$*", "[Global Notice] Hi all, unfortunately one of our former developers has left behind a memory leak in our ircd software which means we'll need to restart several ircds over the next few days. We're going to stagger it to reduce disruption, and the first round will be happening very shortly. Affected users for now will be about 1300. Apologies for the inconvenience!"],
  66. :suffix=>''},
  67. @t.raw_parse(":christel!i=christel@freenode/staff/exherbo.christel NOTICE $* :[Global Notice] Hi all, unfortunately one of our former developers has left behind a memory leak in our ircd software which means we'll need to restart several ircds over the next few days. We're going to stagger it to reduce disruption, and the first round will be happening very shortly. Affected users for now will be about 1300. Apologies for the inconvenience!\r\n"))
  68. assert_nothing_raised {@t.raw_parse(":timmy!~tboisver@dhcp-193-203.nrt.redhat.com PRIVMSG #japan : :)\r\n")}
  69. assert_equal({
  70. :prefix=>{
  71. :nick=>'timmy',
  72. :user=>'~tboisver',
  73. :host=>'dhcp-193-203.nrt.redhat.com'},
  74. :command=>'PRIVMSG',
  75. :params=>["#japan", " :)"],
  76. :suffix=>''},
  77. @t.raw_parse(":timmy!~tboisver@dhcp-193-203.nrt.redhat.com PRIVMSG #japan : :)\r\n"))
  78. assert_nothing_raised {@t.raw_parse("PRIVMSG #foo ::の\r\n")}
  79. assert_equal({
  80. :prefix=>{
  81. :nick=>nil,
  82. :user=>nil,
  83. :host=>nil},
  84. :command=>'PRIVMSG',
  85. :params=>["#foo", ":の"],
  86. :suffix=>''},
  87. @t.raw_parse("PRIVMSG #foo ::の\r\n"))
  88. assert_nothing_raised {@t.raw_parse(":buggbot!n=bugbot@landfill.bugzilla.org PRIVMSG #fedora-devel :Bug https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=527712 low, low, ---, sandmann, NEW, unnecessary dependency on pcsc-lite?\r\n")}
  89. assert_nothing_raised {@t.raw_parse(":BenjaminKreuter!n=Benjamin@c-24-125-42-219.hsdl.va.comcast.net QUIT :Read error: 110 (Connection timed out)\r\n")}
  90. assert_nothing_raised {@t.raw_parse(":npmccallum!n=npmccall@cpe-76-177-118-80.natcky.res.rr.com JOIN :#fedora-devel\r\n")}
  91. assert_nothing_raised {@t.raw_parse(":takuo!~takuo@irc6.airs.net PRIVMSG #Northeye :もぺ\r\n")}
  92. assert_raises {@t.raw_parse(":foo!foo@localhost.localdomain PRIVMSG #foo :�\r\n")}
  93. assert_nothing_raised {@t.raw_parse(":ratbox.services MODE #eng-services +o CHANSERV \r\n")}
  94. assert_nothing_raised {@t.raw_parse(":apt!~apt@irc6.airs.net NOTICE #せつない :7832 (株)バンダイナムコホールディングス 905 03+27(03+3.08%) 639,200 (11:00)\r\n")}
  95. assert_nothing_raised {@t.raw_parse(":mdomsch!~mdomsch@2001:1938:16a::2 JOIN :#fedora-meeting\r\n")}
  96. assert_nothing_raised {@t.raw_parse(":40FAAYSLG!~jsafrane@ip-89-103-131-92.karneval.cz JOIN :#fedora-devel\r\n")}
  97. @t.enable_identification(nil)
  98. assert_equal({
  99. :prefix=>{
  100. :nick=>'foo',
  101. :user=>'foo',
  102. :host=>'localhost'},
  103. :command=>'PRIVMSG',
  104. :params=>["#foo", "blahblahblah"],
  105. :identified=>false,
  106. :suffix=>''},
  107. @t.raw_parse(":foo!foo@localhost PRIVMSG #foo :-blahblahblah\r\n"))
  108. assert_equal({
  109. :prefix=>{
  110. :nick=>'foo',
  111. :user=>'foo',
  112. :host=>'localhost'},
  113. :command=>'PRIVMSG',
  114. :params=>["#foo", "-blahblahblah"],
  115. :identified=>false,
  116. :suffix=>''},
  117. @t.raw_parse(":foo!foo@localhost PRIVMSG #foo :--blahblahblah\r\n"))
  118. assert_equal({
  119. :prefix=>{
  120. :nick=>'foo',
  121. :user=>'foo',
  122. :host=>'localhost'},
  123. :command=>'PRIVMSG',
  124. :params=>["#foo", "blahblahblah"],
  125. :identified=>true,
  126. :suffix=>''},
  127. @t.raw_parse(":foo!foo@localhost PRIVMSG #foo :+blahblahblah\r\n"))
  128. end # def test_parse
  129. end # class TestPRUNE__Parser
  130. if $0 == __FILE__ then
  131. begin
  132. require 'main'
  133. rescue LoadError
  134. require 'tests/main'
  135. end
  136. end