uformats 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +8 -0
- data/COPYING +4 -0
- data/README +36 -0
- data/lib/uformats.rb +158 -0
- data/lib/uformats/basic.rb +268 -0
- data/lib/uformats/hcalendar.rb +23 -0
- data/lib/uformats/hcard.rb +100 -0
- data/lib/uformats/hreview.rb +182 -0
- data/lib/uformats/pluralizer.rb +32 -0
- data/test/all.rb +4 -0
- data/test/basic_test.rb +441 -0
- data/test/hcalendar_test.rb +157 -0
- data/test/hcard_test.rb +438 -0
- data/test/hreview_test.rb +500 -0
- data/test/pluralizer_test.rb +24 -0
- data/test/test_helper.rb +13 -0
- data/test/uformats_test.rb +235 -0
- metadata +70 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require 'uformats/pluralizer'
|
3
|
+
|
4
|
+
class PluralizerTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def s(sym)
|
7
|
+
return Microformats::Pluralizer.pluralize(sym)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_all
|
11
|
+
assert_equal(:honorific_prefixes, s(:honorific_prefix))
|
12
|
+
assert_equal(:nicknames, s(:nickname))
|
13
|
+
assert_equal(:urls, s(:url))
|
14
|
+
assert_equal(:emails, s(:email))
|
15
|
+
assert_equal(:types, s(:type))
|
16
|
+
assert_equal(:adrs, s(:adr))
|
17
|
+
assert_equal(:categories, s(:category))
|
18
|
+
assert_equal(:tels, s(:tel))
|
19
|
+
assert_equal(:notes, s(:note))
|
20
|
+
assert_equal(:keys, s(:key))
|
21
|
+
assert_equal(:matches, s(:match))
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$: << File.dirname(__FILE__) + '/../lib'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
module Test
|
5
|
+
module Unit
|
6
|
+
class TestCase
|
7
|
+
def assert_xml_equal(doc1, doc2)
|
8
|
+
cleaned = [doc1, doc2].map{ |doc| doc.to_s.gsub(/\s+/um, ' ') }
|
9
|
+
assert_equal(*cleaned)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,235 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require 'uformats'
|
3
|
+
require 'rexml/document'
|
4
|
+
|
5
|
+
class MicroformatsTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_method_hash_should_initialize_with_hash_and_have_read_write_access_via_square_brackets
|
8
|
+
h = {:foo => 1, :bar => 2}
|
9
|
+
mh = Microformats::MethodHash.new(h)
|
10
|
+
assert_equal(1, mh[:foo])
|
11
|
+
assert_equal(2, mh[:bar])
|
12
|
+
mh[:baz] = 3
|
13
|
+
assert_equal(3, mh[:baz])
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_iterate_with_arity_1
|
17
|
+
h = {:foo => 1, :bar => 2}
|
18
|
+
mh = Microformats::MethodHash.new(h)
|
19
|
+
ary = []
|
20
|
+
mh.each do |r|
|
21
|
+
ary << r
|
22
|
+
end
|
23
|
+
assert(ary.include?([:foo, 1]))
|
24
|
+
assert(ary.include?([:bar, 2]))
|
25
|
+
assert_equal(2, ary.length)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_should_iterate_with_arity_2
|
29
|
+
h = {:foo => 1, :bar => 2}
|
30
|
+
mh = Microformats::MethodHash.new(h)
|
31
|
+
ary = []
|
32
|
+
mh.each do |k, v|
|
33
|
+
ary << {:key => k, :value => v}
|
34
|
+
end
|
35
|
+
assert_equal(2, ary.length)
|
36
|
+
assert(ary.include?({:key => :foo, :value => 1}))
|
37
|
+
assert(ary.include?({:key => :bar, :value => 2}))
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_method_hash_should_return_first_plural_item_when_singular_item_requested
|
41
|
+
h = {:foos => [1,2]}
|
42
|
+
mh = Microformats::MethodHash.new(h)
|
43
|
+
assert_equal([1,2], mh.foos)
|
44
|
+
assert_equal(1, mh.foo)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_should_return_first_matching_element_for_class
|
48
|
+
doc = REXML::Document.new(%{
|
49
|
+
<html>
|
50
|
+
<body>
|
51
|
+
<p class="foo">
|
52
|
+
Hello
|
53
|
+
</p>
|
54
|
+
<p class="foo">
|
55
|
+
Goodbye
|
56
|
+
</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
59
|
+
})
|
60
|
+
assert_equal('Hello', Microformats.first_element_by_class(doc, :foo).text.strip)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_should_return_nil_when_first_matching_element_not_found
|
64
|
+
doc = REXML::Document.new(%{
|
65
|
+
<html>
|
66
|
+
<body>
|
67
|
+
<p class="foo">
|
68
|
+
Hello
|
69
|
+
</p>
|
70
|
+
<p class="foo">
|
71
|
+
Goodbye
|
72
|
+
</p>
|
73
|
+
</body>
|
74
|
+
</html>
|
75
|
+
})
|
76
|
+
assert_nil(Microformats.first_element_by_class(doc, :bar))
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_should_return_list_of_symbols_corresponding_to_elements_class
|
80
|
+
doc = REXML::Document.new(%{
|
81
|
+
<html>
|
82
|
+
<body>
|
83
|
+
<p class="foo-bar baz">
|
84
|
+
Hello
|
85
|
+
</p>
|
86
|
+
</body>
|
87
|
+
</html>
|
88
|
+
})
|
89
|
+
element = doc.elements["//p"]
|
90
|
+
assert_equal([:foo_bar, :baz], Microformats.classes_for_element(element))
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_should_return_empty_array_for_list_of_css_classes_when_none_exist
|
94
|
+
doc = REXML::Document.new(%{
|
95
|
+
<html>
|
96
|
+
<body>
|
97
|
+
<p>
|
98
|
+
Hello
|
99
|
+
</p>
|
100
|
+
</body>
|
101
|
+
</html>
|
102
|
+
})
|
103
|
+
element = doc.elements["//p"]
|
104
|
+
assert_equal([], Microformats.classes_for_element(element))
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_should_convert_css_class_to_symbol_by_changing_hyphens
|
108
|
+
assert_equal(:foo_bar, Microformats.css_class_to_sym('foo-bar'))
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_should_find_rel_tags_above_element
|
112
|
+
doc = REXML::Document.new(%{
|
113
|
+
<html>
|
114
|
+
<body>
|
115
|
+
<a href="http://example.com/foo" rel="tag">Foo</a>
|
116
|
+
<a href="http://example.com/bar" rel="tag">Bar</a>
|
117
|
+
<p>
|
118
|
+
<a href="http://example.com/baz" rel="tag">Baz</a>
|
119
|
+
</p>
|
120
|
+
</body>
|
121
|
+
</html>
|
122
|
+
|
123
|
+
})
|
124
|
+
element = doc.elements['//p']
|
125
|
+
assert_not_nil(element)
|
126
|
+
assert_equal(%w[foo bar], Microformats.rel_tags_above_element(element))
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_should_find_rel_tags_below_element
|
130
|
+
doc = REXML::Document.new(%{
|
131
|
+
<html>
|
132
|
+
<body>
|
133
|
+
<a href="http://example.com/foo" rel="tag">Foo</a>
|
134
|
+
<a href="http://example.com/bar" rel="tag">Bar</a>
|
135
|
+
<p>
|
136
|
+
<a href="http://example.com/baz" rel="tag">Baz</a>
|
137
|
+
</p>
|
138
|
+
</body>
|
139
|
+
</html>
|
140
|
+
|
141
|
+
})
|
142
|
+
element = doc.elements['//p']
|
143
|
+
assert_not_nil(element)
|
144
|
+
assert_equal(%w[baz], Microformats.rel_tags_below_element(element))
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_should_parse_non_ascii_rel_tags
|
148
|
+
doc = REXML::Document.new(%{
|
149
|
+
<a href="http://technorati.com/tag/Sant%C3%A9+et+bien-%C3%AAtre" rel="tag">Foo</a>
|
150
|
+
})
|
151
|
+
element = doc.elements['//a']
|
152
|
+
assert_equal('Santé et bien-être', Microformats.rel_tag(element))
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_should_extract_correct_part_of_url_for_rel_tag
|
156
|
+
doc = REXML::Document.new(%{
|
157
|
+
<a href="http://technorati.com/tag/tech?tag=fish#emu" rel="tag">Foo</a>
|
158
|
+
})
|
159
|
+
element = doc.elements['//a']
|
160
|
+
assert_equal('tech', Microformats.rel_tag(element))
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_should_not_break_on_partially_formed_rel_tags
|
164
|
+
doc = REXML::Document.new(%{
|
165
|
+
<a rel="tag">Foo</a>
|
166
|
+
})
|
167
|
+
element = doc.elements['//a']
|
168
|
+
assert_nothing_raised{ Microformats.rel_tag(element) }
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_should_find_rel_licenses_in_document
|
172
|
+
doc = REXML::Document.new(%{
|
173
|
+
<html>
|
174
|
+
<body>
|
175
|
+
<a href="http://example.com/link">A random link</a>
|
176
|
+
<a href="http://example.com/licenses/no-dogs-allowed-1.0" rel="license">NDA-1.0</a>
|
177
|
+
<a href="http://example.com/licenses/only-on-tuesdays-2.1" rel="license">Only on Tuesdays 2.1</a>
|
178
|
+
</body>
|
179
|
+
</html>
|
180
|
+
})
|
181
|
+
licenses = Microformats.rel_licenses(doc)
|
182
|
+
assert_not_nil(licenses)
|
183
|
+
assert_equal(2, licenses.length)
|
184
|
+
assert(licenses.include?('http://example.com/licenses/no-dogs-allowed-1.0'))
|
185
|
+
assert(licenses.include?('http://example.com/licenses/only-on-tuesdays-2.1'))
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_should_return_nil_for_rel_licenses_where_none_exist
|
189
|
+
doc = REXML::Document.new(%{
|
190
|
+
<html>
|
191
|
+
<body>
|
192
|
+
<a href="http://example.com/link">A random link</a>
|
193
|
+
</body>
|
194
|
+
</html>
|
195
|
+
})
|
196
|
+
licenses = Microformats.rel_licenses(doc)
|
197
|
+
assert_nil(licenses)
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_should_expand_include_patterns
|
201
|
+
before = REXML::Document.new(%{
|
202
|
+
<div>
|
203
|
+
<span class="vcard">
|
204
|
+
<span class="fn n" id="j">
|
205
|
+
<span class="given-name">James</span> <span class="family-name">Levine</span>
|
206
|
+
</span>
|
207
|
+
</span>
|
208
|
+
<span class="vcard">
|
209
|
+
<object data="#j" class="include" type="text/html"></object>
|
210
|
+
<span class="org">SimplyHired</span>
|
211
|
+
<span class="title">Microformat Brainstormer</span>
|
212
|
+
</span>
|
213
|
+
</div>
|
214
|
+
})
|
215
|
+
after = REXML::Document.new(%{
|
216
|
+
<div>
|
217
|
+
<span class="vcard">
|
218
|
+
<span class="fn n" id="j">
|
219
|
+
<span class="given-name">James</span> <span class="family-name">Levine</span>
|
220
|
+
</span>
|
221
|
+
</span>
|
222
|
+
<span class="vcard">
|
223
|
+
<span class="fn n">
|
224
|
+
<span class="given-name">James</span> <span class="family-name">Levine</span>
|
225
|
+
</span>
|
226
|
+
<span class="org">SimplyHired</span>
|
227
|
+
<span class="title">Microformat Brainstormer</span>
|
228
|
+
</span>
|
229
|
+
</div>
|
230
|
+
})
|
231
|
+
expanded = Microformats.expand_include_patterns!(before)
|
232
|
+
assert_xml_equal(after, expanded)
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: uformats
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.2.1
|
7
|
+
date: 2006-08-02 00:00:00 +01:00
|
8
|
+
summary: A library for parsing various microformats under Ruby
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: paulbattley@reevoo.com
|
12
|
+
homepage:
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
-
|
22
|
+
- ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
signing_key:
|
28
|
+
cert_chain:
|
29
|
+
post_install_message:
|
30
|
+
authors:
|
31
|
+
- Paul Battley
|
32
|
+
files:
|
33
|
+
- lib/uformats.rb
|
34
|
+
- lib/uformats/basic.rb
|
35
|
+
- lib/uformats/hcalendar.rb
|
36
|
+
- lib/uformats/hcard.rb
|
37
|
+
- lib/uformats/hreview.rb
|
38
|
+
- lib/uformats/pluralizer.rb
|
39
|
+
- test/all.rb
|
40
|
+
- test/basic_test.rb
|
41
|
+
- test/hcalendar_test.rb
|
42
|
+
- test/hcard_test.rb
|
43
|
+
- test/hreview_test.rb
|
44
|
+
- test/pluralizer_test.rb
|
45
|
+
- test/test_helper.rb
|
46
|
+
- test/uformats_test.rb
|
47
|
+
- README
|
48
|
+
- CHANGES
|
49
|
+
- COPYING
|
50
|
+
test_files:
|
51
|
+
- test/all.rb
|
52
|
+
rdoc_options: []
|
53
|
+
extra_rdoc_files:
|
54
|
+
- README
|
55
|
+
- CHANGES
|
56
|
+
- COPYING
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
requirements: []
|
60
|
+
dependencies:
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: htmlentities
|
63
|
+
version_requirement:
|
64
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
65
|
+
requirements:
|
66
|
+
-
|
67
|
+
- ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.0.1
|
70
|
+
version:
|