<commit_before>package air

import (
	"net/http"
	"net/url"
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestRequestQueryValueAndFormValue(t *testing.T) {
	a := New()
	c := NewContext(a)

	vs := make(url.Values)
	vs.Set("name", "Air")
	vs.Set("author", "<NAME>")

	req, _ := http.NewRequest(POST, "/?"+vs.Encode(), strings.NewReader(vs.Encode()))
	req.Header.Add(HeaderContentType, MIMEApplicationForm)

	c.feed(req, nil)

	assert.Equal(t, "Air", c.QueryValue("name"))
	assert.Equal(t, "Aofei Sheng", c.QueryValue("author"))
	assert.Equal(t, vs.Get("name"), c.QueryValues().Get("name"))

	assert.Equal(t, "Air", c.FormValue("name"))
	assert.Equal(t, "Aofei Sheng", c.FormValue("author"))
	assert.Equal(t, vs.Get("name"), c.FormValues().Get("name"))
}<commit_msg>test: update request_test.go<commit_after>package air

import (
	"encoding/json"
	"encoding/xml"
	"net/http"
	"net/url"
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestRequestBind(t *testing.T) {
	a := New()
	c := NewContext(a)

	vs := make(url.Values)

	vs.Set("name", "Air")
	vs.Set("author", "<NAME>")

	vs.Set("int", "1")
	vs.Set("int8", "1")
	vs.Set("int16", "1")
	vs.Set("int32", "1")
	vs.Set("int64", "1")

	vs.Set("uint", "1")
	vs.Set("uint8", "1")
	vs.Set("uint16", "1")
	vs.Set("uint32", "1")
	vs.Set("uint64", "1")

	vs.Set("bool", "true")

	vs.Set("float32", "1.11")
	vs.Set("float64", "1.11")

	type Info struct {
		Name   string `query:"name" form:"name" json:"name" xml:"name"`
		Author string `query:"author" form:"author" json:"author" xml:"author"`

		Int   int   `query:"int" form:"int" json:"int" xml:"int"`
		Int8  int8  `query:"int8" form:"int8" json:"int8" xml:"int8"`
		Int16 int16 `query:"int16" form:"int16" json:"int16" xml:"int16"`
		Int32 int32 `query:"int32" form:"int32" json:"int32" xml:"int32"`
		Int64 int64 `query:"int64" form:"int64" json:"int64" xml:"int64"`

		Uint   uint   `query:"uint" form:"uint" json:"uint" xml:"uint"`
		Uint8  uint8  `query:"uint8" form:"uint8" json:"uint8" xml:"uint8"`
		Uint16 uint16 `query:"uint16" form:"uint16" json:"uint16" xml:"uint16"`
		Uint32 uint32 `query:"uint32" form:"uint32" json:"uint32" xml:"uint32"`
		Uint64 uint64 `query:"uint64" form:"uint64" json:"uint64" xml:"uint64"`

		Bool bool `query:"bool" form:"bool" json:"bool" xml:"bool"`

		Float32 float32 `query:"float32" form:"float32" json:"float32" xml:"float32"`
		Float64 float64 `query:"float64" form:"float64" json:"float64" xml:"float64"`
	}

	raw := &Info{
		Name:   vs.Get("name"),
		Author: vs.Get("author"),

		Int:   1,
		Int8:  1,
		Int16: 1,
		Int32: 1,
		Int64: 1,

		Uint:   1,
		Uint8:  1,
		Uint16: 1,
		Uint32: 1,
		Uint64: 1,

		Bool: true,

		Float32: 1.11,
		Float64: 1.11,
	}

	j, _ := json.Marshal(raw)
	x, _ := xml.Marshal(raw)

	req, _ := http.NewRequest(GET, "/?"+vs.Encode(), nil)

	c.reset()
	c.feed(req, nil)

	i := &Info{}

	c.Bind(i)
	assert.Equal(t, *raw, *i)

	req, _ = http.NewRequest(POST, "/", strings.NewReader(vs.Encode()))
	req.Header.Add(HeaderContentType, MIMEApplicationForm)

	c.reset()
	c.feed(req, nil)

	i = &Info{}

	c.Bind(i)
	assert.Equal(t, *raw, *i)

	req, _ = http.NewRequest(POST, "/", strings.NewReader(string(j)))
	req.Header.Add(HeaderContentType, MIMEApplicationJSON)

	c.feed(req, nil)

	i = &Info{}

	c.Bind(i)
	assert.Equal(t, *raw, *i)

	req, _ = http.NewRequest(POST, "/", strings.NewReader(string(x)))
	req.Header.Add(HeaderContentType, MIMEApplicationXML)

	c.feed(req, nil)

	i = &Info{}

	c.Bind(i)
	assert.Equal(t, *raw, *i)
}

func TestRequestOthers(t *testing.T) {
	a := New()
	c := NewContext(a)

	vs := make(url.Values)
	vs.Set("name", "Air")
	vs.Set("author", "<NAME>")

	req, _ := http.NewRequest(POST, "/?"+vs.Encode(), strings.NewReader(vs.Encode()))
	req.Header.Add(HeaderContentType, MIMEApplicationForm)

	c.feed(req, nil)

	assert.Equal(t, vs.Get("name"), c.QueryValues().Get("name"))
	assert.Equal(t, "Air", c.QueryValue("name"))
	assert.Equal(t, "<NAME>", c.QueryValue("author"))

	assert.Equal(t, vs.Get("name"), c.FormValues().Get("name"))
	assert.Equal(t, "Air", c.FormValue("name"))
	assert.Equal(t, "<NAME>", c.FormValue("author"))
}
{'fraction_non_alphanumeric': 0.2228626320845341, 'fraction_numerical': 0.04226705091258405, 'mean_word_length': 4.817039106145251, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 17}, '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': '2797289', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1700, 'n_words': 321}