Class: WikiTestCases
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(parserKlass, testfiles, targets = [:html]) ⇒ WikiTestCases
constructor
A new instance of WikiTestCases.
Constructor Details
#initialize(parserKlass, testfiles, targets = [:html]) ⇒ WikiTestCases
Returns a new instance of WikiTestCases.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/tartan/test/wiki-test.rb', line 13 def initialize(parserKlass, testfiles, targets=[:html]) # if either the testfile or target argument is a single value, turn # it into a single element array testfiles = testfiles.to_a Class.new Test::Unit::TestCase do define_method 'parserClass' do parserKlass end def test_parser(doc, , type, type_name) input = WikiTestCases.get_input(doc, type) expected \ = doc[type_name].gsub(/\{\{\{(.*?)\}\}\}/) {|sub| subs[$1]} # time limit in seconds time_limit = ['time_limit'] ? ['time_limit'] : 1.0 parser = parserClass.new(input, ) out = nil wtimes = Benchmark.measure do out = parser.to_type(type) end time_elapsed = wtimes.utime + wtimes.stime if $DEBUG || ['debug'] || [:debug] print "time_limit: #{'%0.3f' % time_limit}\n"+ "time_elapsed: #{'%0.3f' % time_elapsed}" end assert_equal(expected, out) assert time_elapsed <= time_limit, "elapsed time expected <= #{'%0.3f' % time_limit}"+ " but was #{'%0.3f' % time_elapsed}\n" end sequence = 0 globalOptions = (defined? WikiOptions) ? WikiOptions.dup : {} globalSubs = {} testfiles.each do |testfile| file = File.find_file_in_path(testfile) YAML::load_documents( File.open( file ) ) do |doc| next unless doc globalOptions = doc['options.global'] if doc['options.global'] = globalOptions = .merge(doc['options']) if doc['options'] globalSubs = doc['subs.global'] if doc['subs.global'] subs = globalSubs subs = subs.merge() subs = subs.merge(doc['subs']) if doc['subs'] next unless doc['in'] title = doc['title'] ? doc['title'] : (sequence += 1).to_s targets.each do |target| if target.kind_of? Array target = target.find {|t| doc[t.to_s]} end next unless doc[target.to_s] define_method "test_#{target.to_s}_" + title do test_parser doc, .dup, target.to_sym, target.to_s end # define_method end # targets.each end # YAML::load_documents end # testfiles.each end # Class.new end |
Class Method Details
.get_input(doc, type) ⇒ Object
9 10 11 |
# File 'lib/tartan/test/wiki-test.rb', line 9 def self.get_input(doc, type) doc['in'].gsub(/\{\{\{(.*?)\}\}\}/) {|sub| subs[$1]} end |