Skip to content

Commit

Permalink
add analyzer test
Browse files Browse the repository at this point in the history
  • Loading branch information
yukihir0 committed Jul 18, 2015
1 parent 246c8e0 commit a7d8008
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions analyzer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package gec

import (
"testing"
)

func TestAnalyse(t *testing.T) {
docs := []string{
"<html><head><title>hoge</title></head><frameset></frameset></html>",
"<html><head><title>hoge</title><meta http-equiv=\"refresh\" content=\"5;URL=http://www.example.com\"></head></html>",
"<html><head><title>fuga</title></head><body></body></html>",
"<html><head><title>fuga</title></head><body><!-- google_ad_section_start -->a<!-- google_ad_section_end --><!-- google_ad_section_start -->b<!-- google_ad_section_end --></body></html>",
"<html><head><title>fuga</title></head><body><h1>fuga</h1><h2>fuga</h2></body></html>",
}
expecteds := [][]string{
[]string{"", "hoge"},
[]string{"", "hoge"},
[]string{"", "fuga"},
[]string{"", "fuga"},
[]string{"", "fuga"},
}

for i, _ := range docs {
content, title := Analyse(docs[i], nil)
if content != expecteds[i][0] {
t.Errorf("expected %v, but got %v", expecteds[i][0], content)
}

if title != expecteds[i][1] {
t.Errorf("expected %v, but got %v", expecteds[i][1], title)
}
}
}

func TestAnalyseWithOption(t *testing.T) {
opt := NewOption()
docs := []string{
"<html><head><title>hoge</title></head><frameset></frameset></html>",
"<html><head><title>hoge</title><meta http-equiv=\"refresh\" content=\"5;URL=http://www.example.com\"></head></html>",
"<html><head><title>fuga</title></head><body></body></html>",
"<html><head><title>fuga</title></head><body><!-- google_ad_section_start -->a<!-- google_ad_section_end --><!-- google_ad_section_start -->b<!-- google_ad_section_end --></body></html>",
"<html><head><title>fuga</title></head><body><h1>fuga</h1><h2>fuga</h2></body></html>",
}
expecteds := [][]string{
[]string{"", "hoge"},
[]string{"", "hoge"},
[]string{"", "fuga"},
[]string{"", "fuga"},
[]string{"", "fuga"},
}

for i, _ := range docs {
content, title := Analyse(docs[i], opt)
if content != expecteds[i][0] {
t.Errorf("expected %v, but got %v", expecteds[i][0], content)
}

if title != expecteds[i][1] {
t.Errorf("expected %v, but got %v", expecteds[i][1], title)
}
}
}

0 comments on commit a7d8008

Please sign in to comment.