From 75bc5455af8c3c3381066aac3d5fff42264cac6f Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Fri, 19 Aug 2011 03:09:35 +0200 Subject: Major rewrite of encoders to support IO output; fixed some minor scanner bugs; cleanups; dropped NitroXHTML scanner; improved tests --- test/functional/basic.rb | 41 ++++++++++++++++++++++++++--------------- test/functional/examples.rb | 2 ++ test/functional/for_redcloth.rb | 18 ++++++++++++------ test/functional/suite.rb | 3 ++- 4 files changed, 42 insertions(+), 22 deletions(-) (limited to 'test/functional') diff --git a/test/functional/basic.rb b/test/functional/basic.rb index 94e1dd7..8200ae4 100755 --- a/test/functional/basic.rb +++ b/test/functional/basic.rb @@ -1,21 +1,12 @@ # encoding: utf-8 require 'test/unit' +require File.expand_path('../../lib/assert_warning', __FILE__) + +$:.unshift File.expand_path('../../../lib', __FILE__) require 'coderay' class BasicTest < Test::Unit::TestCase - 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 - def test_version assert_nothing_raised do assert_match(/\A\d\.\d\.\d?\z/, CodeRay::VERSION) @@ -135,7 +126,7 @@ more code # and another comment, in-line. assert_equal 0, CodeRay.scan(rHTML, :html).lines_of_code assert_equal 0, CodeRay.scan(rHTML, :php).lines_of_code assert_equal 0, CodeRay.scan(rHTML, :yaml).lines_of_code - assert_equal 4, CodeRay.scan(rHTML, :rhtml).lines_of_code + assert_equal 4, CodeRay.scan(rHTML, :erb).lines_of_code end def test_rubygems_not_loaded @@ -243,8 +234,28 @@ more code # and another comment, in-line. scanner = CodeRay::Scanners::Plain.new "foo\nbär+quux" assert_equal 0, scanner.pos assert_equal 1, scanner.line - assert_equal 0, scanner.column - scanner.scan(/foo\nbär/) + assert_equal 1, scanner.column + scanner.scan(/foo/) + assert_equal 3, scanner.pos + assert_equal 1, scanner.line + assert_equal 4, scanner.column + scanner.scan(/\n/) + assert_equal 4, scanner.pos + assert_equal 2, scanner.line + assert_equal 1, scanner.column + scanner.scan(/b/) + assert_equal 5, scanner.pos + assert_equal 2, scanner.line + assert_equal 2, scanner.column + scanner.scan(/a/) + assert_equal 5, scanner.pos + assert_equal 2, scanner.line + assert_equal 2, scanner.column + scanner.scan(/ä/) + assert_equal 7, scanner.pos + assert_equal 2, scanner.line + assert_equal 4, scanner.column + scanner.scan(/r/) assert_equal 8, scanner.pos assert_equal 2, scanner.line assert_equal 5, scanner.column diff --git a/test/functional/examples.rb b/test/functional/examples.rb index f80c90c..3de8be5 100755 --- a/test/functional/examples.rb +++ b/test/functional/examples.rb @@ -1,4 +1,6 @@ require 'test/unit' + +$:.unshift File.expand_path('../../../lib', __FILE__) require 'coderay' class ExamplesTest < Test::Unit::TestCase diff --git a/test/functional/for_redcloth.rb b/test/functional/for_redcloth.rb index 8c6491d..3c45eec 100644 --- a/test/functional/for_redcloth.rb +++ b/test/functional/for_redcloth.rb @@ -1,5 +1,7 @@ require 'test/unit' -$:.unshift 'lib' +require File.expand_path('../../lib/assert_warning', __FILE__) + +$:.unshift File.expand_path('../../../lib', __FILE__) require 'coderay' begin @@ -64,15 +66,19 @@ class BasicTest < Test::Unit::TestCase # See http://jgarber.lighthouseapp.com/projects/13054/tickets/124-code-markup-does-not-allow-brackets. def test_for_redcloth_false_positive require 'coderay/for_redcloth' - assert_equal '

[project]_dff.skjd

', - RedCloth.new('@[project]_dff.skjd@').to_html + assert_warning 'CodeRay::Scanners could not load plugin :project; falling back to :text' do + assert_equal '

[project]_dff.skjd

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

_dff.skjd

", RedCloth.new('@[ruby]_dff.skjd@').to_html - assert_equal <<-BLOCKCODE.chomp, + assert_warning 'CodeRay::Scanners could not load plugin :project; falling back to :text' do + assert_equal <<-BLOCKCODE.chomp,
[project]_dff.skjd
- BLOCKCODE - RedCloth.new('bc. [project]_dff.skjd').to_html + BLOCKCODE + RedCloth.new('bc. [project]_dff.skjd').to_html + end end end if defined? RedCloth \ No newline at end of file diff --git a/test/functional/suite.rb b/test/functional/suite.rb index 6d795c0..5490f98 100755 --- a/test/functional/suite.rb +++ b/test/functional/suite.rb @@ -1,5 +1,6 @@ require 'test/unit' -$:.unshift 'lib' + +$:.unshift File.expand_path('../../../lib', __FILE__) require 'coderay' mydir = File.dirname(__FILE__) -- cgit v1.2.1