diff options
author | murphy <murphy@rubychan.de> | 2006-10-15 09:08:50 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2006-10-15 09:08:50 +0000 |
commit | e5088ab940621155554a2e9455b57614c6ff015b (patch) | |
tree | 2ff719674a7855c0de5153a0bc353058cb33df62 /test/coderay_suite.rb | |
parent | 8f4daba117e5b3faf2d4678a3444c05ad946991e (diff) | |
download | coderay-e5088ab940621155554a2e9455b57614c6ff015b.tar.gz |
Tests:
- improved coderay_suite.rb (random and shuffled tests, max parameter, scannerlang->lang, sorted test cases...)
- changed html output extension to .actual.html to svn:ignore them
- fixed some tests (deleted $Id$ etc.)
- made XHTML testcase work
Scanners:
- fixed HTML, Delphi and Nitro scanners thanks to new tests
Engine:
- Tokens#fix and #fix! added (yet to be tested)
- improved Scanner#raise_inspect a bit
Converted more files to UNIX format (go away, stinkin' \r!)
Diffstat (limited to 'test/coderay_suite.rb')
-rw-r--r-- | test/coderay_suite.rb | 86 |
1 files changed, 77 insertions, 9 deletions
diff --git a/test/coderay_suite.rb b/test/coderay_suite.rb index d44d8e9..83d86bb 100644 --- a/test/coderay_suite.rb +++ b/test/coderay_suite.rb @@ -3,6 +3,20 @@ $:.unshift File.join($mydir, '..', 'lib') require 'coderay' +$stdout.sync = true + +# from Ruby Facets (http://facets.rubyforge.org/) +class Array + def shuffle! + s = size + each_index do |j| + i = ::Kernel.rand(s-j) + self[j], self[j+i] = at(j+i), at(j) unless i.zero? + end + self + end +end + module CodeRay require 'test/unit' @@ -53,6 +67,26 @@ module CodeRay :hint => :debug, :css => :class ) + + max = ENV.fetch('max', 500).to_i + unless ENV['norandom'] + print "Random test" + if ENV['showprogress'] + print ': ' + progress = '' + end + for size in 0..max + if ENV['showprogress'] + print "\b" * progress.size + progress = '(%d)' % size + print progress + end + srand size + 17 + scanner.string = Array.new(size) { rand 256 }.pack 'c*' + scanner.tokenize + end + puts ', finished.' + end self.class.dir do for input in Dir["*.#{extension}"] @@ -61,14 +95,48 @@ module CodeRay name = File.basename(input, ".#{extension}") output = name + '.out.' + tokenizer.file_extension code = File.open(input, 'rb') { |f| break f.read } - + unless ENV['noincremental'] - print 'incremental, ' - for size in 0..[code.size, 300].min - print size, '.' if ENV['showprogress'] + print 'incremental' + if ENV['showprogress'] + print ': ' + progress = '' + end + for size in 0..max + break if size > code.size + if ENV['showprogress'] + print "\b" * progress.size + progress = '(%d)' % size + print progress + end scanner.string = code[0,size] scanner.tokenize end + print ', ' + end + + unless ENV['noshuffled'] or code.size < [0].pack('Q').size + print 'shuffled' + if ENV['showprogress'] + print ': ' + progress = '' + end + code_bits = code[0,max].unpack('Q*') # split into quadwords... + (max / 4).times do |i| + if ENV['showprogress'] + print "\b" * progress.size + progress = '(%d)' % i + print progress + end + srand i + code_bits.shuffle! # ...mix... + scanner.string = code_bits.pack('Q*') # ...and join again + scanner.tokenize + end + + # highlighted = highlighter.encode_tokens scanner.tokenize + # File.open(name + '.shuffled.html', 'w') { |f| f.write highlighted } + print ', ' end print 'complete, ' @@ -92,11 +160,11 @@ module CodeRay print 'highlighting, ' highlighted = highlighter.encode_tokens tokens - File.open(name + '.html', 'w') { |f| f.write highlighted } + File.open(name + '.actual.html', 'w') { |f| f.write highlighted } puts 'finished.' end - end + end unless ENV['noexamples'] end end @@ -126,10 +194,10 @@ module CodeRay end def load - if subsuite = ARGV.find { |a| break $1 if a[/^([^-].*)/] } || ENV['scannerlang'] + if subsuite = ARGV.find { |a| break $1 if a[/^([^-].*)/] } || ENV['lang'] load_suite(subsuite) or exit else - Dir[File.join($mydir, '*', '')].each { |suite| load_suite File.basename(suite) } + Dir[File.join($mydir, '*', '')].sort.each { |suite| load_suite File.basename(suite) } end end @@ -147,4 +215,4 @@ module CodeRay end end -end +end
\ No newline at end of file |