forked from sparklemotion/nokogiri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.rb
146 lines (123 loc) · 3.7 KB
/
helper.rb
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
142
143
144
145
146
$VERBOSE = true
require 'rubygems'
require 'test/unit'
%w(../lib ../ext).each do |path|
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), path)))
end
require 'nokogiri'
puts "#{__FILE__}:#{__LINE__}: libxml version info: #{Nokogiri::VERSION_INFO.inspect}"
module Nokogiri
class TestCase < Test::Unit::TestCase
ASSETS_DIR = File.join(File.dirname(__FILE__), 'files')
XML_FILE = File.join(ASSETS_DIR, 'staff.xml')
XSLT_FILE = File.join(ASSETS_DIR, 'staff.xslt')
EXSLT_FILE = File.join(ASSETS_DIR, 'exslt.xslt')
EXML_FILE = File.join(ASSETS_DIR, 'exslt.xml')
HTML_FILE = File.join(ASSETS_DIR, 'tlm.html')
PO_XML_FILE = File.join(ASSETS_DIR, 'po.xml')
PO_SCHEMA_FILE = File.join(ASSETS_DIR, 'po.xsd')
ADDRESS_SCHEMA_FILE = File.join(ASSETS_DIR, 'address_book.rlx')
ADDRESS_XML_FILE = File.join(ASSETS_DIR, 'address_book.xml')
unless RUBY_VERSION >= '1.9'
undef :default_test
end
def setup
warn "#{name}" if ENV['TESTOPTS'] == '-v'
end
def teardown
if ENV['NOKOGIRI_GC']
STDOUT.putc '!'
GC.start
end
end
def assert_indent amount, doc, message = nil
nodes = []
doc.traverse do |node|
nodes << node if node.text? && node.blank?
end
assert nodes.length > 0
nodes.each do |node|
len = node.content.gsub(/[\r\n]/, '').length
assert_equal(0, len % amount, message)
end
end
end
module SAX
class TestCase < Nokogiri::TestCase
class Doc < XML::SAX::Document
attr_reader :start_elements, :start_document_called
attr_reader :end_elements, :end_document_called
attr_reader :data, :comments, :cdata_blocks, :entity_declarations
attr_reader :errors, :warnings, :notation_declarations
attr_reader :attribute_declarations, :internal_subsets
def initialize
@start_document_called = nil
@end_document_called = nil
@errors = []
@warning = []
@start_elements = []
@end_elements = []
@data = []
@comments = []
@cdata_blocks = []
@entity_declarations = []
@notation_declarations = []
@attribute_declarations = []
@internal_subsets = []
end
def start_document
@start_document_called = true
super
end
def end_document
@end_document_called = true
super
end
def error error
@errors << error
super
end
def warning warning
@warning << warning
super
end
def start_element *args
@start_elements << args
super
end
def end_element *args
@end_elements << args
super
end
def characters string
@data += [string]
super
end
def comment string
@comments += [string]
super
end
def cdata_block string
@cdata_blocks += [string]
super
end
def entity_declaration name, type, public_id, system_id, content
@entity_declarations << [name, type, public_id, system_id, content]
super
end
def notation_declaration name, public_id, system_id
@notation_declarations << [name, public_id, system_id]
super
end
def attribute_declaration *args
@attribute_declarations << args
super
end
def internal_subset name, external_id, system_id
@internal_subsets << [name, external_id, system_id]
super
end
end
end
end
end