dkastner-rocco 0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,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,86 @@
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
+ "<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
+ # @TODO: Is this really the correct behavior? Converting text
32
+ # to UTF-8 on the way out is probably preferable.
33
+ r = Rocco.new( File.dirname(__FILE__) + "/fixtures/issue10.iso-8859-1.rb" )
34
+ assert_equal(
35
+ "<p>hello w\366rld</p>\n",
36
+ r.sections[0][0],
37
+ "ISO-8859-1 input should probably also behave correctly."
38
+ )
39
+ end
40
+
41
+ def test_issue12_css_octothorpe_classname_change
42
+ # Docco changed some CSS classes. Rocco needs to update its default template.
43
+ # http://github.com/rtomayko/rocco/issues#issue/12
44
+ r = Rocco.new( 'issue12.sh' ) {
45
+ "# Comment 1\n# Comment 1\nprint 'omg!'"
46
+ }
47
+ html = r.to_html
48
+ assert(
49
+ !html.include?( "<div class=\"octowrap\">" ),
50
+ "`octowrap` wrapper is present in rendered HTML. This ought be replaced with `pilwrap`."
51
+ )
52
+ assert(
53
+ !html.include?( "<a class=\"octothorpe\" href=\"#section-1\">" ),
54
+ "`octothorpe` link is present in rendered HTML. This ought be replaced with `pilcrow`."
55
+ )
56
+ end
57
+
58
+ def test_issue13_incorrect_code_divider_parsing
59
+ # In `bash` mode (among others), the comment class is `c`, not `c1`.
60
+ # http://github.com/rtomayko/rocco/issues#issue/13
61
+ r = Rocco.new( 'issue13.sh', [], { :language => 'bash' } ) {
62
+ "# Comment 1\necho 'code';\n# Comment 2\necho 'code';\n# Comment 3\necho 'code';\n"
63
+ }
64
+ r.sections.each do | section |
65
+ if not section[1].nil?
66
+ assert(
67
+ !section[1].include?("<span class=\"c\"># DIVIDER</span>"),
68
+ "`# DIVIDER` present in code text, which means the highligher screwed up somewhere."
69
+ )
70
+ end
71
+ end
72
+ end
73
+
74
+ def test_issue15_extra_space_after_comment_character_remains
75
+ # After the comment character, a single space should be removed.
76
+ # http://github.com/rtomayko/rocco/issues#issue/15
77
+ r = Rocco.new( 'issue15.sh') {
78
+ "# Comment 1\n# ---------\necho 'code';"
79
+ }
80
+ assert(
81
+ !r.sections[0][0].include?( "<hr />" ),
82
+ "`<hr />` present in rendered documentation text. It should be a header, not text followed by a horizontal rule."
83
+ )
84
+ assert_equal("<h2>Comment 1</h2>\n", r.sections[0][0])
85
+ end
86
+ 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' ) { "" }
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
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class RoccoSourceListTests < Test::Unit::TestCase
4
+ def test_flat_sourcelist
5
+ r = Rocco.new( 'issue26.sh', [ 'issue26a.sh', 'issue26b.sh', 'issue26c.sh' ] ) {
6
+ "# Comment 1\n# Comment 1\nprint 'omg!'"
7
+ }
8
+ html = r.to_html
9
+ assert(
10
+ html.include?( '<a class="source" href="issue26a.html">issue26a.sh</a>' ) &&
11
+ html.include?( '<a class="source" href="issue26b.html">issue26b.sh</a>' ) &&
12
+ html.include?( '<a class="source" href="issue26c.html">issue26c.sh</a>' ),
13
+ "URLs correctly generated for files in a flat directory structure"
14
+ )
15
+ end
16
+
17
+ def test_heiarachical_sourcelist
18
+ r = Rocco.new( 'a/issue26.sh', [ 'a/issue26a.sh', 'b/issue26b.sh', 'c/issue26c.sh' ] ) {
19
+ "# Comment 1\n# Comment 1\nprint 'omg!'"
20
+ }
21
+ html = r.to_html
22
+ assert(
23
+ html.include?( '<a class="source" href="issue26a.html">issue26a.sh</a>' ) &&
24
+ html.include?( '<a class="source" href="../b/issue26b.html">issue26b.sh</a>' ) &&
25
+ html.include?( '<a class="source" href="../c/issue26c.html">issue26c.sh</a>' ),
26
+ "URLs correctly generated for files in a flat directory structure"
27
+ )
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dkastner-rocco
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.8"
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Tomayko
9
+ - Mike West
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2011-05-24 00:00:00 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rdiscount
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: mustache
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rake
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.9.0
47
+ type: :development
48
+ version_requirements: *id003
49
+ description: Docco in Ruby
50
+ email:
51
+ - r@tomayko.com
52
+ - <mike@mikewest.org>
53
+ executables:
54
+ - rocco
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - CHANGES.md
61
+ - COPYING
62
+ - README
63
+ - Rakefile
64
+ - bin/rocco
65
+ - lib/rocco.rb
66
+ - lib/rocco/layout.mustache
67
+ - lib/rocco/layout.rb
68
+ - lib/rocco/tasks.rb
69
+ - rocco.gemspec
70
+ - test/fixtures/issue10.iso-8859-1.rb
71
+ - test/fixtures/issue10.utf-8.rb
72
+ - test/helper.rb
73
+ - test/suite.rb
74
+ - test/test_basics.rb
75
+ - test/test_block_comments.rb
76
+ - test/test_comment_normalization.rb
77
+ - test/test_commentchar_detection.rb
78
+ - test/test_descriptive_section_names.rb
79
+ - test/test_language_detection.rb
80
+ - test/test_reported_issues.rb
81
+ - test/test_skippable_lines.rb
82
+ - test/test_source_list.rb
83
+ homepage: http://rtomayko.github.com/rocco/
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options: []
88
+
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ requirements: []
104
+
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.3
107
+ signing_key:
108
+ specification_version: 2
109
+ summary: Docco in Ruby
110
+ test_files: []
111
+