forked from rtomayko/rocco
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
two char indent and whitespace error fixes
- Loading branch information
Showing
9 changed files
with
254 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.