<commit_before>package epp

import (
	"bytes"
	"testing"

	"github.com/nbio/st"
)

func TestDecodeResult(t *testing.T) {
	var r Result
	var buf bytes.Buffer
	d := NewDecoder(&buf)

	buf.Reset()
	buf.WriteString(`<result code="1000"><msg>Command completed successfully</msg></result>`)
	d.Reset()
	err := decodeResult(&d, &r)
	st.Expect(t, err, nil)
	st.Expect(t, r.Code, 1000)
	st.Expect(t, r.Message, "Command completed successfully")
	st.Expect(t, r.IsError(), false)
	st.Expect(t, r.IsFatal(), false)

	buf.Reset()
	buf.WriteString(`<result code="2001"><msg>Command syntax error</msg></result>`)
	d.Reset()
	err = decodeResult(&d, &r)
	st.Expect(t, err, &r)
	st.Expect(t, r.Code, 2001)
	st.Expect(t, r.Message, "Command syntax error")
	st.Expect(t, r.IsError(), true)
	st.Expect(t, r.IsFatal(), false)

	buf.Reset()
	buf.WriteString(`<result code="2501"><msg>Authentication error; server closing connection</msg></result>`)
	d.Reset()
	err = decodeResult(&d, &r)
	st.Expect(t, err, &r)
	st.Expect(t, r.Code, 2501)
	st.Expect(t, r.Message, "Authentication error; server closing connection")
	st.Expect(t, r.IsError(), true)
	st.Expect(t, r.IsFatal(), true)
}<commit_msg>Benchmark decodeResult.<commit_after>package epp

import (
	"bytes"
	"testing"

	"github.com/nbio/st"
)

func TestDecodeResult(t *testing.T) {
	var r Result
	var buf bytes.Buffer
	d := NewDecoder(&buf)

	buf.Reset()
	buf.WriteString(`<result code="1000"><msg>Command completed successfully</msg></result>`)
	d.Reset()
	err := decodeResult(&d, &r)
	st.Expect(t, err, nil)
	st.Expect(t, r.Code, 1000)
	st.Expect(t, r.Message, "Command completed successfully")
	st.Expect(t, r.IsError(), false)
	st.Expect(t, r.IsFatal(), false)

	buf.Reset()
	buf.WriteString(`<result code="2001"><msg>Command syntax error</msg></result>`)
	d.Reset()
	err = decodeResult(&d, &r)
	st.Expect(t, err, &r)
	st.Expect(t, r.Code, 2001)
	st.Expect(t, r.Message, "Command syntax error")
	st.Expect(t, r.IsError(), true)
	st.Expect(t, r.IsFatal(), false)

	buf.Reset()
	buf.WriteString(`<result code="2501"><msg>Authentication error; server closing connection</msg></result>`)
	d.Reset()
	err = decodeResult(&d, &r)
	st.Expect(t, err, &r)
	st.Expect(t, r.Code, 2501)
	st.Expect(t, r.Message, "Authentication error; server closing connection")
	st.Expect(t, r.IsError(), true)
	st.Expect(t, r.IsFatal(), true)
}

func BenchmarkDecodeResult(b *testing.B) {
	b.StopTimer()
	var r Result
	var buf bytes.Buffer
	d := NewDecoder(&buf)
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		b.StopTimer()
		buf.Reset()
		buf.WriteString(`<result code="2501"><msg>Authentication error; server closing connection</msg></result>`)
		d.Reset()
		b.StartTimer()
		decodeResult(&d, &r)
	}
}
{'fraction_non_alphanumeric': 0.19063421828908556, 'fraction_numerical': 0.019542772861356934, 'mean_word_length': 4.936542669584245, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 31, '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': '567610', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1036, 'n_words': 230}