<commit_before>package main

import (
    "code.google.com/p/go-html-transform/h5"
    "code.google.com/p/go-html-transform/html/transform"
    "io/ioutil"
    "net/http"
    "strings"
    "testing"
    "time"
)

func curl(url string) string {
    if r, err := http.Get("http://localhost:8080/" + url); err == nil {
        b, err := ioutil.ReadAll(r.Body)
        r.Body.Close()
        if err == nil {
            return string(b)
        }
    }
    return ""
}

func mustContain(t *testing.T, page string, what string) {
    if !strings.Contains(page, what) {
        t.Errorf("Test page did not contain %q", what)
    }
}

func TestStartServer(t *testing.T) {
    go runServer()
    time.Sleep(50 * time.Millisecond)
}

func TestMainPage(t *testing.T) {
    var simpleTests = []struct {
        url string
        out string
    }{
        {"", "container"},
        {"", "header"},
        {"", "subheader"},
        {"", "content"},
        {"", "sidebar"},
        {"", "footer"},
        {"", "blueprint"},
        {"", "utf-8"},
        {"", "gopher.png"},
        {"", "vim_created.png"},
    }
    for _, test := range simpleTests {
        mustContain(t, curl(test.url), test.out)
    }
}

func TestBasicStructure(t *testing.T) {
    var blocks = []string{
        "#header", "#subheader", "#content", "#footer", "#sidebar",
    }
    for _, block := range blocks {
        node := query1(t, "", block)
        if node[0].Data() != "div" {
            t.Errorf("<div> expected, but <%q> found!", node[0].Data())
        }
    }
}

func TestEmptyDatasetGeneratesFriendlyError(t *testing.T) {
    html := curl("")
    mustContain(t, html, "No entries")
}

func TestNonEmptyDatasetHasEntries(t *testing.T) {
    posts = loadData("testdata")
    what := "No entries"
    if strings.Contains(curl(""), what) {
        t.Errorf("Test page should not contain %q", what)
    }
}

func TestEntryHasAuthor(t *testing.T) {
    nodes := query(t, "", "#author")
    for _, node := range nodes {
        if node.Data() != "div" {
            t.Fatalf("<div> expected, but <%q> found!", node.Data())
        }
        if len(node.Children) == 0 {
            t.Fatalf("No author specified in author div!")
        }
        if node.Children[0].Data() != "rtfb" {
            t.Fatalf("'rtfb' expected, but '%q' found!", node.Children[0].Data())
        }
    }<commit_msg>Make sure empty means empty<commit_after>package main

import (
    "code.google.com/p/go-html-transform/h5"
    "code.google.com/p/go-html-transform/html/transform"
    "io/ioutil"
    "net/http"
    "strings"
    "testing"
    "time"
)

func curl(url string) string {
    if r, err := http.Get("http://localhost:8080/" + url); err == nil {
        b, err := ioutil.ReadAll(r.Body)
        r.Body.Close()
        if err == nil {
            return string(b)
        }
    }
    return ""
}

func mustContain(t *testing.T, page string, what string) {
    if !strings.Contains(page, what) {
        t.Errorf("Test page did not contain %q", what)
    }
}

func TestStartServer(t *testing.T) {
    go runServer()
    time.Sleep(50 * time.Millisecond)
}

func TestMainPage(t *testing.T) {
    var simpleTests = []struct {
        url string
        out string
    }{
        {"", "container"},
        {"", "header"},
        {"", "subheader"},
        {"", "content"},
        {"", "sidebar"},
        {"", "footer"},
        {"", "blueprint"},
        {"", "utf-8"},
        {"", "gopher.png"},
        {"", "vim_created.png"},
    }
    for _, test := range simpleTests {
        mustContain(t, curl(test.url), test.out)
    }
}

func TestBasicStructure(t *testing.T) {
    var blocks = []string{
        "#header", "#subheader", "#content", "#footer", "#sidebar",
    }
    for _, block := range blocks {
        node := query1(t, "", block)
        if node[0].Data() != "div" {
            t.Errorf("<div> expected, but <%q> found!", node[0].Data())
        }
    }
}

func TestEmptyDatasetGeneratesFriendlyError(t *testing.T) {
    posts = nil
    html := curl("")
    mustContain(t, html, "No entries")
}

func TestNonEmptyDatasetHasEntries(t *testing.T) {
    posts = loadData("testdata")
    what := "No entries"
    if strings.Contains(curl(""), what) {
        t.Errorf("Test page should not contain %q", what)
    }
}

func TestEntryHasAuthor(t *testing.T) {
    nodes := query(t, "", "#author")
    for _, node := range nodes {
        if node.Data() != "div" {
            t.Fatalf("<div> expected, but <%q> found!", node.Data())
        }
        if len(node.Children) == 0 {
            t.Fatalf("No author specified in author div!")
        }
        if node.Children[0].Data() != "rtfb" {
            t.Fatalf("'rtfb' expected, but '%q' found!", node.Children[0].Data())
        }
    }
{'fraction_non_alphanumeric': 0.18259958071278826, 'fraction_numerical': 0.005870020964360587, 'mean_word_length': 2.214959568733154, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '570133', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1592, 'n_words': 352}