2012-06-07 03:49:06 +04:00
|
|
|
package microdata
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func ParseData(html string, t *testing.T) *Microdata {
|
2012-06-07 03:49:06 +04:00
|
|
|
p := NewParser(strings.NewReader(html))
|
|
|
|
|
|
|
|
data, err := p.Parse()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected no error but got %d", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if data == nil {
|
|
|
|
t.Errorf("Expected non-nil data")
|
|
|
|
}
|
|
|
|
|
2012-06-07 03:55:09 +04:00
|
|
|
return data
|
2012-06-07 03:49:06 +04:00
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func ParseOneItem(html string, t *testing.T) *Item {
|
|
|
|
data := ParseData(html, t)
|
2012-06-07 03:55:09 +04:00
|
|
|
return data.items[0]
|
|
|
|
}
|
2012-06-07 03:49:06 +04:00
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParse(t *testing.T) {
|
2012-06-07 03:49:06 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope>
|
|
|
|
<p>My name is <span itemprop="name">Elizabeth</span>.</p>
|
|
|
|
</div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:49:06 +04:00
|
|
|
|
|
|
|
if item.properties["name"][0].(string) != "Elizabeth" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseActuallyParses(t *testing.T) {
|
2012-06-07 03:49:06 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope>
|
|
|
|
<p>My name is <span itemprop="name">Daniel</span>.</p>
|
|
|
|
</div>`
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:49:06 +04:00
|
|
|
|
|
|
|
if item.properties["name"][0].(string) != "Daniel" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseThreeProps(t *testing.T) {
|
2012-06-07 03:49:06 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope>
|
|
|
|
<p>My name is <span itemprop="name">Neil</span>.</p>
|
|
|
|
<p>My band is called <span itemprop="band">Four Parts Water</span>.</p>
|
|
|
|
<p>I am <span itemprop="nationality">British</span>.</p>
|
|
|
|
</div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:49:06 +04:00
|
|
|
|
|
|
|
if item.properties["name"][0].(string) != "Neil" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
if item.properties["band"][0].(string) != "Four Parts Water" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
if item.properties["nationality"][0].(string) != "British" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseImgSrc(t *testing.T) {
|
2012-06-07 03:49:06 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope>
|
|
|
|
<img itemprop="image" src="google-logo.png" alt="Google">
|
|
|
|
</div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:49:06 +04:00
|
|
|
|
|
|
|
if item.properties["image"][0].(string) != "google-logo.png" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseAHref(t *testing.T) {
|
2012-06-07 03:49:06 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope>
|
|
|
|
<a itemprop="image" href="google-logo.png">foo</a>
|
|
|
|
</div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:49:06 +04:00
|
|
|
|
|
|
|
if item.properties["image"][0].(string) != "google-logo.png" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseAreaHref(t *testing.T) {
|
2012-06-07 03:49:06 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope><map name="shapes">
|
|
|
|
<area itemprop="foo" href="target.html" shape=rect coords="50,50,100,100">
|
|
|
|
|
|
|
|
</map></div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:49:06 +04:00
|
|
|
|
|
|
|
if item.properties["foo"][0].(string) != "target.html" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseLinkHref(t *testing.T) {
|
2012-06-07 03:49:06 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope>
|
|
|
|
<link itemprop="foo" rel="author" href="target.html">
|
|
|
|
</div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:49:06 +04:00
|
|
|
|
|
|
|
if item.properties["foo"][0].(string) != "target.html" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseAudioSrc(t *testing.T) {
|
2012-06-07 03:49:06 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope>
|
|
|
|
<audio itemprop="foo" src="target"></audio>
|
|
|
|
</div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:49:06 +04:00
|
|
|
|
|
|
|
if item.properties["foo"][0].(string) != "target" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseSourceSrc(t *testing.T) {
|
2012-06-07 03:49:06 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope>
|
|
|
|
<source itemprop="foo" src="target"></source>
|
|
|
|
</div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:49:06 +04:00
|
|
|
|
|
|
|
if item.properties["foo"][0].(string) != "target" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseVideoSrc(t *testing.T) {
|
2012-06-07 03:49:06 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope>
|
|
|
|
<video itemprop="foo" src="target"></video>
|
|
|
|
</div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:49:06 +04:00
|
|
|
|
|
|
|
if item.properties["foo"][0].(string) != "target" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseEmbedSrc(t *testing.T) {
|
2012-06-07 03:49:06 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope>
|
|
|
|
<embed itemprop="foo" src="target"></embed>
|
|
|
|
</div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:49:06 +04:00
|
|
|
|
|
|
|
if item.properties["foo"][0].(string) != "target" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseTrackSrc(t *testing.T) {
|
2012-06-07 03:49:06 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope>
|
|
|
|
<track itemprop="foo" src="target"></track>
|
|
|
|
</div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:49:06 +04:00
|
|
|
|
|
|
|
if item.properties["foo"][0].(string) != "target" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseIFrameSrc(t *testing.T) {
|
2012-06-07 03:49:06 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope>
|
|
|
|
<iframe itemprop="foo" src="target"></iframe>
|
|
|
|
</div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:49:06 +04:00
|
|
|
|
|
|
|
if item.properties["foo"][0].(string) != "target" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseDataValue(t *testing.T) {
|
2012-06-07 03:49:06 +04:00
|
|
|
html := `
|
|
|
|
<h1 itemscope>
|
|
|
|
<data itemprop="product-id" value="9678AOU879">The Instigator 2000</data>
|
|
|
|
</h1>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:49:06 +04:00
|
|
|
|
|
|
|
if item.properties["product-id"][0].(string) != "9678AOU879" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseTimeDatetime(t *testing.T) {
|
2012-06-07 03:49:06 +04:00
|
|
|
html := `
|
|
|
|
<h1 itemscope>
|
|
|
|
I was born on <time itemprop="birthday" datetime="2009-05-10">May 10th 2009</time>.
|
|
|
|
</h1>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:49:06 +04:00
|
|
|
|
|
|
|
if item.properties["birthday"][0].(string) != "2009-05-10" {
|
|
|
|
t.Errorf("Property value not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseTwoValues(t *testing.T) {
|
2012-06-07 03:55:09 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope>
|
|
|
|
<p>Flavors in my favorite ice cream:</p>
|
|
|
|
<ul>
|
|
|
|
<li itemprop="flavor">Lemon sorbet</li>
|
|
|
|
<li itemprop="flavor">Apricot sorbet</li>
|
|
|
|
</ul>
|
|
|
|
</div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 03:57:36 +04:00
|
|
|
if len(item.properties["flavor"]) != 2 {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting 2 values but got %d", len(item.properties["flavor"]))
|
2012-06-07 03:57:36 +04:00
|
|
|
}
|
|
|
|
if item.properties["flavor"][0].(string) != "Lemon sorbet" {
|
|
|
|
t.Errorf("Property value 'Lemon sorbet' not found")
|
2012-06-07 03:55:09 +04:00
|
|
|
}
|
2012-06-07 03:57:36 +04:00
|
|
|
if item.properties["flavor"][1].(string) != "Apricot sorbet" {
|
|
|
|
t.Errorf("Property value 'Apricot sorbet' not found")
|
|
|
|
}
|
|
|
|
|
2012-06-07 03:55:09 +04:00
|
|
|
}
|
2012-06-07 04:09:36 +04:00
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseTwoPropertiesOneValue(t *testing.T) {
|
2012-06-07 04:09:36 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope>
|
|
|
|
<span itemprop="favorite-color favorite-fruit">orange</span>
|
|
|
|
</div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 18:31:43 +04:00
|
|
|
if len(item.properties) != 2 {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting 2 properties but got %d", len(item.properties))
|
2012-06-07 18:31:43 +04:00
|
|
|
}
|
|
|
|
if len(item.properties["favorite-color"]) != 1 {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting 1 value but got %d", len(item.properties["favorite-color"]))
|
2012-06-07 18:31:43 +04:00
|
|
|
}
|
|
|
|
if len(item.properties["favorite-fruit"]) != 1 {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting 1 value but got %d", len(item.properties["favorite-fruit"]))
|
2012-06-07 18:31:43 +04:00
|
|
|
}
|
|
|
|
if item.properties["favorite-color"][0].(string) != "orange" {
|
|
|
|
t.Errorf("Property value 'orange' not found for 'favorite-color'")
|
|
|
|
}
|
|
|
|
if item.properties["favorite-fruit"][0].(string) != "orange" {
|
|
|
|
t.Errorf("Property value 'orange' not found for 'favorite-fruit'")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseTwoPropertiesOneValueMultispaced(t *testing.T) {
|
2012-06-07 18:31:43 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope>
|
|
|
|
<span itemprop=" favorite-color favorite-fruit ">orange</span>
|
|
|
|
</div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 18:31:43 +04:00
|
|
|
if len(item.properties) != 2 {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting 2 properties but got %d", len(item.properties))
|
2012-06-07 18:31:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(item.properties["favorite-color"]) != 1 {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting 1 value but got %d", len(item.properties["favorite-color"]))
|
2012-06-07 04:09:36 +04:00
|
|
|
}
|
2012-06-07 18:31:43 +04:00
|
|
|
if len(item.properties["favorite-fruit"]) != 1 {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting 1 value but got %d", len(item.properties["favorite-fruit"]))
|
2012-06-07 04:09:36 +04:00
|
|
|
}
|
|
|
|
if item.properties["favorite-color"][0].(string) != "orange" {
|
|
|
|
t.Errorf("Property value 'orange' not found for 'favorite-color'")
|
|
|
|
}
|
|
|
|
if item.properties["favorite-fruit"][0].(string) != "orange" {
|
|
|
|
t.Errorf("Property value 'orange' not found for 'favorite-fruit'")
|
|
|
|
}
|
2012-06-07 18:31:43 +04:00
|
|
|
}
|
2012-06-07 04:09:36 +04:00
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseItemType(t *testing.T) {
|
2012-06-07 18:31:43 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope itemtype="http://example.org/animals#cat">
|
|
|
|
<h1 itemprop="name">Hedral</h1>
|
|
|
|
</div>`
|
2012-06-07 04:09:36 +04:00
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 18:31:43 +04:00
|
|
|
if len(item.types) != 1 {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting 1 type but got %d", len(item.types))
|
2012-06-07 18:31:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if item.types[0] != "http://example.org/animals#cat" {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting type of 'http://example.org/animals#cat' but got %d", item.types[0])
|
2012-06-07 18:31:43 +04:00
|
|
|
}
|
2012-06-07 04:09:36 +04:00
|
|
|
}
|
2012-06-07 18:31:43 +04:00
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
func TestParseMultipleItemTypes(t *testing.T) {
|
2012-06-07 18:31:43 +04:00
|
|
|
html := `
|
|
|
|
<div itemscope itemtype=" http://example.org/animals#mammal http://example.org/animals#cat ">
|
|
|
|
<h1 itemprop="name">Hedral</h1>
|
|
|
|
</div>`
|
|
|
|
|
2012-06-07 18:36:08 +04:00
|
|
|
item := ParseOneItem(html, t)
|
2012-06-07 18:31:43 +04:00
|
|
|
if len(item.types) != 2 {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting 2 types but got %d", len(item.types))
|
2012-06-07 18:31:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if item.types[0] != "http://example.org/animals#mammal" {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting type of 'http://example.org/animals#mammal' but got %d", item.types[0])
|
2012-06-07 18:31:43 +04:00
|
|
|
}
|
|
|
|
if item.types[1] != "http://example.org/animals#cat" {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting type of 'http://example.org/animals#cat' but got %d", item.types[1])
|
2012-06-07 18:31:43 +04:00
|
|
|
}
|
2012-06-07 18:36:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseItemId(t *testing.T) {
|
|
|
|
html := `<dl itemscope
|
|
|
|
itemtype="http://vocab.example.net/book"
|
|
|
|
itemid="urn:isbn:0-330-34032-8">
|
|
|
|
<dt>Title
|
|
|
|
<dd itemprop="title">The Reality Dysfunction
|
|
|
|
<dt>Author
|
|
|
|
<dd itemprop="author">Peter F. Hamilton
|
|
|
|
<dt>Publication date
|
|
|
|
<dd><time itemprop="pubdate" datetime="1996-01-26">26 January 1996</time>
|
|
|
|
</dl>`
|
|
|
|
|
|
|
|
item := ParseOneItem(html, t)
|
|
|
|
|
|
|
|
if item.id != "urn:isbn:0-330-34032-8" {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting id of 'urn:isbn:0-330-34032-8' but got %d", item.id)
|
2012-06-07 18:36:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 17:18:33 +04:00
|
|
|
func TestParseItemRef(t *testing.T) {
|
|
|
|
html := `<body><p><figure itemscope itemtype="http://n.whatwg.org/work" itemref="licenses">
|
|
|
|
<img itemprop="work" src="images/house.jpeg" alt="A white house, boarded up, sits in a forest.">
|
|
|
|
<figcaption itemprop="title">The house I found.</figcaption>
|
|
|
|
</figure></p>
|
|
|
|
<p id="licenses">All images licensed under the <a itemprop="license"
|
|
|
|
href="http://www.opensource.org/licenses/mit-license.php">MIT
|
|
|
|
license</a>.</p></body>`
|
|
|
|
|
|
|
|
item := ParseOneItem(html, t)
|
|
|
|
|
|
|
|
if len(item.properties) != 3 {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting 3 properties but got %d", len(item.properties))
|
2012-06-10 17:18:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if item.properties["license"][0].(string) != "http://www.opensource.org/licenses/mit-license.php" {
|
|
|
|
t.Errorf("Property value 'http://www.opensource.org/licenses/mit-license.php' not found for 'license'")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseSharedItemRef(t *testing.T) {
|
|
|
|
html := `<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Photo gallery</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>My photos</h1>
|
|
|
|
<figure itemscope itemtype="http://n.whatwg.org/work" itemref="licenses">
|
|
|
|
<img itemprop="work" src="images/house.jpeg" alt="A white house, boarded up, sits in a forest.">
|
|
|
|
<figcaption itemprop="title">The house I found.</figcaption>
|
|
|
|
</figure>
|
|
|
|
<figure itemscope itemtype="http://n.whatwg.org/work" itemref="licenses">
|
|
|
|
<img itemprop="work" src="images/mailbox.jpeg" alt="Outside the house is a mailbox. It has a leaflet inside.">
|
|
|
|
<figcaption itemprop="title">The mailbox.</figcaption>
|
|
|
|
</figure>
|
|
|
|
<footer>
|
|
|
|
<p id="licenses">All images licensed under the <a itemprop="license"
|
|
|
|
href="http://www.opensource.org/licenses/mit-license.php">MIT
|
|
|
|
license</a>.</p>
|
|
|
|
</footer>
|
|
|
|
</body>
|
|
|
|
</html>`
|
|
|
|
|
|
|
|
data := ParseData(html, t)
|
|
|
|
|
|
|
|
if len(data.items) != 2 {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting 2 items but got %d", len(data.items))
|
2012-06-10 17:18:33 +04:00
|
|
|
}
|
|
|
|
if len(data.items[0].properties) != 3 {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting 3 properties but got %d", len(data.items[0].properties))
|
2012-06-10 17:18:33 +04:00
|
|
|
}
|
|
|
|
if len(data.items[1].properties) != 3 {
|
2012-06-10 17:59:30 +04:00
|
|
|
t.Errorf("Expecting 3 properties but got %d", len(data.items[1].properties))
|
2012-06-10 17:18:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.items[0].properties["license"][0].(string) != "http://www.opensource.org/licenses/mit-license.php" {
|
|
|
|
t.Errorf("Property value 'http://www.opensource.org/licenses/mit-license.php' not found for 'license'")
|
|
|
|
}
|
|
|
|
|
|
|
|
if data.items[1].properties["license"][0].(string) != "http://www.opensource.org/licenses/mit-license.php" {
|
|
|
|
t.Errorf("Property value 'http://www.opensource.org/licenses/mit-license.php' not found for 'license'")
|
|
|
|
}
|
|
|
|
|
2012-06-10 17:59:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseMultiValuedItemRef(t *testing.T) {
|
|
|
|
html := `<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
<div itemscope id="amanda" itemref="a b"></div>
|
|
|
|
<p id="a">Name: <span itemprop="name">Amanda</span></p>
|
|
|
|
<p id="b">Age: <span itemprop="age">26</span></p>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>`
|
|
|
|
|
|
|
|
data := ParseData(html, t)
|
|
|
|
|
|
|
|
if data.items[0].properties["name"][0].(string) != "Amanda" {
|
|
|
|
t.Errorf("Property value 'Amanda' not found for 'name'")
|
|
|
|
}
|
|
|
|
|
|
|
|
if data.items[0].properties["age"][0].(string) != "26" {
|
|
|
|
t.Errorf("Property value '26' not found for 'age'")
|
|
|
|
}
|
|
|
|
}
|