shit works

This commit is contained in:
Shane Becker 2011-06-15 00:35:24 -07:00
parent 9260774403
commit ce2ea993a8
4 changed files with 364 additions and 7 deletions

30
test/hcard.html Normal file
View file

@ -0,0 +1,30 @@
<html>
<head>
<title>Simple hCard</title>
</head>
<body>
<h1 class="h-card">
<a class="p-fn u-url" href="http://factoryjoe.com/">
<span class="p-given-name">Chris</span>
<abbr class="p-additional-name">R.</abbr>
<span class="p-family-name">Messina</span>
</a>
</h1>
<h1 class="h-card">
<a class="p-fn u-url" href="http://iamshane.com">
<span class="p-given-name">Shane</span>
<abbr class="p-additional-name">B</abbr>
<span class="p-family-name">Becker</span>
</a>
</h1>
<h1 class="h-mitch">
<a class="p-snap" href="http://iamshane.com">
<span class="p-krackle">Breakfast</span>
<span class="p-pop">Cereal</span>
</a>
</h1>
</body>
</html>

View file

@ -2,7 +2,174 @@ require "test/unit"
require "microformats2"
class TestMicroformats2 < Test::Unit::TestCase
def test_sanity
flunk "write tests or I will kneecap you"
def test_acceptence_of_string
assert_nothing_raised Microformats2::LoadError do
Microformats2.parse("A String")
end
end
def test_throw_exception_on_non_string_params
assert_raise Microformats2::LoadError do
Microformats2.parse(nil)
end
end
def test_returns_array_of_microformat_objects
result = Microformats2.parse("A String")
assert_equal Array, result.class
end
def test_only_parse_microformats
result = Microformats2.parse("<html><body><p>Something</p></body></html>")
assert_equal 0, result.size
end
def test_extracts_hcard_from_html
hcard = <<-END
<html>
<head>
<title>Simple hCard</title>
</head>
<body>
<h1 class="h-card">
<a class="p-fn u-url" href="http://factoryjoe.com/">
<span class="p-given-name">Chris</span>
<abbr class="p-additional-name">R.</abbr>
<span class="p-family-name">Messina</span>
</a>
</h1>
</body>
</html>
END
result = Microformats2.parse(hcard)
assert_equal HCard, result.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/">
<span class="p-given-name">Chris</span>
<abbr class="p-additional-name">R.</abbr>
<span class="p-family-name">Messina</span>
</a>
</h1>
</body>
</html>
END
result = Microformats2.parse(hcard)
mycard = result.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">
<a class="p-fn u-url" href="http://factoryjoe.com/">
<span class="p-given-name">Chris</span>
<abbr class="p-additional-name">R.</abbr>
<span class="p-family-name">Messina</span>
</a>
<span class="d-bday">1979-09-18</span>
<span class="d-epoch" title="1970-01-01">EPOCH!</span>
</h1>
</body>
</html>
END
result = Microformats2.parse(hcard)
mycard = result.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">
<a class="p-fn u-url" href="http://factoryjoe.com/">
<span class="p-given-name">Chris</span>
<abbr class="p-additional-name">R.</abbr>
<span class="p-family-name">Messina</span>
</a>
<span class="t-start">09:30</span>
<span class="t-end" title="6:00">Leaving time</span>
</h1>
</body>
</html>
END
result = Microformats2.parse(hcard)
mycard = result.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>
</h1>
</body>
</html>
END
result = Microformats2.parse(hcard)
mycard = result.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/">
<span class="p-given-name">Chris</span>
<abbr class="p-additional-name">R.</abbr>
<span class="p-family-name">Messina</span>
</a>
</h1>
</body>
</html>
END
result = Microformats2.parse(hcard)
mycard = result.first
assert_equal "http://factoryjoe.com/", mycard.url
end
end