Skip to content

Commit

Permalink
two char indent and whitespace error fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomayko committed Mar 5, 2011
1 parent a2d316b commit f40e57b
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 242 deletions.
6 changes: 2 additions & 4 deletions test/suite.rb
@@ -1,6 +1,4 @@
require 'test/unit'

tests = Dir["#{File.dirname(__FILE__)}/test_*.rb"]
tests.each do |file|
require file
end
Dir["#{File.dirname(__FILE__)}/test_*.rb"].
each { |file| require file }
109 changes: 54 additions & 55 deletions test/test_basics.rb
@@ -1,64 +1,63 @@
require File.dirname(__FILE__) + '/helper'

class RoccoBasicTests < Test::Unit::TestCase
def test_rocco_exists_and_is_instancable
roccoize( "filename.rb", "# Comment 1\ndef codeblock\nend\n" )
end
def test_rocco_exists_and_is_instancable
roccoize( "filename.rb", "# Comment 1\ndef codeblock\nend\n" )
end

def test_filename
r = roccoize( "filename.rb", "# Comment 1\ndef codeblock\nend\n" )
assert_equal "filename.rb", r.file
end
def test_filename
r = roccoize( "filename.rb", "# Comment 1\ndef codeblock\nend\n" )
assert_equal "filename.rb", r.file
end

def test_sources
r = roccoize( "filename.rb", "# Comment 1\ndef codeblock\nend\n" )
assert_equal [ "filename.rb" ], r.sources
end
def test_sources
r = roccoize( "filename.rb", "# Comment 1\ndef codeblock\nend\n" )
assert_equal [ "filename.rb" ], r.sources
end

def test_sections
r = roccoize( "filename.rb", "# Comment 1\ndef codeblock\nend\n" )
assert_equal 1, r.sections.length
assert_equal 2, r.sections[ 0 ].length
assert_equal "<p>Comment 1</p>\n", r.sections[ 0 ][ 0 ]
assert_equal "<span class=\"k\">def</span> <span class=\"nf\">codeblock</span>\n<span class=\"k\">end</span>", r.sections[ 0 ][ 1 ]
end
def test_sections
r = roccoize( "filename.rb", "# Comment 1\ndef codeblock\nend\n" )
assert_equal 1, r.sections.length
assert_equal 2, r.sections[ 0 ].length
assert_equal "<p>Comment 1</p>\n", r.sections[ 0 ][ 0 ]
assert_equal "<span class=\"k\">def</span> <span class=\"nf\">codeblock</span>\n<span class=\"k\">end</span>", r.sections[ 0 ][ 1 ]
end

def test_parsing
r = Rocco.new( 'test' ) { "" } # Generate throwaway instance so I can test `parse`
assert_equal(
[
[ [ "Comment 1" ], [ "def codeblock", "end" ] ]
],
r.parse( "# Comment 1\ndef codeblock\nend\n" )
)
assert_equal(
[
[ [ "Comment 1" ], [ "def codeblock" ] ],
[ [ "Comment 2" ], [ "end" ] ]
],
r.parse( "# Comment 1\ndef codeblock\n# Comment 2\nend\n" )
)
end

def test_splitting
r = Rocco.new( 'test' ) { "" } # Generate throwaway instance so I can test `split`
assert_equal(
[
[ "Comment 1" ],
[ "def codeblock\nend" ]
],
r.split([ [ [ "Comment 1" ], [ "def codeblock", "end" ] ] ])
)
assert_equal(
[
[ "Comment 1", "Comment 2" ],
[ "def codeblock", "end" ]
],
r.split( [
[ [ "Comment 1" ], [ "def codeblock" ] ],
[ [ "Comment 2" ], [ "end" ] ]
] )
)
end
def test_parsing
r = Rocco.new( 'test' ) { "" } # Generate throwaway instance so I can test `parse`
assert_equal(
[
[ [ "Comment 1" ], [ "def codeblock", "end" ] ]
],
r.parse( "# Comment 1\ndef codeblock\nend\n" )
)
assert_equal(
[
[ [ "Comment 1" ], [ "def codeblock" ] ],
[ [ "Comment 2" ], [ "end" ] ]
],
r.parse( "# Comment 1\ndef codeblock\n# Comment 2\nend\n" )
)
end

def test_splitting
r = Rocco.new( 'test' ) { "" } # Generate throwaway instance so I can test `split`
assert_equal(
[
[ "Comment 1" ],
[ "def codeblock\nend" ]
],
r.split([ [ [ "Comment 1" ], [ "def codeblock", "end" ] ] ])
)
assert_equal(
[
[ "Comment 1", "Comment 2" ],
[ "def codeblock", "end" ]
],
r.split( [
[ [ "Comment 1" ], [ "def codeblock" ] ],
[ [ "Comment 2" ], [ "end" ] ]
] )
)
end
end
189 changes: 96 additions & 93 deletions test/test_block_comments.rb
@@ -1,98 +1,101 @@
require File.dirname(__FILE__) + '/helper'

