From 228726f6bfed89b86fb985d554040f91de776840 Mon Sep 17 00:00:00 2001 From: murphy Date: Fri, 1 Jan 2010 04:44:10 +0000 Subject: Cleaning up functional tests; test:functional scans without loading Rubygems now. --- rake_tasks/test.rake | 8 +++- test/functional/basic.rb | 78 ++---------------------------------- test/functional/for_redcloth.rb | 87 +++++++++++++++++++++++++++++++++++++++++ test/functional/suite.rb | 3 +- test/functional/vhdl.rb | 2 +- 5 files changed, 100 insertions(+), 78 deletions(-) create mode 100644 test/functional/for_redcloth.rb diff --git a/rake_tasks/test.rake b/rake_tasks/test.rake index bb22f36..ebde606 100644 --- a/rake_tasks/test.rake +++ b/rake_tasks/test.rake @@ -25,6 +25,11 @@ namespace :test do end end + desc 'run for_redcloth tests' + task :for_redcloth do + ruby "./test/functional/for_redcloth.rb" + end + desc 'run all scanner tests' task :scanners do ruby "./test/scanners/suite.rb" @@ -60,6 +65,7 @@ namespace :test do ruby '-v' Rake::Task['test'].reenable Rake::Task['test:functional'].reenable + Rake::Task['test:for_redcloth'].reenable Rake::Task['test:scanners'].reenable Rake::Task['test'].invoke else @@ -70,5 +76,5 @@ namespace :test do end -task :test => %w( test:functional test:scanners ) +task :test => %w( test:functional test:for_redcloth test:scanners ) task :samples => 'test:samples' \ No newline at end of file diff --git a/test/functional/basic.rb b/test/functional/basic.rb index bbf6d7a..6eb9782 100755 --- a/test/functional/basic.rb +++ b/test/functional/basic.rb @@ -90,81 +90,9 @@ more code # and another comment, in-line. assert_equal 4, CodeRay.scan(rHTML, :rhtml).lines_of_code end - begin - require 'rubygems' - gem 'RedCloth', '>= 4.0.3' rescue nil - require 'redcloth' - - def test_for_redcloth - require 'rubygems' - require 'coderay/for_redcloth' - assert_equal "

puts "Hello, World!"

", - RedCloth.new('@[ruby]puts "Hello, World!"@').to_html - assert_equal <<-BLOCKCODE.chomp, -
-
puts "Hello, World!"
-
- BLOCKCODE - RedCloth.new('bc[ruby]. puts "Hello, World!"').to_html - end - - def test_for_redcloth_no_lang - require 'rubygems' - require 'coderay/for_redcloth' - assert_equal "

puts \"Hello, World!\"

", - RedCloth.new('@puts "Hello, World!"@').to_html - assert_equal <<-BLOCKCODE.chomp, -
puts \"Hello, World!\"
- BLOCKCODE - RedCloth.new('bc. puts "Hello, World!"').to_html - end - - def test_for_redcloth_style - require 'rubygems' - require 'coderay/for_redcloth' - assert_equal <<-BLOCKCODE.chomp, -
puts \"Hello, World!\"
- BLOCKCODE - RedCloth.new('bc{color: red}. puts "Hello, World!"').to_html - end - - def test_for_redcloth_escapes - require 'rubygems' - require 'coderay/for_redcloth' - assert_equal '

>

', - RedCloth.new('@[ruby]>@').to_html - assert_equal <<-BLOCKCODE.chomp, -
-
&
-
- BLOCKCODE - RedCloth.new('bc[ruby]. &').to_html - end - - def test_for_redcloth_escapes2 - require 'rubygems' - require 'coderay/for_redcloth' - assert_equal "

#include <test.h>

", - RedCloth.new('@[c]#include @').to_html - end - - # See http://jgarber.lighthouseapp.com/projects/13054/tickets/124-code-markup-does-not-allow-brackets. - def test_for_redcloth_false_positive - require 'rubygems' - require 'coderay/for_redcloth' - assert_equal '

[project]_dff.skjd

', - RedCloth.new('@[project]_dff.skjd@').to_html - # false positive, but expected behavior / known issue - assert_equal "

_dff.skjd

