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 From d385eff0109b890dccb3ae209b84bdd4fdd9b43d Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sat, 31 Mar 2012 21:38:09 +0200 Subject: fix tests for #16 --- test/unit/file_type.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/unit') diff --git a/test/unit/file_type.rb b/test/unit/file_type.rb index 607e30a..263517b 100644 --- a/test/unit/file_type.rb +++ b/test/unit/file_type.rb @@ -63,9 +63,9 @@ class FileTypeTests < Test::Unit::TestCase end def test_html - assert_equal :page, FileType['test.htm'] - assert_equal :page, FileType['test.xhtml'] - assert_equal :page, FileType['test.html.xhtml'] + assert_equal :html, FileType['test.htm'] + assert_equal :html, FileType['test.xhtml'] + assert_equal :html, FileType['test.html.xhtml'] assert_equal :erb, FileType['_form.rhtml'] assert_equal :erb, FileType['_form.html.erb'] end -- cgit v1.2.1 From df4e2bc7f7d8238f56e2d823aea707bfd860ad8f Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 1 Apr 2012 00:28:15 +0200 Subject: here come the white-space nazis --- test/unit/html.rb | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'test/unit') diff --git a/test/unit/html.rb b/test/unit/html.rb index f6e3d7e..cc4a0c6 100644 --- a/test/unit/html.rb +++ b/test/unit/html.rb @@ -2,36 +2,35 @@ 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 - + 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 - + 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 - + HTML_OPT_INDEPENDENT_LINES_ON + snippets[:java] = {} - + snippets[:java][:in] = <<-JAVA import java.lang.*; @@ -51,8 +50,8 @@ public class Test { System.out.println(MESSAGE); } } - JAVA - + JAVA + snippets[:java][:expected_with_option_off] = <<-HTML_OPT_INDEPENDENT_LINES_OFF import java.lang.*; @@ -71,8 +70,8 @@ public class Test { System.out.println(MESSAGE); } } - HTML_OPT_INDEPENDENT_LINES_OFF - + HTML_OPT_INDEPENDENT_LINES_OFF + snippets[:java][:expected_with_option_on] = <<-HTML_OPT_INDEPENDENT_LINES_ON import java.lang.*; @@ -91,14 +90,14 @@ public class Test { System.out.println(MESSAGE); } } - HTML_OPT_INDEPENDENT_LINES_ON - - snippets.entries().each do |lang, code| + HTML_OPT_INDEPENDENT_LINES_ON + + for lang, code in snippets 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 +end -- cgit v1.2.1 From 5c4124559127f8ce991e31e4ea8a40516fe0757a Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Mon, 2 Apr 2012 00:15:20 +0200 Subject: rename :independent_lines option to :break_lines --- test/unit/html.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/unit') diff --git a/test/unit/html.rb b/test/unit/html.rb index cc4a0c6..0072635 100644 --- a/test/unit/html.rb +++ b/test/unit/html.rb @@ -3,7 +3,7 @@ require 'coderay' class HtmlTest < Test::Unit::TestCase - def test_independent_lines_option + def test_break_lines_option snippets = {} snippets[:ruby] = {} @@ -96,8 +96,8 @@ public class Test { 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) + assert_equal code[:expected_with_option_off], tokens.html(:break_lines => false) + assert_equal code[:expected_with_option_on], tokens.html(:break_lines => true) end end end -- cgit v1.2.1