<commit_before>package client

import (
	"bytes"
	"io"
	"testing"
)

var readVersionTests = []struct {
	line     string
	expected Version
	err      error
}{
	{"HTTP/1.0 ", HTTP_1_0, nil},
	{"HTTP/1.0", Version{}, io.EOF},
	// {"http/1.1", Version{}, fmt.Errorf("ReadVersion: expected %q, got %q at position %v", 'H', 'h', 0)},
}

func TestReadVersion(t *testing.T) {
	for _, tt := range readVersionTests {
		c := &reader{b(tt.line)}
		actual, err := c.ReadVersion()
		if actual != tt.expected || err != tt.err {
			t.Errorf("ReadVersion(%q): expected %v %v, got %v %v", tt.line, tt.expected, tt.err, actual, err)
		}
	}
}

var readStatusCodeTests = []struct {
	line     string
	expected int
	err      error
}{
	{"200 OK\r\n", 200, nil},
	{"200 OK", 200, nil},
	{"200 ", 200, nil},
	{"200", 0, io.EOF},
}

func TestReadStatusCode(t *testing.T) {
	for _, tt := range readStatusCodeTests {
		c := &reader{b(tt.line)}
		actual, err := c.ReadStatusCode()
		if actual != tt.expected || err != tt.err {
			t.Errorf("ReadVersion(%q): expected %v %v, got %v %v", tt.line, tt.expected, tt.err, actual, err)
		}
	}
}

var readStatusLineTests = []struct {
	line string
	Version
	code int
	msg  string
	err  error
}{
	{"HTTP/1.0 200 OK", HTTP_1_0, 200, "OK", nil},
	{"HTTP/1.0 200 OK\r\n", HTTP_1_0, 200, "OK", nil},
	{"HTTP/1.1 200 OK\r\n\r\n", HTTP_1_1, 200, "OK", nil},<commit_msg>More coverage for Start line parsing.<commit_after>package client

import (
	"bytes"
	"errors"
	"io"
	"testing"
)

var readVersionTests = []struct {
	line     string
	expected Version
	err      error
}{
	{"HTTP/1.0 ", HTTP_1_0, nil},
	{"HTTP/1.0", Version{}, io.EOF},
	{"http/1.1", Version{}, errors.New("ReadVersion: expected 'H', got 'h' at position 0")},
	{"Http/1.1", Version{}, errors.New("ReadVersion: expected 'T', got 't' at position 1")},
	{"HTTp/1.1", Version{}, errors.New("ReadVersion: expected 'P', got 'p' at position 3")},
	{"HTTP#1.1", Version{}, errors.New("ReadVersion: expected '/', got '#' at position 4")},
	{"HTTP/11", Version{}, errors.New("ReadVersion: expected '.', got '1' at position 6")},
	{"HTTP/1.10", Version{}, errors.New("ReadVersion: expected ' ', got '0' at position 8")},
}

func TestReadVersion(t *testing.T) {
	for _, tt := range readVersionTests {
		c := &reader{b(tt.line)}
		actual, err := c.ReadVersion()
		if actual != tt.expected || !sameErr(err, tt.err) {
			t.Errorf("ReadVersion(%q): expected %v %v, got %v %v", tt.line, tt.expected, tt.err, actual, err)
		}
	}
}

var readStatusCodeTests = []struct {
	line     string
	expected int
	err      error
}{
	{"200 OK\r\n", 200, nil},
	{"200 OK", 200, nil},
	{"200 ", 200, nil},
	{"200", 0, io.EOF},
	{"20 ", 0, io.EOF},
	{"2000", 0, errors.New("ReadStatusCode: expected ' ', got '0' at position 3")},
}

func TestReadStatusCode(t *testing.T) {
	for _, tt := range readStatusCodeTests {
		c := &reader{b(tt.line)}
		actual, err := c.ReadStatusCode()
		if actual != tt.expected || !sameErr(err, tt.err) {
			t.Errorf("ReadVersion(%q): expected %v %v, got %v %v", tt.line, tt.expected, tt.err, actual, err)
		}
	}
}

func sameErr(a, b error) bool {
	if a != nil && b != nil {
		return a.Error() == b.Error()
	}
	return a == b
}

var readStatusLineTests = []struct {
	line string
	Version
	code int
	msg  string
	err  error
}{
	{"HTTP/1.0 200 OK", HTTP_1_0, 200, "OK", nil},
	{"HTTP/1.0 200 OK\r\n", HTTP_1_0, 200, "OK", nil},
	{"HTTP/1.1 200 OK\r\n\r\n", HTTP_1_1, 200, "OK", nil},
{'fraction_non_alphanumeric': 0.2045916884626562, 'fraction_numerical': 0.043591979075850044, 'mean_word_length': 3.651351351351351, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1962254', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1340, 'n_words': 372}