fl-rocco 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,64 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class RoccoBlockCommentTest < Test::Unit::TestCase
4
+ def test_one_liner
5
+ r = Rocco.new( 'test', '', { :language => "c" } ) { "" } # Generate throwaway instance so I can test `parse`
6
+ assert_equal(
7
+ [
8
+ [ [ "Comment 1" ], [ "def codeblock", "end" ] ]
9
+ ],
10
+ r.parse( "/** Comment 1 */\ndef codeblock\nend\n" )
11
+ )
12
+ end
13
+
14
+ def test_block_start_with_comment
15
+ r = Rocco.new( 'test', '', { :language => "c" } ) { "" } # Generate throwaway instance so I can test `parse`
16
+ assert_equal(
17
+ [
18
+ [ [ "Comment 1a", "Comment 1b" ], [ "def codeblock", "end" ] ]
19
+ ],
20
+ r.parse( "/** Comment 1a\n * Comment 1b\n */\ndef codeblock\nend\n" )
21
+ )
22
+ end
23
+
24
+ def test_block_end_with_comment
25
+ r = Rocco.new( 'test', '', { :language => "c" } ) { "" } # Generate throwaway instance so I can test `parse`
26
+ assert_equal(
27
+ [
28
+ [ [ "Comment 1a", "Comment 1b" ], [ "def codeblock", "end" ] ]
29
+ ],
30
+ r.parse( "/**\n * Comment 1a\n Comment 1b */\ndef codeblock\nend\n" )
31
+ )
32
+ end
33
+
34
+ def test_block_end_with_comment_and_middle
35
+ r = Rocco.new( 'test', '', { :language => "c" } ) { "" } # Generate throwaway instance so I can test `parse`
36
+ assert_equal(
37
+ [
38
+ [ [ "Comment 1a", "Comment 1b" ], [ "def codeblock", "end" ] ]
39
+ ],
40
+ r.parse( "/**\n * Comment 1a\n * Comment 1b */\ndef codeblock\nend\n" )
41
+ )
42
+ end
43
+
44
+ def test_block_start_with_comment_and_end_with_comment
45
+ r = Rocco.new( 'test', '', { :language => "c" } ) { "" } # Generate throwaway instance so I can test `parse`
46
+ assert_equal(
47
+ [
48
+ [ [ "Comment 1a", "Comment 1b" ], [ "def codeblock", "end" ] ]
49
+ ],
50
+ r.parse( "/** Comment 1a\n Comment 1b */\ndef codeblock\nend\n" )
51
+ )
52
+ end
53
+
54
+ def test_block_start_with_comment_and_end_with_comment_and_middle
55
+ r = Rocco.new( 'test', '', { :language => "c" } ) { "" } # Generate throwaway instance so I can test `parse`
56
+ assert_equal(
57
+ [
58
+ [ [ "Comment 1a", "Comment 1b" ], [ "def codeblock", "end" ] ]
59
+ ],
60
+ r.parse( "/** Comment 1a\n * Comment 1b */\ndef codeblock\nend\n" )
61
+ )
62
+ end
63
+
64
+ end
@@ -0,0 +1,101 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class RoccoBlockCommentTest < Test::Unit::TestCase
4
+ def test_basics
5
+ r = Rocco.new( 'test', '', { :language => "c" } ) { "" } # Generate throwaway instance so I can test `parse`
6
+ assert_equal(
7
+ [
8
+ [ [ "Comment 1" ], [ "def codeblock", "end" ] ]
9
+ ],
10
+ r.parse( "/**\n * Comment 1\n */\ndef codeblock\nend\n" )
11
+ )
12
+ assert_equal(
13
+ [
14
+ [ [ "Comment 1a", "Comment 1b" ], [ "def codeblock", "end" ] ]
15
+ ],
16
+ r.parse( "/**\n * Comment 1a\n * Comment 1b\n */\ndef codeblock\nend\n" )
17
+ )
18
+ end
19
+
20
+ def test_multiple_blocks
21
+ r = Rocco.new( 'test', '', { :language => "c" } ) { "" } # Generate throwaway instance so I can test `parse`
22
+ assert_equal(
23
+ [
24
+ [ [ "Comment 1" ], [ "def codeblock", "end" ] ],
25
+ [ [ "Comment 2" ], [] ]
26
+ ],
27
+ r.parse( "/**\n * Comment 1\n */\ndef codeblock\nend\n/**\n * Comment 2\n */\n" )
28
+ )
29
+ assert_equal(
30
+ [
31
+ [ [ "Comment 1" ], [ "def codeblock", "end" ] ],
32
+ [ [ "Comment 2" ], [ "if false", "end" ] ]
33
+ ],
34
+ r.parse( "/**\n * Comment 1\n */\ndef codeblock\nend\n/**\n * Comment 2\n */\nif false\nend" )
35
+ )
36
+ end
37
+
38
+ def test_block_without_middle_character
39
+ r = Rocco.new( 'test', '', { :language => "python" } ) { "" } # Generate throwaway instance so I can test `parse`
40
+ assert_equal(
41
+ [
42
+ [ [ "Comment 1" ], [ "def codeblock", "end" ] ],
43
+ [ [ "Comment 2" ], [] ]
44
+ ],
45
+ r.parse( "\"\"\"\n Comment 1\n\"\"\"\ndef codeblock\nend\n\"\"\"\n Comment 2\n\"\"\"\n" )
46
+ )
47
+ assert_equal(
48
+ [
49
+ [ [ "Comment 1" ], [ "def codeblock", "end" ] ],
50
+ [ [ "Comment 2" ], [ "if false", "end" ] ]
51
+ ],
52
+ r.parse( "\"\"\"\n Comment 1\n\"\"\"\ndef codeblock\nend\n\"\"\"\n Comment 2\n\"\"\"\nif false\nend" )
53
+ )
54
+ end
55
+
56
+ def test_language_without_single_line_comments_parse
57
+ r = Rocco.new( 'test', '', { :language => "css" } ) { "" } # Generate throwaway instance so I can test `parse`
58
+ assert_equal(
59
+ [
60
+ [ [ "Comment 1" ], [ "def codeblock", "end" ] ],
61
+ [ [ "Comment 2" ], [ "if false", "end" ] ]
62
+ ],
63
+ r.parse( "/**\n * Comment 1\n */\ndef codeblock\nend\n/**\n * Comment 2\n */\nif false\nend" )
64
+ )
65
+ end
66
+
67
+ def test_language_without_single_line_comments_split
68
+ r = Rocco.new( 'test', '', { :language => "css" } ) { "" } # Generate throwaway instance so I can test `parse`
69
+ assert_equal(
70
+ [
71
+ [ "Comment 1", "Comment 2" ],
72
+ [ "def codeblock\nend", "if false\nend" ]
73
+ ],
74
+ r.split( [
75
+ [ [ "Comment 1" ], [ "def codeblock", "end" ] ],
76
+ [ [ "Comment 2" ], [ "if false", "end" ] ]
77
+ ] )
78
+ )
79
+ end
80
+
81
+ def test_language_without_single_line_comments_highlight
82
+ r = Rocco.new( 'test', '', { :language => "css" } ) { "" } # Generate throwaway instance so I can test `parse`
83
+
84
+ highlighted = r.highlight( r.split( r.parse( "/**\n * This is a comment!\n */\n.rule { goes: here; }\n/**\n * Comment 2\n */\n.rule2 { goes: here; }" ) ) )
85
+ assert_equal(
86
+ "<p>This is a comment!</p>",
87
+ highlighted[0][0]
88
+ )
89
+ assert_equal(
90
+ fb_assert_val("<p>Comment 2</p>\n"),
91
+ highlighted[1][0]
92
+ )
93
+ assert(
94
+ !highlighted[0][1].include?("DIVIDER") &&
95
+ !highlighted[1][1].include?("DIVIDER"),
96
+ "`DIVIDER` stripped successfully."
97
+ )
98
+ assert( true )
99
+ end
100
+
101
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class RoccoCommentNormalization < Test::Unit::TestCase
4
+ def test_normal_comments
5
+ r = Rocco.new( 'test', '', { :language => "python" } ) { "" } # Generate throwaway instance so I can test `parse`
6
+ assert_equal(
7
+ [
8
+ [ [ "Comment 1a", "Comment 1b" ], [ "def codeblock", "end" ] ],
9
+ [ [ "Comment 2a", " Comment 2b" ], [] ]
10
+ ],
11
+ r.parse( "\"\"\"\n Comment 1a\n Comment 1b\n\"\"\"\ndef codeblock\nend\n\"\"\"\n Comment 2a\n Comment 2b\n\"\"\"\n" )
12
+ )
13
+ end
14
+
15
+ def test_single_line_comments
16
+ r = Rocco.new( 'test', '', { :language => "python" } ) { "" } # Generate throwaway instance so I can test `parse`
17
+ assert_equal(
18
+ [
19
+ [ [ "Comment 1a", "Comment 1b" ], [ "def codeblock", "end" ] ],
20
+ [ [ "Comment 2a", " Comment 2b" ], [] ]
21
+ ],
22
+ r.parse( "# Comment 1a\n# Comment 1b\ndef codeblock\nend\n# Comment 2a\n# Comment 2b\n" )
23
+ )
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class RoccoAutomaticCommentChars < Test::Unit::TestCase
4
+ def test_basic_detection
5
+ r = Rocco.new( 'filename.js' ) { "" }
6
+ assert_equal "//", r.options[:comment_chars][:single]
7
+ end
8
+
9
+ def test_fallback_language
10
+ r = Rocco.new( 'filename.an_extension_with_no_meaning_whatsoever', '', { :language => "js" } ) { "" }
11
+ assert_equal "//", r.options[:comment_chars][:single]
12
+ end
13
+
14
+ def test_fallback_default
15
+ r = Rocco.new( 'filename.an_extension_with_no_meaning_whatsoever' ) { "" }
16
+ assert_equal "#", r.options[:comment_chars][:single], "`:comment_chars` should be `#` when falling back to defaults."
17
+ end
18
+
19
+ def test_fallback_user
20
+ r = Rocco.new( 'filename.an_extension_with_no_meaning_whatsoever', '', { :comment_chars => "user" } ) { "" }
21
+ assert_equal "user", r.options[:comment_chars][:single], "`:comment_chars` should be the user's default when falling back to user-provided settings."
22
+ end
23
+
24
+ def test_fallback_user_with_unknown_language
25
+ r = Rocco.new( 'filename.an_extension_with_no_meaning_whatsoever', '', { :language => "not-a-language", :comment_chars => "user" } ) { "" }
26
+ assert_equal "user", r.options[:comment_chars][:single], "`:comment_chars` should be the user's default when falling back to user-provided settings."
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class RoccoDescriptiveSectionNamesTests < Test::Unit::TestCase
4
+ def test_section_name
5
+ r = roccoize( "filename.rb", "# # Comment 1\ndef codeblock\nend\n" )
6
+ html = r.to_html
7
+ assert(
8
+ html.include?( "<tr id='section-Comment_1'>" ),
9
+ "The first section should be named"
10
+ )
11
+ assert(
12
+ html.include?( '<a class="pilcrow" href="#section-Comment_1">' ),
13
+ "The rendered HTML should link to a named section"
14
+ )
15
+ end
16
+
17
+ def test_section_numbering
18
+ r = roccoize( "filename.rb", "# # Header 1\ndef codeblock\nend\n# Comment 1\ndef codeblock1\nend\n# # Header 2\ndef codeblock2\nend" )
19
+ html = r.to_html
20
+ assert(
21
+ html.include?( '<a class="pilcrow" href="#section-Header_1">' ) &&
22
+ html.include?( '<a class="pilcrow" href="#section-Header_2">' ),
23
+ "First and second headers should be named sections"
24
+ )
25
+ assert(
26
+ html.include?( '<a class="pilcrow" href="#section-2">' ),
27
+ "Sections should continue numbering as though headers were counted."
28
+ )
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class RoccoDocblockAnnotationsTest < Test::Unit::TestCase
4
+ def test_basics
5
+ r = Rocco.new( 'test', '', { :language => "c", :docblocks => true } ) { "" } # Generate throwaway instance so I can test `parse`
6
+ assert_equal(
7
+ [
8
+ "Comment\n\n> **param** mixed foo \n> **return** void "
9
+ ],
10
+ r.docblock( ["Comment\n\n@param mixed foo\n@return void"] )
11
+ )
12
+ end
13
+
14
+ def test_highlighted_in_blocks
15
+ r = Rocco.new( 'test', '', { :language => "c", :docblocks => true } ) { "" } # Generate throwaway instance so I can test `parse`
16
+ highlighted = r.highlight( r.split( r.parse( "/**\n * Comment\n *\n * @param type name\n */\ndef codeblock\nend\n" ) ) )
17
+
18
+ assert_equal(
19
+ Rocco::MD_BLUECLOTH ? "<p>Comment</p>\n\n<blockquote><p><strong>param</strong> type name</p></blockquote>" : "<p>Comment</p>\n<blockquote>\n<p><strong>param</strong> type name </p>\n</blockquote>",
20
+ highlighted[0][0]
21
+ )
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class RoccoHeredocTest < Test::Unit::TestCase
4
+ def test_basics
5
+ r = Rocco.new( 'test', '', { :language => "rb" } ) { "" } # Generate throwaway instance so I can test `parse`
6
+ assert_equal(
7
+ [
8
+ [ [ "Comment 1" ], [ "heredoc <<-EOH", "#comment", "code", "EOH" ] ]
9
+ ],
10
+ r.parse( "# Comment 1\nheredoc <<-EOH\n#comment\ncode\nEOH" )
11
+ )
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class RoccoLanguageDetection < Test::Unit::TestCase
4
+ def test_basic_detection
5
+ r = Rocco.new( 'filename.py' ) { "" }
6
+ if r.pygmentize?
7
+ assert_equal "python", r.detect_language(), "`detect_language()` should return the correct language"
8
+ assert_equal "python", r.options[:language], "`@options[:language]` should be set to the correct language"
9
+ end
10
+ end
11
+
12
+ def test_fallback_default
13
+ r = Rocco.new( 'filename.an_extension_with_no_meaning_whatsoever' ) { "" }
14
+ if r.pygmentize?
15
+ assert_equal "text", r.detect_language(), "`detect_language()` should return `text` when nothing else is detected"
16
+ assert_equal "ruby", r.options[:language], "`@options[:language]` should be set to `ruby` when nothing else is detected"
17
+ end
18
+ end
19
+
20
+ def test_fallback_user
21
+ r = Rocco.new( 'filename.an_extension_with_no_meaning_whatsoever', '', { :language => "c" } ) { "" }
22
+ if r.pygmentize?
23
+ assert_equal "text", r.detect_language(), "`detect_language()` should return `text` nothing else is detected"
24
+ assert_equal "c", r.options[:language], "`@options[:language]` should be set to the user's setting when nothing else is detected"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../helper', __FILE__)
3
+
4
+ class RoccoIssueTests < Test::Unit::TestCase
5
+ def test_issue07_incorrect_parsing_in_c_mode
6
+ # Precursor to issue #13 below, Rocco incorrectly parsed C/C++
7
+ # http://github.com/rtomayko/rocco/issues#issue/7
8
+ r = Rocco.new( 'issue7.c', [], { :language => 'c' } ) {
9
+ "// *stdio.h* declares *puts*\n#include <stdio.h>\n\n//### code hello world\n\n// every C program contains function *main*.\nint main (int argc, char *argv[]) {\n puts('hello world');\n return 0;\n}\n\n// that's it!"
10
+ }
11
+ r.sections.each do | section |
12
+ if not section[1].nil?
13
+ assert(
14
+ !section[1].include?("<span class=\"c\"># DIVIDER</span>"),
15
+ "`# DIVIDER` present in code text, which means the highligher screwed up somewhere."
16
+ )
17
+ end
18
+ end
19
+ end
20
+
21
+ def test_issue10_utf8_processing
22
+ # Rocco has issues with strange UTF-8 characters: need to explicitly set the encoding for Pygments
23
+ # http://github.com/rtomayko/rocco/issues#issue/10
24
+ r = Rocco.new( File.dirname(__FILE__) + "/fixtures/issue10.utf-8.rb" )
25
+ assert_equal(
26
+ fb_assert_val("<p>hello ąćęłńóśźż</p>\n"),
27
+ r.sections[0][0],
28
+ "UTF-8 input files ought behave correctly."
29
+ )
30
+ # and, just for grins, ensure that iso-8859-1 works too.
31
+ r = Rocco.new( File.dirname(__FILE__) + "/fixtures/issue10.iso-8859-1.rb", [], :encoding => 'ISO-8859-1' )
32
+ assert_equal(
33
+ fb_assert_val("<p>hello wörld</p>\n"),
34
+ r.sections[0][0],
35
+ "ISO-8859-1 input should probably also behave correctly."
36
+ )
37
+ end
38
+
39
+ def test_issue12_css_octothorpe_classname_change
40
+ # Docco changed some CSS classes. Rocco needs to update its default template.
41
+ # http://github.com/rtomayko/rocco/issues#issue/12
42
+ r = Rocco.new( 'issue12.sh' ) {
43
+ "# Comment 1\n# Comment 1\nprint 'omg!'"
44
+ }
45
+ html = r.to_html
46
+ assert(
47
+ !html.include?( "<div class=\"octowrap\">" ),
48
+ "`octowrap` wrapper is present in rendered HTML. This ought be replaced with `pilwrap`."
49
+ )
50
+ assert(
51
+ !html.include?( "<a class=\"octothorpe\" href=\"#section-1\">" ),
52
+ "`octothorpe` link is present in rendered HTML. This ought be replaced with `pilcrow`."
53
+ )
54
+ end
55
+
56
+ def test_issue13_incorrect_code_divider_parsing
57
+ # In `bash` mode (among others), the comment class is `c`, not `c1`.
58
+ # http://github.com/rtomayko/rocco/issues#issue/13
59
+ r = Rocco.new( 'issue13.sh', [], { :language => 'bash' } ) {
60
+ "# Comment 1\necho 'code';\n# Comment 2\necho 'code';\n# Comment 3\necho 'code';\n"
61
+ }
62
+ r.sections.each do | section |
63
+ if not section[1].nil?
64
+ assert(
65
+ !section[1].include?("<span class=\"c\"># DIVIDER</span>"),
66
+ "`# DIVIDER` present in code text, which means the highligher screwed up somewhere."
67
+ )
68
+ end
69
+ end
70
+ end
71
+
72
+ def test_issue15_extra_space_after_comment_character_remains
73
+ # After the comment character, a single space should be removed.
74
+ # http://github.com/rtomayko/rocco/issues#issue/15
75
+ r = Rocco.new( 'issue15.sh') {
76
+ "# Comment 1\n# ---------\necho 'code';"
77
+ }
78
+ assert(
79
+ !r.sections[0][0].include?( "<hr />" ),
80
+ "`<hr />` present in rendered documentation text. It should be a header, not text followed by a horizontal rule."
81
+ )
82
+ assert_equal(fb_assert_val("<h2>Comment 1</h2>\n"), r.sections[0][0])
83
+ end
84
+ end
@@ -0,0 +1,64 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class RoccoSkippableLines < Test::Unit::TestCase
4
+ def test_shebang_first_line
5
+ r = Rocco.new( 'filename.sh' ) { "" }
6
+ assert_equal(
7
+ [
8
+ [ [ "Comment 1" ], [ "def codeblock" ] ],
9
+ [ [ "Comment 2" ], [ "end" ] ]
10
+ ],
11
+ r.parse( "#!/usr/bin/env bash\n# Comment 1\ndef codeblock\n# Comment 2\nend\n" ),
12
+ "Shebang should be stripped when it appears as the first line."
13
+ )
14
+ end
15
+
16
+ def test_shebang_in_content
17
+ r = Rocco.new( 'filename.sh' ) { "" }
18
+ assert_equal(
19
+ [
20
+ # @TODO: `#!/` shouldn't be recognized as a comment.
21
+ [ [ "Comment 1", "!/usr/bin/env bash" ], [ "def codeblock" ] ],
22
+ [ [ "Comment 2" ], [ "end" ] ]
23
+ ],
24
+ r.parse( "# Comment 1\n#!/usr/bin/env bash\ndef codeblock\n# Comment 2\nend\n" ),
25
+ "Shebang shouldn't be stripped anywhere other than as the first line."
26
+ )
27
+ end
28
+
29
+ def test_encoding_in_ruby
30
+ r = Rocco.new( 'filename.rb' ) { "" }
31
+ assert_equal(
32
+ [
33
+ [ [ "Comment 1" ], [ "def codeblock" ] ],
34
+ [ [ "Comment 2" ], [ "end" ] ]
35
+ ],
36
+ r.parse( "#!/usr/bin/env bash\n# encoding: utf-8\n# Comment 1\ndef codeblock\n# Comment 2\nend\n" ),
37
+ "Strings matching the PEP 263 encoding definition regex should be stripped when they appear at the top of a python document."
38
+ )
39
+ end
40
+
41
+ def test_encoding_in_python
42
+ r = Rocco.new( 'filename.py', [], {:language => "python"} ) { "" }
43
+ assert_equal(
44
+ [
45
+ [ [ "Comment 1" ], [ "def codeblock" ] ],
46
+ [ [ "Comment 2" ], [ "end" ] ]
47
+ ],
48
+ r.parse( "#!/usr/bin/env bash\n# encoding: utf-8\n# Comment 1\ndef codeblock\n# Comment 2\nend\n" ),
49
+ "Strings matching the PEP 263 encoding definition regex should be stripped when they appear at the top of a python document."
50
+ )
51
+ end
52
+
53
+ def test_encoding_in_notpython
54
+ r = Rocco.new( 'filename.sh' ) { "" }
55
+ assert_equal(
56
+ [
57
+ [ [ "encoding: utf-8", "Comment 1" ], [ "def codeblock" ] ],
58
+ [ [ "Comment 2" ], [ "end" ] ]
59
+ ],
60
+ r.parse( "#!/usr/bin/env bash\n# encoding: utf-8\n# Comment 1\ndef codeblock\n# Comment 2\nend\n" ),
61
+ "Strings matching the PEP 263 encoding definition regex should be stripped when they appear at the top of a python document."
62
+ )
63
+ end
64
+ end