diff options
author | murphy <murphy@rubychan.de> | 2010-06-29 07:01:39 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2010-06-29 07:01:39 +0000 |
commit | 13a98cec5c7f19e8e7231899645b8f51464becb4 (patch) | |
tree | c22c3c4812713756f36a0e501ebd1f5b9f436321 /lib/coderay/encoders | |
parent | ebab9d3ec5280066e443bfd19b43219dbef9b588 (diff) | |
download | coderay-13a98cec5c7f19e8e7231899645b8f51464becb4.tar.gz |
LOC encoder uses faster to_s encoder now and prints a more useful warning when no scanner was assigned.
Diffstat (limited to 'lib/coderay/encoders')
-rw-r--r-- | lib/coderay/encoders/lines_of_code.rb | 53 |
1 files changed, 2 insertions, 51 deletions
diff --git a/lib/coderay/encoders/lines_of_code.rb b/lib/coderay/encoders/lines_of_code.rb index 8ba82fa..2e2dd9a 100644 --- a/lib/coderay/encoders/lines_of_code.rb +++ b/lib/coderay/encoders/lines_of_code.rb @@ -1,4 +1,3 @@ -($:.unshift '../..'; require 'coderay') unless defined? CodeRay module CodeRay module Encoders @@ -27,11 +26,11 @@ module Encoders if scanner = tokens.scanner kinds_not_loc = scanner.class::KINDS_NOT_LOC else - warn 'Tokens have no scanner.' if $VERBOSE + warn "Tokens have no associated scanner, counting all nonempty lines." if $VERBOSE kinds_not_loc = CodeRay::Scanners::Scanner::KINDS_NOT_LOC end code = tokens.token_kind_filter :exclude => kinds_not_loc - @loc = code.text.scan(NON_EMPTY_LINE).size + @loc = code.to_s.scan(NON_EMPTY_LINE).size end def finish options @@ -42,51 +41,3 @@ module Encoders end end - -if $0 == __FILE__ - $VERBOSE = true - $: << File.join(File.dirname(__FILE__), '..') - eval DATA.read, nil, $0, __LINE__ + 4 -end - -__END__ -require 'test/unit' - -class LinesOfCodeTest < Test::Unit::TestCase - - def test_creation - assert CodeRay::Encoders::LinesOfCode < CodeRay::Encoders::Encoder - filter = nil - assert_nothing_raised do - filter = CodeRay.encoder :loc - end - assert_kind_of CodeRay::Encoders::LinesOfCode, filter - assert_nothing_raised do - filter = CodeRay.encoder :lines_of_code - end - assert_kind_of CodeRay::Encoders::LinesOfCode, filter - end - - def test_lines_of_code - tokens = CodeRay.scan <<-RUBY, :ruby -#!/usr/bin/env ruby - -# a minimal Ruby program -puts "Hello world!" - RUBY - assert_equal 1, CodeRay::Encoders::LinesOfCode.new.encode_tokens(tokens) - assert_equal 1, tokens.lines_of_code - assert_equal 1, tokens.loc - end - - def test_filtering_block_tokens - tokens = CodeRay::Tokens.new - tokens.concat ["Hello\n", :world] - tokens.concat ["Hello\n", :space] - tokens.concat ["Hello\n", :comment] - assert_equal 2, CodeRay::Encoders::LinesOfCode.new.encode_tokens(tokens) - assert_equal 2, tokens.lines_of_code - assert_equal 2, tokens.loc - end - -end
\ No newline at end of file |