<commit_before>package htmlfiller_test

import (
    "testing"
    . "launchpad.net/gocheck"
	"github.com/griffy/htmlfiller"
)

// hook gocheck into the gotest runner
func Test(t *testing.T) { TestingT(t) }

type S struct {}
var _ = Suite(&S{})

func (s *S) TestFillElement(c *C) {
    html := `<input name="test"/>`
    obsHtml := htmlfiller.FillElement(html, "test", "val")
    expHtml := `<input name="test" value="val"/>`
    c.Check(obsHtml, Equals, expHtml)
    
    html = `<input name="test" value="old"/>`
    obsHtml = htmlfiller.FillElement(html, "test", "val")
    expHtml = `<input name="test" value="val"/>`
    c.Check(obsHtml, Equals, expHtml)
    
    html = `<input name="test"></input>`
    obsHtml = htmlfiller.FillElement(html, "test", "val")
    expHtml = `<input name="test" value="val"></input>`
    c.Check(obsHtml, Equals, expHtml)

    html = `<input name="test" value="old"></input>`
    obsHtml = htmlfiller.FillElement(html, "test", "val")
    expHtml = `<input name="test" value="val"></input>`
    c.Check(obsHtml, Equals, expHtml)

    html = `<select name="test">
    <option value="opt1">Option 1</option>
    <option value="opt2">Option 2</option>
    <option value="opt3">Option 3</option>
    </select>`
    obsHtml = htmlfiller.FillElement(html, "test", "opt2")
    expHtml = `<select name="test">
    <option value="opt1">Option 1</option>
    <option value="opt2" selected="selected">Option 2</option>
    <option value="opt3">Option 3</option>
    </select>`
    c.Check(obsHtml, Equals, expHtml)

    html = `<textarea name="test"></textarea>`
    obsHtml = htmlfiller.FillElement(html, "test", "val")
    expHtml = `<textarea name="test">val</textarea>`
    c.Check(obsHtml, Equals, expHtml)

    html = `<textarea name="test">old</textarea>`
    obsHtml = htmlfiller.FillElement(html, "test", "val")
    expHtml = `<textarea name="test">val</textarea>`
    c.Check(obsHtml, Equals, expHtml)

    html = `<span id="test"></span>`
    obsHtml = htmlfiller.FillElement(html, "test", "val")
    expHtml = `<span id="test">val</span>`
    c.Check(obsHtml, Equals, expHtml)<commit_msg>add a test for checkboxes<commit_after>package htmlfiller_test

import (
    "testing"
    . "launchpad.net/gocheck"
	"github.com/griffy/htmlfiller"
)

// hook gocheck into the gotest runner
func Test(t *testing.T) { TestingT(t) }

type S struct {}
var _ = Suite(&S{})

func (s *S) TestFillElement(c *C) {
    html := `<input name="test"/>`
    obsHtml := htmlfiller.FillElement(html, "test", "val")
    expHtml := `<input name="test" value="val"/>`
    c.Check(obsHtml, Equals, expHtml)
    
    html = `<input name="test" value="old"/>`
    obsHtml = htmlfiller.FillElement(html, "test", "val")
    expHtml = `<input name="test" value="val"/>`
    c.Check(obsHtml, Equals, expHtml)
    
    html = `<input name="test"></input>`
    obsHtml = htmlfiller.FillElement(html, "test", "val")
    expHtml = `<input name="test" value="val"></input>`
    c.Check(obsHtml, Equals, expHtml)

    html = `<input name="test" value="old"></input>`
    obsHtml = htmlfiller.FillElement(html, "test", "val")
    expHtml = `<input name="test" value="val"></input>`
    c.Check(obsHtml, Equals, expHtml)

    html = `<input type="checkbox" name="test" value="val"/>`
    obsHtml = htmlfiller.FillElement(html, "test", "val")
    expHtml = `<input type="checkbox" name="test" value="val" checked="checked"/>`
    c.Check(obsHtml, Equals, expHtml)
    
    html = `<input name="test"></input>`
    obsHtml = htmlfiller.FillElement(html, "test", "val")
    expHtml = `<input name="test" value="val"></input>`
    c.Check(obsHtml, Equals, expHtml)

    html = `<input name="test" value="old"></input>`
    obsHtml = htmlfiller.FillElement(html, "test", "val")
    expHtml = `<input name="test" value="val"></input>`
    c.Check(obsHtml, Equals, expHtml)



    html = `<select name="test">
    <option value="opt1">Option 1</option>
    <option value="opt2">Option 2</option>
    <option value="opt3">Option 3</option>
    </select>`
    obsHtml = htmlfiller.FillElement(html, "test", "opt2")
    expHtml = `<select name="test">
    <option value="opt1">Option 1</option>
    <option value="opt2" selected="selected">Option 2</option>
    <option value="opt3">Option 3</option>
    </select>`
    c.Check(obsHtml, Equals, expHtml)

    html = `<textarea name="test"></textarea>`
    obsHtml = htmlfiller.FillElement(html, "test", "val")
    expHtml = `<textarea name="test">val</textarea>`
    c.Check(obsHtml, Equals, expHtml)

    html = `<textarea name="test">old</textarea>`
    obsHtml = htmlfiller.FillElement(html, "test", "val")
    expHtml = `<textarea name="test">val</textarea>`
    c.Check(obsHtml, Equals, expHtml)

    html = `<span id="test"></span>`
    obsHtml = htmlfiller.FillElement(html, "test", "val")
    expHtml = `<span id="test">val</span>`
    c.Check(obsHtml, Equals, expHtml)
{'fraction_non_alphanumeric': 0.19050529747351264, 'fraction_numerical': 0.005297473512632437, 'mean_word_length': 4.009183673469388, 'pattern_counts': {'":': 0, '<': 93, '<?xml version=': 0, '>': 93, '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': '6770104', 'n_tokens_mistral': 1770, 'n_tokens_neox': 1692, 'n_words': 364}