Skip to content

Commit

Permalink
Refactoring tests out into separate files.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikewest committed Oct 24, 2010
1 parent e506c51 commit 6aa2217
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 268 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -16,7 +16,7 @@ end

desc 'Run tests (default)'
Rake::TestTask.new(:test) do |t|
t.test_files = FileList['test/*_test.rb']
t.test_files = FileList['test/suite.rb']
t.ruby_opts = ['-rubygems'] if defined? Gem
end

Expand Down
23 changes: 23 additions & 0 deletions test/helper.rb
@@ -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:')
267 changes: 0 additions & 267 deletions test/rocco_test.rb

This file was deleted.

6 changes: 6 additions & 0 deletions test/suite.rb
@@ -0,0 +1,6 @@
require 'test/unit'

tests = Dir["#{File.dirname(__FILE__)}/test_*.rb"]
tests.each do |file|
require file
end
64 changes: 64 additions & 0 deletions test/test_basics.rb
@@ -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
24 changes: 24 additions & 0 deletions test/test_commentchar_detection.rb
@@ -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

0 comments on commit 6aa2217

Please sign in to comment.