diff options
author | murphy <murphy@rubychan.de> | 2011-02-28 23:10:25 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2011-02-28 23:10:25 +0000 |
commit | 4d8afef1c46d1db99a7c71bc71906317441a90c3 (patch) | |
tree | 18bf4a476168de72959705aae7ff6a0ef6a4d2a5 /test/unit/plugin.rb | |
parent | fa8b580bfcf1082ac671acde60c4205681dec1dd (diff) | |
download | coderay-4d8afef1c46d1db99a7c71bc71906317441a90c3.tar.gz |
Added lots of tests for Plugin and other helper classes.
Diffstat (limited to 'test/unit/plugin.rb')
-rwxr-xr-x | test/unit/plugin.rb | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/test/unit/plugin.rb b/test/unit/plugin.rb index 25bbc93..ee3e2cc 100755 --- a/test/unit/plugin.rb +++ b/test/unit/plugin.rb @@ -1,11 +1,79 @@ require 'test/unit' require 'coderay' +require 'pathname' class PluginScannerTest < Test::Unit::TestCase + module Plugins + extend CodeRay::PluginHost + plugin_path File.dirname(__FILE__), 'plugins' + class Plugin + extend CodeRay::Plugin + plugin_host Plugins + end + end + + module PluginsWithDefault + extend CodeRay::PluginHost + plugin_path File.dirname(__FILE__), 'plugins_with_default' + class Plugin + extend CodeRay::Plugin + plugin_host PluginsWithDefault + end + default :default + end + def test_load - require File.join(File.dirname(__FILE__), 'vhdl') - assert_equal 'VHDL', CodeRay.scanner(:vhdl).class.name + require Pathname.new(__FILE__).realpath.dirname + 'plugins' + 'user_defined' + 'user_plugin' + assert_equal 'UserPlugin', Plugins.load(:user_plugin).name + end + + def test_load_all + assert_instance_of Symbol, Plugins.load_all.first + assert_operator Plugins.all_plugins.first, :<, Plugins::Plugin + assert_equal 'The Example', Plugins.all_titles.sort.first + end + + def test_default + assert_nothing_raised do + assert_operator PluginsWithDefault[:gargamel], :<, PluginsWithDefault::Plugin + end + assert_equal PluginsWithDefault::Default, PluginsWithDefault.default + end + + def test_plugin_not_found + assert_raise CodeRay::PluginHost::PluginNotFound do + Plugins[:thestral] + end + assert_raise ArgumentError do + Plugins[14] + end + assert_raise ArgumentError do + Plugins['test/test'] + end + assert_raise CodeRay::PluginHost::PluginNotFound do + PluginsWithDefault[:example_without_register_for] + end + end + + def test_autoload_constants + assert_operator Plugins::Example, :<, Plugins::Plugin + end + + def test_title + assert_equal 'The Example', Plugins::Example.title + end + + def assert_warning expected_warning + require 'stringio' + oldstderr = $stderr + $stderr = StringIO.new + yield + $stderr.rewind + given_warning = $stderr.read.chomp + assert_equal expected_warning, given_warning + ensure + $stderr = oldstderr end end |