PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/composer.rb

https://bitbucket.org/tagoh/prune
Ruby | 79 lines | 42 code | 20 blank | 17 comment | 2 complexity | 1919ec4be001ffd6049d5e4847671d7c MD5 | raw file
Possible License(s): GPL-2.0
  1. # composer.rb
  2. # Copyright (C) 2010 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/composer'
  21. require 'prune/message'
  22. class TestPRUNE__MessageComposer < Test::Unit::TestCase
  23. def setup
  24. @t = PRUNE::MessageComposer.new
  25. end # def setup
  26. def teardown
  27. end # def teardown
  28. def test_functional
  29. assert_nothing_raised {t = PRUNE::MessageComposer.new}
  30. assert_nothing_raised {t = PRUNE::MessageComposer.new("__PARAM__")}
  31. end # def test_functional
  32. def test_format_
  33. # should be done in test_each_symbol.
  34. end # def test_format_
  35. def test_each_symbol
  36. assert_nothing_raised {@t.format = "\\A__COMMAND__\\Z"}
  37. assert_equal(["__COMMAND__"], @t.each_symbol {|x|})
  38. assert_nothing_raised {@t.format = "\\A__COMMAND__ __PARAMS__\\Z"}
  39. assert_equal(["__COMMAND__", "__PARAMS__"], @t.each_symbol {|x|})
  40. end # def test_each_symbol
  41. def test_parse
  42. assert_nothing_raised {@t.format = "\\A__COMMAND__ __PARAMS__\\Z"}
  43. assert_equal(["abc", "def"], @t.parse(PRUNE::Message::PRIVMSG.new("#foo", "abc def")).map {|k, v| v})
  44. assert_equal(nil, @t.parse(PRUNE::Message::PRIVMSG.new("#foo", "abc")))
  45. assert_nothing_raised {@t.format = "\\A__COMMAND__(?:\\Z| __PARAMS__)"}
  46. assert_nothing_raised {@t.parse(PRUNE::Message::PRIVMSG.new("#foo", "blahblah(blahblah"))}
  47. assert_equal({"__COMMAND__"=>"blahblah(blahblah"}, @t.parse(PRUNE::Message::PRIVMSG.new("#foo", "blahblah(blahblah")))
  48. assert_equal(["abc(abc", "def"], @t.parse(PRUNE::Message::PRIVMSG.new("#foo", "abc(abc def")).map {|k, v| v})
  49. end # def test_parse
  50. def test_compose
  51. end # def test_compose
  52. end # class TestPRUNE__MessageComposer
  53. if $0 == __FILE__ then
  54. begin
  55. require 'main'
  56. rescue LoadError
  57. require 'tests/main'
  58. end
  59. end