Changeset 1006
- Timestamp:
- 2008-05-23 13:04:05 (8 months ago)
- Files:
-
- trunk/lib/parser/test/parser (added)
- trunk/lib/parser/test/parser/latex.yml (moved) (moved from trunk/lib/parser/test/latex.yml)
- trunk/lib/parser/test/parser/zafu.yml (moved) (moved from trunk/lib/parser/test/zafu.yml)
- trunk/lib/parser/test/parser/zafu_asset.yml (moved) (moved from trunk/lib/parser/test/zafu_asset.yml)
- trunk/lib/parser/test/parser/zafu_insight.yml (moved) (moved from trunk/lib/parser/test/zafu_insight.yml)
- trunk/lib/parser/test/parser/zazen.yml (moved) (moved from trunk/lib/parser/test/zazen.yml) (1 diff)
- trunk/lib/parser/test/parser_test.rb (modified) (2 diffs)
- trunk/lib/parser/test/testhelp.rb (deleted)
- trunk/lib/query_builder/test/query_builder (added)
- trunk/lib/query_builder/test/query_builder/basic.yml (moved) (moved from trunk/lib/query_builder/test/basic.yml)
- trunk/lib/query_builder/test/query_builder/errors.yml (moved) (moved from trunk/lib/query_builder/test/errors.yml)
- trunk/lib/query_builder/test/query_builder/filters.yml (moved) (moved from trunk/lib/query_builder/test/filters.yml)
- trunk/lib/query_builder/test/query_builder/joins.yml (moved) (moved from trunk/lib/query_builder/test/joins.yml)
- trunk/lib/query_builder/test/query_builder_test.rb (moved) (moved from trunk/lib/query_builder/test/query_test.rb) (1 diff)
- trunk/lib/yaml_test.rb (modified) (3 diffs)
- trunk/test/helpers/node_query_test.rb (modified) (1 diff)
- trunk/test/helpers/zena_parser/data.yml (modified) (1 diff)
- trunk/vendor/TextMate (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/parser/test/parser/zazen.yml
r1004 r1006 141 141 textile_link: 142 142 src: "See \"trac\":http://dev.zenadmin.org/report/3." 143 res: "< "143 res: "<p>See <a href=\"http://dev.zenadmin.org/report/3\">trac</a>.</p>" 144 144 145 145 wiki_link: trunk/lib/parser/test/parser_test.rb
r886 r1006 1 require File.join(File.dirname(__FILE__) , 'testhelp.rb') 1 require 'test/unit' 2 require 'yaml' 3 require File.join(File.dirname(__FILE__) , '..', 'lib', 'parser') 4 require File.join(File.dirname(__FILE__), '..','..','yaml_test') 2 5 require 'ruby-debug' 3 6 Debugger.start … … 63 66 64 67 class ParserTest < Test::Unit::TestCase 65 testfile :zafu => {}, :zafu_asset => {}, :zafu_insight => {}, :zazen => {} #, :latex => {:module => :zazen, :output => 'latex'} 68 yaml_test :zafu => {}, :zafu_asset => {}, :zafu_insight => {}, :zazen => {} #, :latex => {:module => :zazen, :output => 'latex'} 69 @@test_parsers = {} 70 @@test_options = {} 71 72 @@file_list.each do |file, opts| 73 file = file.to_s 74 mod_name = opts.delete(:module) || file 75 mod_name = mod_name.to_s.split("_").first.capitalize 76 @@test_parsers[file] = Parser.parser_with_rules(eval("#{mod_name}::Rules"), eval("#{mod_name}::Tags")) 77 @@test_options[file] = opts 78 end 79 80 def do_test(file, test) 81 res = @@test_parsers[file].new_with_url("/#{test.gsub('_', '/')}", :helper=>ParserModule::DummyHelper.new(@@test_strings[file])).render(@@test_options[file]) 82 if @@test_strings[file][test]['res'] 83 assert_yaml_test @@test_strings[file][test]['res'], res 84 end 85 end 86 66 87 def test_single 67 88 do_test('zafu', 'only_hello') trunk/lib/query_builder/test/query_builder_test.rb
r970 r1006 98 98 99 99 class QueryTest < Test::Unit::TestCase 100 yaml_dir File.dirname(__FILE__)101 100 yaml_test :basic, :joins, :filters, :errors 102 101 trunk/lib/yaml_test.rb
r980 r1006 19 19 # We need to do a class_eval so that the class variables 'test_strings, test_methods, ...' are scoped 20 20 # in the final class and are not global to all tests using the YamlTest helper. 21 if files[0].kind_of?(Hash) 22 file_list = files[0] 23 else 24 file_list = Hash[*(files.map{|f| [f,{}]}.flatten)] 25 end 26 21 27 class_eval %Q{ 22 28 @@test_strings = {} … … 24 30 @@test_options = {} 25 31 @@test_files = [] 26 #{files.inspect}.each do |file| 32 @@file_list = #{file_list.inspect} 33 @@file_directory ||= begin 34 if #{caller[0].inspect}.split('/').last =~ /^(.*)_test.rb/ 35 File.join(File.dirname(#{caller[0].inspect}), $1) 36 else 37 puts "Bad file name for yaml_tests '#{caller[0]}'. Should be '..._test.rb'. Trying main directory." 38 File.dirname(#{caller[0].inspect}) 39 end 40 end 41 42 @@file_list.each do |file, opts| 27 43 file = file.to_s 28 44 strings = {} … … 42 58 @@test_methods[file] = test_methods 43 59 @@test_files << file 60 end 44 61 62 # Override this in your test class 63 def parse(value) 64 value 65 end 45 66 46 # Override this in your test class 47 def parse(value) 48 value 67 def do_test(file, test) 68 context = @@test_strings[file][test]['context'] || {} 69 default_context = (@@test_strings[file]['default'] || {})['context'] || {} 70 context = Hash[*default_context.merge(context).map{|k,v| [k.to_sym,v]}.flatten] 71 res = parse(@@test_strings[file][test]['src'] || test.gsub('_',' '), context) 72 if test_res = @@test_strings[file][test]['res'] 73 assert_yaml_test test_res, res 49 74 end 50 51 def do_test(file, test) 52 context = @@test_strings[file][test]['context'] || {} 53 default_context = (@@test_strings[file]['default'] || {})['context'] || {} 54 context = Hash[*default_context.merge(context).map{|k,v| [k.to_sym,v]}.flatten] 55 res = parse(@@test_strings[file][test]['src'] || test.gsub('_',' '), context) 56 if test_res = @@test_strings[file][test]['res'] 57 assert_yaml_test test_res, res 75 end 76 77 protected 78 def assert_yaml_test(test_res, res) 79 if test_res[0..1] == '!/' 80 assert_no_match %r{\#{test_res[2..-2]}}m, res 81 elsif test_res[0..0] == '/' 82 assert_match %r{\#{test_res[1..-2]}}m, res 83 else 84 assert_equal test_res, res 58 85 end 59 86 end 60 61 protected62 def assert_yaml_test(test_res, res)63 if test_res[0..1] == '!/'64 assert_no_match %r{\#{test_res[2..-2]}}m, res65 elsif test_res[0..0] == '/'66 assert_match %r{\#{test_res[1..-2]}}m, res67 else68 assert_equal test_res, res69 end70 end71 end72 87 } 73 88 end trunk/test/helpers/node_query_test.rb
r984 r1006 2 2 3 3 class NodeQueryTest < ZenaTestUnit 4 yaml_dir File.join(File.dirname(__FILE__), 'node_query')5 4 yaml_test :basic, :filters, :relations 6 5 trunk/test/helpers/zena_parser/data.yml
r1005 r1006 21 21 res: "150.000" 22 22 23 stat_count: 24 src: "<r:data do='stat' find='count'/>" 25 res: "5" 26 23 27 stat_min: 24 28 src: "<r:data do='stat' find='min'/>"