", - RedCloth.new('@[ruby]_dff.skjd@').to_html - assert_equal <<-BLOCKCODE.chomp, -
[project]_dff.skjd
- BLOCKCODE - RedCloth.new('bc. [project]_dff.skjd').to_html - end - rescue LoadError - $stderr.puts 'RedCloth not found - skipping for_redcloth tests.' - end + def test_rubygems_not_loaded + assert_equal nil, defined? Gem + end unless RUBY_VERSION >= '1.9' def test_list_of_encoders assert_kind_of(Array, CodeRay::Encoders.list) diff --git a/test/functional/for_redcloth.rb b/test/functional/for_redcloth.rb new file mode 100644 index 0000000..e955e30 --- /dev/null +++ b/test/functional/for_redcloth.rb @@ -0,0 +1,87 @@ +require "test/unit" + +require 'pathname' +MYDIR = File.dirname(__FILE__) +LIBDIR = Pathname.new(MYDIR).join('..', '..', 'lib').cleanpath.to_s +$LOAD_PATH.unshift LIBDIR +require "coderay" + +begin + require 'rubygems' + gem 'RedCloth', '>= 4.0.3' rescue nil + require 'redcloth' +rescue LoadError + $stderr.puts 'RedCloth not found - skipping for_redcloth tests.' +end + +class BasicTest < Test::Unit::TestCase + + def test_for_redcloth + require 'rubygems' + require 'coderay/for_redcloth' + assert_equal "

puts "Hello, World!"

", + RedCloth.new('@[ruby]puts "Hello, World!"@').to_html + assert_equal <<-BLOCKCODE.chomp, +
+
puts "Hello, World!"
+
+ BLOCKCODE + RedCloth.new('bc[ruby]. puts "Hello, World!"').to_html + end + + def test_for_redcloth_no_lang + require 'rubygems' + require 'coderay/for_redcloth' + assert_equal "

puts \"Hello, World!\"

", + RedCloth.new('@puts "Hello, World!"@').to_html + assert_equal <<-BLOCKCODE.chomp, +
puts \"Hello, World!\"
+ BLOCKCODE + RedCloth.new('bc. puts "Hello, World!"').to_html + end + + def test_for_redcloth_style + require 'rubygems' + require 'coderay/for_redcloth' + assert_equal <<-BLOCKCODE.chomp, +
puts \"Hello, World!\"
+ BLOCKCODE + RedCloth.new('bc{color: red}. puts "Hello, World!"').to_html + end + + def test_for_redcloth_escapes + require 'rubygems' + require 'coderay/for_redcloth' + assert_equal '

>

', + RedCloth.new('@[ruby]>@').to_html + assert_equal <<-BLOCKCODE.chomp, +
+
&
+
+ BLOCKCODE + RedCloth.new('bc[ruby]. &').to_html + end + + def test_for_redcloth_escapes2 + require 'rubygems' + require 'coderay/for_redcloth' + assert_equal "

#include <test.h>

", + RedCloth.new('@[c]#include @').to_html + end + + # See http://jgarber.lighthouseapp.com/projects/13054/tickets/124-code-markup-does-not-allow-brackets. + def test_for_redcloth_false_positive + require 'rubygems' + require 'coderay/for_redcloth' + assert_equal '

[project]_dff.skjd

', + RedCloth.new('@[project]_dff.skjd@').to_html + # false positive, but expected behavior / known issue + assert_equal "

_dff.skjd

", + RedCloth.new('@[ruby]_dff.skjd@').to_html + assert_equal <<-BLOCKCODE.chomp, +
[project]_dff.skjd
+ BLOCKCODE + RedCloth.new('bc. [project]_dff.skjd').to_html + end + +end if defined? RedCloth \ No newline at end of file diff --git a/test/functional/suite.rb b/test/functional/suite.rb index 6c6d625..ae9c7f0 100755 --- a/test/functional/suite.rb +++ b/test/functional/suite.rb @@ -1,9 +1,10 @@ require 'test/unit' -require 'pathname' +require 'pathname' MYDIR = File.dirname(__FILE__) LIBDIR = Pathname.new(MYDIR).join('..', '..', 'lib').cleanpath.to_s $LOAD_PATH.unshift MYDIR, LIBDIR require 'basic' +require 'load_plugin_scanner' require 'word_list' diff --git a/test/functional/vhdl.rb b/test/functional/vhdl.rb index fb4b4e1..c7e3824 100644 --- a/test/functional/vhdl.rb +++ b/test/functional/vhdl.rb @@ -34,7 +34,7 @@ class VHDL < CodeRay::Scanners::Scanner add(PREDEFINED_TYPES, :pre_type). add(PREDEFINED_CONSTANTS, :pre_constant) - ESCAPE = / [rbfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x + ESCAPE = / [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x def scan_tokens tokens, options -- cgit v1.2.1