1+ require 'test/unit'
2+ require 'coderay'
3+
4+ class HtmlTest <Test ::Unit ::TestCase
5+
6+ def test_independent_lines_option
7+
8+ snippets = { }
9+
10+ snippets [ :ruby ] = { }
11+
12+ snippets [ :ruby ] [ :in ] = <<-RUBY
13+ ruby_inside = <<-RUBY_INSIDE
14+ This is tricky,
15+ isn't it?
16+ RUBY_INSIDE
17+ RUBY
18+
19+ snippets [ :ruby ] [ :expected_with_option_off ] = <<-HTML_OPT_INDEPENDENT_LINES_OFF
20+ ruby_inside = <span class=\" string\" ><span class=\" delimiter\" ><<-RUBY_INSIDE</span></span><span class=\" string\" ><span class=\" content\" >
21+ This is tricky,
22+ isn't it?</span><span class=\" delimiter\" >
23+ RUBY_INSIDE</span></span>
24+ HTML_OPT_INDEPENDENT_LINES_OFF
25+
26+ snippets [ :ruby ] [ :expected_with_option_on ] = <<-HTML_OPT_INDEPENDENT_LINES_ON
27+ ruby_inside = <span class=\" string\" ><span class=\" delimiter\" ><<-RUBY_INSIDE</span></span><span class=\" string\" ><span class=\" content\" ></span></span>
28+ <span class=\" string\" ><span class=\" content\" >This is tricky,</span></span>
29+ <span class=\" string\" ><span class=\" content\" >isn't it?</span><span class=\" delimiter\" ></span></span>
30+ <span class=\" string\" ><span class=\" delimiter\" >RUBY_INSIDE</span></span>
31+ HTML_OPT_INDEPENDENT_LINES_ON
32+
33+ snippets [ :java ] = { }
34+
35+ snippets [ :java ] [ :in ] = <<-JAVA
36+ import java.lang.*;
37+
38+ /**
39+ * This is some multiline javadoc
40+ * used to test the
41+ */
42+ public class Test {
43+ public static final String MESSAGE = "My message\
44+ To the world";
45+
46+ static void main() {
47+ /*
48+ * Another multiline
49+ * comment
50+ */
51+ System.out.println(MESSAGE);
52+ }
53+ }
54+ JAVA
55+
56+ snippets [ :java ] [ :expected_with_option_off ] = <<-HTML_OPT_INDEPENDENT_LINES_OFF
57+ <span class=\" keyword\" >import</span> <span class=\" include\" >java.lang</span>.*;
58+
59+ <span class=\" comment\" >/**
60+ * This is some multiline javadoc
61+ * used to test the
62+ */</span>
63+ <span class=\" directive\" >public</span> <span class=\" type\" >class</span> <span class=\" class\" >Test</span> {
64+ <span class=\" directive\" >public</span> <span class=\" directive\" >static</span> <span class=\" directive\" >final</span> <span class=\" predefined-type\" >String</span> MESSAGE = <span class=\" string\" ><span class=\" delimiter\" >"</span><span class=\" content\" >My message To the world</span><span class=\" delimiter\" >"</span></span>;
65+
66+ <span class=\" directive\" >static</span> <span class=\" type\" >void</span> main() {
67+ <span class=\" comment\" >/*
68+ * Another multiline
69+ * comment
70+ */</span>
71+ <span class=\" predefined-type\" >System</span>.out.println(MESSAGE);
72+ }
73+ }
74+ HTML_OPT_INDEPENDENT_LINES_OFF
75+
76+ snippets [ :java ] [ :expected_with_option_on ] = <<-HTML_OPT_INDEPENDENT_LINES_ON
77+ <span class=\" keyword\" >import</span> <span class=\" include\" >java.lang</span>.*;
78+
79+ <span class=\" comment\" >/**</span>
80+ <span class=\" comment\" > * This is some multiline javadoc</span>
81+ <span class=\" comment\" > * used to test the</span>
82+ <span class=\" comment\" > */</span>
83+ <span class=\" directive\" >public</span> <span class=\" type\" >class</span> <span class=\" class\" >Test</span> {
84+ <span class=\" directive\" >public</span> <span class=\" directive\" >static</span> <span class=\" directive\" >final</span> <span class=\" predefined-type\" >String</span> MESSAGE = <span class=\" string\" ><span class=\" delimiter\" >"</span><span class=\" content\" >My message To the world</span><span class=\" delimiter\" >"</span></span>;
85+
86+ <span class=\" directive\" >static</span> <span class=\" type\" >void</span> main() {
87+ <span class=\" comment\" >/*</span>
88+ <span class=\" comment\" > * Another multiline</span>
89+ <span class=\" comment\" > * comment</span>
90+ <span class=\" comment\" > */</span>
91+ <span class=\" predefined-type\" >System</span>.out.println(MESSAGE);
92+ }
93+ }
94+ HTML_OPT_INDEPENDENT_LINES_ON
95+
96+ snippets . entries ( ) . each do |lang , code |
97+ tokens = CodeRay . scan code [ :in ] , lang
98+
99+ assert_equal code [ :expected_with_option_off ] , tokens . html
100+ assert_equal code [ :expected_with_option_off ] , tokens . html ( :independent_lines => false )
101+ assert_equal code [ :expected_with_option_on ] , tokens . html ( :independent_lines => true )
102+ end
103+ end
104+ end