fixed duplicate elements bug
This commit is contained in:
parent
b35a24becc
commit
0903ac0fab
3 changed files with 375 additions and 19 deletions
|
@ -7,12 +7,12 @@ class TestMicroformats2 < Test::Unit::TestCase
|
|||
Microformats2.parse(nil)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_returns_hash_of_microformat_objects
|
||||
result = Microformats2.parse("A String")
|
||||
assert_equal Hash, result.class
|
||||
end
|
||||
|
||||
|
||||
def test_only_parse_microformats
|
||||
result = Microformats2.parse("<html><body><p>Something</p></body></html>")
|
||||
assert_equal 0, result.size
|
||||
|
@ -30,8 +30,10 @@ class TestMicroformats2 < Test::Unit::TestCase
|
|||
</body>
|
||||
</html>
|
||||
END
|
||||
|
||||
result = Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "simple.html")))
|
||||
assert_equal HCard, result[:hcard].first.class
|
||||
assert_equal 2, result[:hcard].length
|
||||
end
|
||||
|
||||
def test_extracts_hcard_from_html
|
||||
|
@ -40,7 +42,7 @@ class TestMicroformats2 < Test::Unit::TestCase
|
|||
<head>
|
||||
<title>Simple hCard</title>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<h1 class="h-card">Chris</h1>
|
||||
</body>
|
||||
|
@ -49,14 +51,14 @@ class TestMicroformats2 < Test::Unit::TestCase
|
|||
result = Microformats2.parse(hcard)
|
||||
assert_equal HCard, result[:hcard].first.class
|
||||
end
|
||||
|
||||
|
||||
def test_constructs_properties_from_hcard
|
||||
hcard = <<-END
|
||||
<html>
|
||||
<head>
|
||||
<title>Simple hCard</title>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<h1 class="h-card">
|
||||
<a class="p-fn u-url" href="http://factoryjoe.com/">
|
||||
|
@ -70,20 +72,20 @@ class TestMicroformats2 < Test::Unit::TestCase
|
|||
END
|
||||
result = Microformats2.parse(hcard)
|
||||
mycard = result[:hcard].first
|
||||
|
||||
|
||||
assert_equal "Chris", mycard.given_name
|
||||
assert_equal "R.", mycard.additional_name
|
||||
assert_equal "Messina", mycard.family_name
|
||||
assert_equal "Chris R. Messina", mycard.fn
|
||||
end
|
||||
|
||||
|
||||
def test_constructs_dates
|
||||
hcard = <<-END
|
||||
<html>
|
||||
<head>
|
||||
<title>Simple hCard</title>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<h1 class="h-card">
|
||||
<span class="d-bday">1979-09-18</span>
|
||||
|
@ -94,18 +96,18 @@ class TestMicroformats2 < Test::Unit::TestCase
|
|||
END
|
||||
result = Microformats2.parse(hcard)
|
||||
mycard = result[:hcard].first
|
||||
|
||||
|
||||
assert_equal DateTime.parse("1979-09-18"), mycard.bday
|
||||
assert_equal DateTime.parse("1970-01-01"), mycard.epoch
|
||||
end
|
||||
|
||||
|
||||
def test_constructs_times
|
||||
hcard = <<-END
|
||||
<html>
|
||||
<head>
|
||||
<title>Simple hCard</title>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<h1 class="h-card">
|
||||
<span class="t-start">09:30</span>
|
||||
|
@ -116,18 +118,18 @@ class TestMicroformats2 < Test::Unit::TestCase
|
|||
END
|
||||
result = Microformats2.parse(hcard)
|
||||
mycard = result[:hcard].first
|
||||
|
||||
|
||||
assert_equal Time.parse("09:30"), mycard.start
|
||||
assert_equal Time.parse("06:00"), mycard.end
|
||||
end
|
||||
|
||||
|
||||
def test_ignores_pattern_matches_not_at_the_beginning_of_class
|
||||
hcard = <<-END
|
||||
<html>
|
||||
<head>
|
||||
<title>Simple hCard</title>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<h1 class="h-card">
|
||||
<span class="p-n-x">Chris</span>
|
||||
|
@ -137,18 +139,18 @@ class TestMicroformats2 < Test::Unit::TestCase
|
|||
END
|
||||
result = Microformats2.parse(hcard)
|
||||
mycard = result[:hcard].first
|
||||
|
||||
|
||||
assert_equal "Chris", mycard.n_x
|
||||
assert mycard.n_x.is_a?(String)
|
||||
end
|
||||
|
||||
|
||||
def test_constructs_urls_from_hcard
|
||||
hcard = <<-END
|
||||
<html>
|
||||
<head>
|
||||
<title>Simple hCard</title>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<h1 class="h-card">
|
||||
<a class="p-fn u-url" href="http://factoryjoe.com/">Chris</a>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue