Permalink
Browse files

Python block comments (no middle character), and CSS syntax

  • Loading branch information...
1 parent 77dff76 commit d0211ecc99a2a9490fd902d16c2de0412417d6fb @mikewest mikewest committed Nov 22, 2010
Showing with 34 additions and 6 deletions.
  1. +3 −2 lib/rocco.rb
  2. +31 −4 test/test_block_comments.rb
View
@@ -211,6 +211,7 @@ def generate_comment_chars
"c" => { :single => "//", :multi => { :start => "/**", :middle => "*", :end => "*/" } },
"coffee-script" => { :single => "#", :multi => { :start => "###", :middle => nil, :end => "###" } },
"cpp" => { :single => "//", :multi => { :start => "/**", :middle => "*", :end => "*/" } },
+ "css" => { :single => nil, :multi => { :start => "/**", :middle => "*", :end => "*/" } },
"java" => { :single => "//", :multi => { :start => "/**", :middle => "*", :end => "*/" } },
"js" => { :single => "//", :multi => { :start => "/**", :middle => "*", :end => "*/" } },
"lua" => { :single => "--", :multi => nil },
@@ -265,7 +266,7 @@ def parse(data)
if block_comment_end && line.match( block_comment_end )
in_comment_block = false
else
- docs << line.sub( block_comment_mid, '' )
+ docs << line.sub( block_comment_mid || '', '' )
end
# Otherwise, check whether the line matches the beginning of a block, or
# a single-line comment all on it's lonesome. In either case, if there's
@@ -282,7 +283,7 @@ def parse(data)
sections << [docs, code]
docs, code = [], []
end
- docs << line.sub( single_line_comment, '' )
+ docs << line.sub( single_line_comment || '', '' )
else
code << line
end
@@ -7,13 +7,13 @@ def test_basics
[
[ [ "Comment 1" ], [ "def codeblock", "end" ] ]
],
- r.parse( "/**\n * Comment 1\n*/\ndef codeblock\nend\n" )
+ r.parse( "/**\n * Comment 1\n */\ndef codeblock\nend\n" )
)
assert_equal(
[
[ [ "Comment 1a", "Comment 1b" ], [ "def codeblock", "end" ] ]
],
- r.parse( "/**\n * Comment 1a\n * Comment 1b\n*/\ndef codeblock\nend\n" )
+ r.parse( "/**\n * Comment 1a\n * Comment 1b\n */\ndef codeblock\nend\n" )
)
end
def test_multiple_blocks
@@ -23,14 +23,41 @@ def test_multiple_blocks
[ [ "Comment 1" ], [ "def codeblock", "end" ] ],
[ [ "Comment 2" ], [] ]
],
- r.parse( "/**\n * Comment 1\n*/\ndef codeblock\nend\n/**\n * Comment 2\n*/\n" )
+ r.parse( "/**\n * Comment 1\n */\ndef codeblock\nend\n/**\n * Comment 2\n */\n" )
)
assert_equal(
[
[ [ "Comment 1" ], [ "def codeblock", "end" ] ],
[ [ "Comment 2" ], [ "if false", "end" ] ]
],
- r.parse( "/**\n * Comment 1\n*/\ndef codeblock\nend\n/**\n * Comment 2\n*/\nif false\nend" )
+ r.parse( "/**\n * Comment 1\n */\ndef codeblock\nend\n/**\n * Comment 2\n */\nif false\nend" )
+ )
+ end
+ def test_block_without_middle_character
+ r = Rocco.new( 'test', '', { :language => "python" } ) { "" } # Generate throwaway instance so I can test `parse`
+ assert_equal(
+ [
+ [ [ " Comment 1" ], [ "def codeblock", "end" ] ],
+ [ [ " Comment 2" ], [] ]
+ ],
+ r.parse( "\"\"\"\n Comment 1\n\"\"\"\ndef codeblock\nend\n\"\"\"\n Comment 2\n\"\"\"\n" )
+ )
+ assert_equal(
+ [
+ [ [ " Comment 1" ], [ "def codeblock", "end" ] ],
+ [ [ " Comment 2" ], [ "if false", "end" ] ]
+ ],
+ r.parse( "\"\"\"\n Comment 1\n\"\"\"\ndef codeblock\nend\n\"\"\"\n Comment 2\n\"\"\"\nif false\nend" )
+ )
+ end
+ def test_language_without_single_line_comments
+ r = Rocco.new( 'test', '', { :language => "css" } ) { "" } # Generate throwaway instance so I can test `parse`
+ assert_equal(
+ [
+ [ [ "Comment 1" ], [ "def codeblock", "end" ] ],
+ [ [ "Comment 2" ], [ "if false", "end" ] ]
+ ],
+ r.parse( "/**\n * Comment 1\n */\ndef codeblock\nend\n/**\n * Comment 2\n */\nif false\nend" )
)
end
end

0 comments on commit d0211ec

Please sign in to comment.