class RoccoBlockCommentTest < Test::Unit::TestCase
def test_basics
r = Rocco.new( 'test', '', { :language => "c" } ) { "" } # Generate throwaway instance so I can test `parse`
assert_equal(
[
[ [ "Comment 1" ], [ "def codeblock", "end" ] ]
],
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" )
)
end
def test_multiple_blocks
r = Rocco.new( 'test', '', { :language => "c" } ) { "" } # 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_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_parse
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
def test_language_without_single_line_comments_split
r = Rocco.new( 'test', '', { :language => "css" } ) { "" } # Generate throwaway instance so I can test `parse`
assert_equal(
[
[ "Comment 1", "Comment 2" ],
[ "def codeblock\nend", "if false\nend" ]
],
r.split( [
[ [ "Comment 1" ], [ "def codeblock", "end" ] ],
[ [ "Comment 2" ], [ "if false", "end" ] ]
] )
)
end
def test_language_without_single_line_comments_highlight
r = Rocco.new( 'test', '', { :language => "css" } ) { "" } # Generate throwaway instance so I can test `parse`

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; }" ) ) )
assert_equal(
"<p>This is a comment!</p>",
highlighted[0][0]
);
assert_equal(
"<p>Comment 2</p>\n",
highlighted[1][0]
);
assert(
!highlighted[0][1].include?("DIVIDER") &&
!highlighted[1][1].include?("DIVIDER"),
"`DIVIDER` stripped successfully."
)

assert( true
);
end
def test_basics
r = Rocco.new( 'test', '', { :language => "c" } ) { "" } # Generate throwaway instance so I can test `parse`
assert_equal(
[
[ [ "Comment 1" ], [ "def codeblock", "end" ] ]
],
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" )
)
end

def test_multiple_blocks
r = Rocco.new( 'test', '', { :language => "c" } ) { "" } # 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_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_parse
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

def test_language_without_single_line_comments_split
r = Rocco.new( 'test', '', { :language => "css" } ) { "" } # Generate throwaway instance so I can test `parse`
assert_equal(
[
[ "Comment 1", "Comment 2" ],
[ "def codeblock\nend", "if false\nend" ]
],
r.split( [
[ [ "Comment 1" ], [ "def codeblock", "end" ] ],
[ [ "Comment 2" ], [ "if false", "end" ] ]
] )
)
end

def test_language_without_single_line_comments_highlight
r = Rocco.new( 'test', '', { :language => "css" } ) { "" } # Generate throwaway instance so I can test `parse`

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; }" ) ) )
assert_equal(
"<p>This is a comment!</p>",
highlighted[0][0]
)
assert_equal(
"<p>Comment 2</p>\n",
highlighted[1][0]
)
assert(
!highlighted[0][1].include?("DIVIDER") &&
!highlighted[1][1].include?("DIVIDER"),
"`DIVIDER` stripped successfully."
)
assert( true )
end

end
41 changes: 21 additions & 20 deletions test/test_comment_normalization.rb
@@ -1,24 +1,25 @@
require File.dirname(__FILE__) + '/helper'

class RoccoCommentNormalization < Test::Unit::TestCase
def test_normal_comments
r = Rocco.new( 'test', '', { :language => "python" } ) { "" } # Generate throwaway instance so I can test `parse`
assert_equal(
[
[ [ "Comment 1a", "Comment 1b" ], [ "def codeblock", "end" ] ],
[ [ "Comment 2a", " Comment 2b" ], [] ]
],
r.parse( "\"\"\"\n Comment 1a\n Comment 1b\n\"\"\"\ndef codeblock\nend\n\"\"\"\n Comment 2a\n Comment 2b\n\"\"\"\n" )
)
end
def test_single_line_comments
r = Rocco.new( 'test', '', { :language => "python" } ) { "" } # Generate throwaway instance so I can test `parse`
assert_equal(
[
[ [ "Comment 1a", "Comment 1b" ], [ "def codeblock", "end" ] ],
[ [ "Comment 2a", " Comment 2b" ], [] ]
],
r.parse( "# Comment 1a\n# Comment 1b\ndef codeblock\nend\n# Comment 2a\n# Comment 2b\n" )
)
end
def test_normal_comments
r = Rocco.new( 'test', '', { :language => "python" } ) { "" } # Generate throwaway instance so I can test `parse`
assert_equal(
[
[ [ "Comment 1a", "Comment 1b" ], [ "def codeblock", "end" ] ],
[ [ "Comment 2a", " Comment 2b" ], [] ]
],
r.parse( "\"\"\"\n Comment 1a\n Comment 1b\n\"\"\"\ndef codeblock\nend\n\"\"\"\n Comment 2a\n Comment 2b\n\"\"\"\n" )
)
end

def test_single_line_comments
r = Rocco.new( 'test', '', { :language => "python" } ) { "" } # Generate throwaway instance so I can test `parse`
assert_equal(
[
[ [ "Comment 1a", "Comment 1b" ], [ "def codeblock", "end" ] ],
[ [ "Comment 2a", " Comment 2b" ], [] ]
],
r.parse( "# Comment 1a\n# Comment 1b\ndef codeblock\nend\n# Comment 2a\n# Comment 2b\n" )
)
end
end

0 comments on commit f40e57b

Please sign in to comment.