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.
Refactoring tests out into separate files.
- Loading branch information
Showing
9 changed files
with
283 additions
and
268 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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
rootdir = File.dirname(File.dirname(__FILE__)) | ||
$LOAD_PATH.unshift "#{rootdir}/lib" | ||
|
||
require 'test/unit' | ||
begin; require 'turn'; rescue LoadError; end | ||
begin | ||
require 'rdiscount' | ||
rescue LoadError | ||
if !defined?(Gem) | ||
require 'rubygems' | ||
retry | ||
end | ||
end | ||
require 'rocco' | ||
|
||
def roccoize( filename, contents, options = {} ) | ||
Rocco.new( filename, [ filename ], options ) { | ||
contents | ||
} | ||
end | ||
|
||
# Send STDERR into the void to suppress program output messages | ||
STDERR.reopen(test(?e, '/dev/null') ? '/dev/null' : 'NUL:') |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'test/unit' | ||
|
||
tests = Dir["#{File.dirname(__FILE__)}/test_*.rb"] | ||
tests.each do |file| | ||
require file | ||
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
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_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_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 | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require File.dirname(__FILE__) + '/helper' | ||
|
||
class RoccoAutomaticCommentChars < Test::Unit::TestCase | ||
def test_basic_detection | ||
r = Rocco.new( 'filename.js' ) { "" } | ||
assert_equal "//", r.options[:comment_chars] | ||
end | ||
def test_fallback_language | ||
r = Rocco.new( 'filename.an_extension_with_no_meaning_whatsoever', '', { :language => "js" } ) { "" } | ||
assert_equal "//", r.options[:comment_chars] | ||
end | ||
def test_fallback_default | ||
r = Rocco.new( 'filename.an_extension_with_no_meaning_whatsoever' ) { "" } | ||
assert_equal "#", r.options[:comment_chars], "`:comment_chars` should be `#` when falling back to defaults." | ||
end | ||
def test_fallback_user | ||
r = Rocco.new( 'filename.an_extension_with_no_meaning_whatsoever', '', { :comment_chars => "user" } ) { "" } | ||
assert_equal "user", r.options[:comment_chars], "`:comment_chars` should be the user's default when falling back to user-provided settings." | ||
end | ||
def test_fallback_user_with_unknown_language | ||
r = Rocco.new( 'filename.an_extension_with_no_meaning_whatsoever', '', { :language => "not-a-language", :comment_chars => "user" } ) { "" } | ||
assert_equal "user", r.options[:comment_chars], "`:comment_chars` should be the user's default when falling back to user-provided settings." | ||
end | ||
end |
Oops, something went wrong.