tenderlove / dom-test-suite

2001 Dom test suite

This URL has Read+Write access

tenderlove (author)
Sun Aug 31 16:22:01 -0700 2008
commit  c28bfab0e66a8b9125e690dd2e6c08c8e367553e
tree    ec271e0cd19e1bcdd30a97848ff9ee23df5132dc
parent  b9538458499af0f0911fed42018c0f48e10df409
dom-test-suite / Rakefile
100644 141 lines (126 sloc) 4.649 kb
1
2
3
4
5
6
7
8
9
10
11
12
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
$LOAD_PATH << File.join(File.expand_path('~aaron'), 'git', 'nokogiri', 'lib')
 
require 'nokogiri'
require 'open-uri'
 
BASE = File.expand_path(File.dirname(__FILE__))
BUILD_DIR = File.join(BASE, "build")
TRANSFORMS_DIR = File.join(BASE, "transforms")
SPECS_DIR = File.join(BASE, 'lib', 'specs')
TEST_DIR = File.join(BASE, 'tests')
RUBY_DIR = File.join(BUILD_DIR, 'ruby')
 
FileUtils.mkdir_p(RUBY_DIR)
FileUtils.mkdir_p(SPECS_DIR)
FileUtils.mkdir_p(File.join(TEST_DIR, 'level1', 'core'))
FileUtils.mkdir_p(File.join(TEST_DIR, 'level1', 'html'))
 
DOM_ZIP = File.join(SPECS_DIR, 'DOM.zip')
 
#dom1-check-spec:
#
#get-dom1:
# [mkdir] Created dir: /Users/aaron/git/DOM-Test-Suite/lib/specs/Level-1
# [get] Getting: http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/DOM.zip
# [get] To: /Users/aaron/git/DOM-Test-Suite/lib/specs/DOM.zip
file DOM_ZIP do
  open("http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/DOM.zip") do |f|
    File.open(File.join(SPECS_DIR, 'DOM.zip'), 'wb') { |dest|
      dest.write f.read
    }
  end
end
task :get_dom1 => DOM_ZIP
 
#dom1-init:
# [unzip] Expanding: /Users/aaron/git/DOM-Test-Suite/lib/specs/DOM.zip into /Users/aaron/git/DOM-Test-Suite/lib/specs/Level-1
# [unzip] Expanding: /Users/aaron/git/DOM-Test-Suite/lib/specs/Level-1/xml-source.zip into /Users/aaron/git/DOM-Test-Suite/lib/specs/Level-1
#
file File.join(SPECS_DIR, "Level-1") => [:get_dom1] do
  chdir(SPECS_DIR)
  FileUtils.rm_rf("Level-1")
  sh("unzip DOM.zip -d Level-1")
  sh("unzip Level-1/xml-source.zip -d Level-1")
  wd_dom = File.read(File.join(SPECS_DIR, 'Level-1', 'xml', 'wd-dom.xml'))
  File.open(File.join(SPECS_DIR, 'Level-1', 'xml', 'wd-dom.xml'), 'wb') { |f|
    f.write wd_dom.gsub(/<spec>/, "<spec xmlns:xlink='http://www.w3.org/1999/xlink'>")
  }
end
 
task :dom1_init => File.join(SPECS_DIR, "Level-1")
 
#dom1-interfaces-init:
#
#dom1-interfaces-gen:
#
#dom1-interfaces-copy:
# [copy] Copying 1 file to /Users/aaron/git/DOM-Test-Suite/build
task :dom_interfaces_copy => [:dom1_init] do
  dom1_int = File.join(BASE, 'patches' ,'dom1-interfaces.xml')
  cp(dom1_int, BUILD_DIR)
end
 
#dom1-interfaces:
task :dom1_interfaces => [:dom_interfaces_copy]
 
#dom1-dtd:
# [style] Warning: the task name <style> is deprecated. Use <xslt> instead.
# [style] Processing /Users/aaron/git/DOM-Test-Suite/build/dom1-interfaces.xml to /Users/aaron/git/DOM-Test-Suite/build/dom1.dtd
# [style] Loading stylesheet /Users/aaron/git/DOM-Test-Suite/transforms/dom-to-dtd.xsl
# [copy] Copying 1 file to /Users/aaron/git/DOM-Test-Suite/tests/level1/core
# [copy] Copying 1 file to /Users/aaron/git/DOM-Test-Suite/tests/level1/html
task :dom1_dtd => :dom1_interfaces do
  doc = Nokogiri::XML.parse(
    File.read(File.join(BUILD_DIR, 'dom1-interfaces.xml')),
    File.join(BUILD_DIR, 'dom1-interfaces.xml')
  )
  xslt = Nokogiri::XSLT.parse(
    File.read(File.join(TRANSFORMS_DIR, 'dom-to-dtd.xsl'))
  )
  dom1_dtd = File.join(BUILD_DIR, 'dom1.dtd')
  File.open(dom1_dtd, 'wb') do |f|
    f.write(
      xslt.apply_to(doc,
        [
          'schema-namespace', '"http://www.w3.org/2001/DOM-Test-Suite/Level-1"',
          'schema-location', '"dom1.xsd"'
        ]
      )
    )
  end
  cp(dom1_dtd, File.join(TEST_DIR, 'level1', 'core'))
  cp(dom1_dtd, File.join(TEST_DIR, 'level1', 'html'))
end
 
#
#dom1-core-gen-java:
task :dom1_schema => [:dom_interfaces_gen] do
  xsd_file = File.join(BUILD_DIR, 'dom1.xsd')
  doc = Nokogiri::XML.parse(
    File.read(File.join(BUILD_DIR, 'dom1-interfaces.xml')),
    File.join(BUILD_DIR, 'dom1-interfaces.xml')
  )
  xslt = Nokogiri::XSLT.parse(
    File.read(File.join(TRANSFORMS_DIR, 'dom-to-xsd.xsl'))
  )
  File.open(xsd_file, 'wb') { |f|
    xsd = xslt.apply_to(doc)
    xsd.gsub!(/_xmlns/, 'xmlns')
    xsd.gsub!(/xmlns_test/, 'xmlns:test')
    f.write(xsd)
  }
  cp(xsd_file, File.join(TEST_DIR, 'level1', 'core'))
  cp(xsd_file, File.join(TEST_DIR, 'level1', 'html'))
end
 
task :to_ruby => :dom1_dtd do
  xslt = Nokogiri::XSLT.parse(
    File.read(File.join(TRANSFORMS_DIR, 'test-to-ruby.xsl'))
  )
  chdir(File.join(TEST_DIR, 'level1', 'core'))
  Dir['**/*.xml'].each do |f|
    doc = Nokogiri::XML.parse(File.read(f), f)
    filename = File.basename(f, '.xml')
    File.open(File.join(RUBY_DIR, "test_#{filename}.rb"), 'wb') do |test_file|
      test_file.write(
        xslt.apply_to(doc,
          ['interfaces-docname', "'#{File.join(BUILD_DIR, 'dom1-interfaces.xml')}'"]
        )
      )
    end
  end
end
 
task :test_ruby => :to_ruby do
  chdir(BASE)
  all = File.join(RUBY_DIR, 'test_alltests.rb')
  ruby("-I ruby:#{RUBY_DIR} #{all}")
end
 
task :default => [:to_ruby]