From ce3a6c7bcc0b7efac4844de859d8c8364476ab0d Mon Sep 17 00:00:00 2001 From: Etienne Massip Date: Thu, 29 Mar 2012 20:47:18 +0200 Subject: Added a unit test for HTML encoder (with a test for :line_independent option) --- test/unit/html.rb | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 test/unit/html.rb (limited to 'test/unit') diff --git a/test/unit/html.rb b/test/unit/html.rb new file mode 100644 index 0000000..f6e3d7e --- /dev/null +++ b/test/unit/html.rb @@ -0,0 +1,104 @@ +require 'test/unit' +require 'coderay' + +class HtmlTest < Test::Unit::TestCase + + def test_independent_lines_option + + snippets = {} + + snippets[:ruby] = {} + + snippets[:ruby][:in] = <<-RUBY +ruby_inside = <<-RUBY_INSIDE +This is tricky, +isn't it? +RUBY_INSIDE + RUBY + + snippets[:ruby][:expected_with_option_off] = <<-HTML_OPT_INDEPENDENT_LINES_OFF +ruby_inside = <<-RUBY_INSIDE +This is tricky, +isn't it? +RUBY_INSIDE + HTML_OPT_INDEPENDENT_LINES_OFF + + snippets[:ruby][:expected_with_option_on] = <<-HTML_OPT_INDEPENDENT_LINES_ON +ruby_inside = <<-RUBY_INSIDE +This is tricky, +isn't it? +RUBY_INSIDE + HTML_OPT_INDEPENDENT_LINES_ON + + snippets[:java] = {} + + snippets[:java][:in] = <<-JAVA +import java.lang.*; + +/** + * This is some multiline javadoc + * used to test the + */ +public class Test { + public static final String MESSAGE = "My message\ + To the world"; + + static void main() { + /* + * Another multiline + * comment + */ + System.out.println(MESSAGE); + } +} + JAVA + + snippets[:java][:expected_with_option_off] = <<-HTML_OPT_INDEPENDENT_LINES_OFF +import java.lang.*; + +/** + * This is some multiline javadoc + * used to test the + */ +public class Test { + public static final String MESSAGE = "My message To the world"; + + static void main() { + /* + * Another multiline + * comment + */ + System.out.println(MESSAGE); + } +} + HTML_OPT_INDEPENDENT_LINES_OFF + + snippets[:java][:expected_with_option_on] = <<-HTML_OPT_INDEPENDENT_LINES_ON +import java.lang.*; + +/** + * This is some multiline javadoc + * used to test the + */ +public class Test { + public static final String MESSAGE = "My message To the world"; + + static void main() { + /* + * Another multiline + * comment + */ + System.out.println(MESSAGE); + } +} + HTML_OPT_INDEPENDENT_LINES_ON + + snippets.entries().each do |lang, code| + tokens = CodeRay.scan code[:in], lang + + assert_equal code[:expected_with_option_off], tokens.html + assert_equal code[:expected_with_option_off], tokens.html(:independent_lines => false) + assert_equal code[:expected_with_option_on], tokens.html(:independent_lines => true) + end + end +end \ No newline at end of file -- cgit v1.2.1