summaryrefslogtreecommitdiff
path: root/test/unit/html.rb
blob: 9175a4fc8dad4133270c2f0209371a2d7585a5ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require 'test/unit'
require 'coderay'

class HtmlTest < Test::Unit::TestCase
  
  def normalize_html html
    html.gsub('&#39;', "'").gsub('&quot;', '"')
  end
  
  def test_break_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 = <span class=\"string\"><span class=\"delimiter\">&lt;&lt;-RUBY_INSIDE</span></span><span class=\"string\"><span class=\"content\">
This is tricky,
isn't it?</span><span class=\"delimiter\">
RUBY_INSIDE</span></span>
    HTML_OPT_INDEPENDENT_LINES_OFF
    
    snippets[:ruby][:expected_with_option_on] = <<-HTML_OPT_INDEPENDENT_LINES_ON
ruby_inside = <span class=\"string\"><span class=\"delimiter\">&lt;&lt;-RUBY_INSIDE</span></span><span class=\"string\"><span class=\"content\"></span></span>
<span class=\"string\"><span class=\"content\">This is tricky,</span></span>
<span class=\"string\"><span class=\"content\">isn't it?</span><span class=\"delimiter\"></span></span>
<span class=\"string\"><span class=\"delimiter\">RUBY_INSIDE</span></span>
    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
<span class=\"keyword\">import</span> <span class=\"include\">java.lang</span>.*;

<span class=\"comment\">/**
 * This is some multiline javadoc
 * used to test the
 */</span>
<span class=\"directive\">public</span> <span class=\"type\">class</span> <span class=\"class\">Test</span> {
  <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>;

  <span class=\"directive\">static</span> <span class=\"type\">void</span> main() {
    <span class=\"comment\">/*
     * Another multiline
     * comment
     */</span>
    <span class=\"predefined-type\">System</span>.out.println(MESSAGE);
  }
}
    HTML_OPT_INDEPENDENT_LINES_OFF
    
    snippets[:java][:expected_with_option_on] = <<-HTML_OPT_INDEPENDENT_LINES_ON
<span class=\"keyword\">import</span> <span class=\"include\">java.lang</span>.*;

<span class=\"comment\">/**</span>
<span class=\"comment\"> * This is some multiline javadoc</span>
<span class=\"comment\"> * used to test the</span>
<span class=\"comment\"> */</span>
<span class=\"directive\">public</span> <span class=\"type\">class</span> <span class=\"class\">Test</span> {
  <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>;

  <span class=\"directive\">static</span> <span class=\"type\">void</span> main() {
    <span class=\"comment\">/*</span>
<span class=\"comment\">     * Another multiline</span>
<span class=\"comment\">     * comment</span>
<span class=\"comment\">     */</span>
    <span class=\"predefined-type\">System</span>.out.println(MESSAGE);
  }
}
    HTML_OPT_INDEPENDENT_LINES_ON
    
    for lang, code in snippets
      tokens = CodeRay.scan code[:in], lang
      
      assert_equal code[:expected_with_option_off], normalize_html(tokens.html)
      assert_equal code[:expected_with_option_off], normalize_html(tokens.html(:break_lines => false))
      assert_equal code[:expected_with_option_on],  normalize_html(tokens.html(:break_lines => true))
    end
  end
end