package microdata import ( "strings" "testing" ) func ReadOneItem(html string, t *testing.T) *Item { 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") } return data.items[0] } func TestRead(t *testing.T) { html := `

My name is Elizabeth.

` item := ReadOneItem(html, t) if item.properties["name"][0].(string) != "Elizabeth" { t.Errorf("Property value not found") } } func TestReadActuallyParses(t *testing.T) { html := `

My name is Daniel.

` item := ReadOneItem(html, t) if item.properties["name"][0].(string) != "Daniel" { t.Errorf("Property value not found") } } func TestReadThreeProps(t *testing.T) { html := `

My name is Neil.

My band is called Four Parts Water.

I am British.

` item := ReadOneItem(html, t) 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") } } func TestReadImgSrc(t *testing.T) { html := `
Google
` item := ReadOneItem(html, t) if item.properties["image"][0].(string) != "google-logo.png" { t.Errorf("Property value not found") } } func TestReadAHref(t *testing.T) { html := `
foo
` item := ReadOneItem(html, t) if item.properties["image"][0].(string) != "google-logo.png" { t.Errorf("Property value not found") } } func TestReadAreaHref(t *testing.T) { html := `
` item := ReadOneItem(html, t) if item.properties["foo"][0].(string) != "target.html" { t.Errorf("Property value not found") } } func TestReadLinkHref(t *testing.T) { html := `
` item := ReadOneItem(html, t) if item.properties["foo"][0].(string) != "target.html" { t.Errorf("Property value not found") } } func TestReadAudioSrc(t *testing.T) { html := `
` item := ReadOneItem(html, t) if item.properties["foo"][0].(string) != "target" { t.Errorf("Property value not found") } } func TestReadSourceSrc(t *testing.T) { html := `
` item := ReadOneItem(html, t) if item.properties["foo"][0].(string) != "target" { t.Errorf("Property value not found") } } func TestReadVideoSrc(t *testing.T) { html := `
` item := ReadOneItem(html, t) if item.properties["foo"][0].(string) != "target" { t.Errorf("Property value not found") } } func TestReadEmbedSrc(t *testing.T) { html := `
` item := ReadOneItem(html, t) if item.properties["foo"][0].(string) != "target" { t.Errorf("Property value not found") } } func TestReadTrackSrc(t *testing.T) { html := `
` item := ReadOneItem(html, t) if item.properties["foo"][0].(string) != "target" { t.Errorf("Property value not found") } } func TestReadIFrameSrc(t *testing.T) { html := `
` item := ReadOneItem(html, t) if item.properties["foo"][0].(string) != "target" { t.Errorf("Property value not found") } } func TestReadDataValue(t *testing.T) { html := `

The Instigator 2000

` item := ReadOneItem(html, t) if item.properties["product-id"][0].(string) != "9678AOU879" { t.Errorf("Property value not found") } } func TestReadTimeDatetime(t *testing.T) { html := `

I was born on .

` item := ReadOneItem(html, t) if item.properties["birthday"][0].(string) != "2009-05-10" { t.Errorf("Property value not found") } }