From 93dfad17309f46d00d1043592efdb282d13963fe Mon Sep 17 00:00:00 2001 From: murphy Date: Tue, 29 Jun 2010 06:32:30 +0000 Subject: Added lots of unit tests. Theses actually come from the library files; now they are included. Also, rake test and test:all don't test the scanners now; you have to start them using rake test:scanners. --- test/unit/debug.rb | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 test/unit/debug.rb (limited to 'test/unit/debug.rb') diff --git a/test/unit/debug.rb b/test/unit/debug.rb new file mode 100644 index 0000000..8bafcf5 --- /dev/null +++ b/test/unit/debug.rb @@ -0,0 +1,76 @@ +require 'test/unit' +require 'coderay' + +class DebugEncoderTest < Test::Unit::TestCase + + def test_creation + debug = nil + assert_nothing_raised do + debug = CodeRay.encoder :debug + end + assert CodeRay::Encoders::Debug < CodeRay::Encoders::Encoder + assert_kind_of CodeRay::Encoders::Encoder, debug + end + + TEST_INPUT = CodeRay::Tokens[ + ['10', :integer], + ['(\\)', :operator], + [:begin_group, :string], + ['test', :content], + [:end_group, :string], + [:begin_line, :test], + ["\n", :space], + ["\n \t", :space], + [" \n", :space], + ["[]", :method], + [:end_line, :test], + ].flatten + TEST_OUTPUT = <<-'DEBUG'.chomp +integer(10)operator((\\\))stringtest[ + + +method([])] + DEBUG + + def test_filtering_text_tokens + assert_equal TEST_OUTPUT, CodeRay::Encoders::Debug.new.encode_tokens(TEST_INPUT) + assert_equal TEST_OUTPUT, TEST_INPUT.debug + end + +end + +class DebugScannerTest < Test::Unit::TestCase + + def test_creation + assert CodeRay::Scanners::Debug < CodeRay::Scanners::Scanner + debug = nil + assert_nothing_raised do + debug = CodeRay.scanner :debug + end + assert_kind_of CodeRay::Scanners::Scanner, debug + end + + TEST_INPUT = <<-'DEBUG'.chomp +integer(10)operator((\\\))stringtest[ + + +method([])] + DEBUG + TEST_OUTPUT = CodeRay::Tokens[ + ['10', :integer], + ['(\\)', :operator], + [:begin_group, :string], + ['test', :content], + [:end_group, :string], + [:begin_line, :test], + ["\n\n \t \n", :space], + ["[]", :method], + [:end_line, :test], + ].flatten + + def test_filtering_text_tokens + assert_equal TEST_OUTPUT, CodeRay::Scanners::Debug.new.tokenize(TEST_INPUT) + assert_equal TEST_OUTPUT, CodeRay.scan(TEST_INPUT, :debug) + end + +end -- cgit v1.2.1