<commit_before>package util

import (
	"reflect"
	"testing"
)

type pair interface {
	expected() string
	errorType() reflect.Type
}

type simplePair struct {
	input string

	_expected  string
	_errorType reflect.Type
}

func (p simplePair) expected() string        { return p._expected }
func (p simplePair) errorType() reflect.Type { return p._errorType }

var cleanSlashesPairs = []simplePair{
	{"http://maven.java.net", "http://maven.java.net", nil},
	{"http://maven.java.net/", "http://maven.java.net/", nil},
	{"http://maven.java.net/////", "http://maven.java.net/", nil},
	{"http://maven.java.net/nexus", "http://maven.java.net/nexus", nil},
	{"http://maven.java.net/////nexus", "http://maven.java.net/nexus", nil},
	{"http:/maven.java.net", "", reflect.TypeOf(&MalformedUrlError{})},
}

func checkResults(t *testing.T, p pair, actual string, err error) {
	if p.expected() != "" { // a value should have been returned
		if err != nil {
			t.Errorf("expected %v, got an error: %v", p.expected, err)
		}
		if actual != p.expected() {
			t.Errorf("expected %v, got %v", p.expected, actual)
		}
	} else if p.errorType() != nil { // an error should have been returned
		if actual != "" {
			t.Errorf("expected \"\" and an error, got %v", actual)
		}

		actualErrorType := reflect.TypeOf(err)
		if p.errorType() != actualErrorType {
			t.Errorf("expected an error %v, got %v", p.errorType(), actualErrorType)
		}
	} else { // if we're here, the test is broken
		t.Errorf("Test malformed; check the pair: %v", p)
	}
}

func TestCleanSlashes(t *testing.T) {
	for _, p := range cleanSlashesPairs {
		actual, err := cleanSlashes(p.input)

		checkResults(t, p, actual, err)
	}
}

type bfuInput struct {
	host  string
	path  string
	query map[string]string
}

type bfuPair struct {
	input bfuInput

	_expected  string
	_errorType reflect.Type
}

func (p bfuPair) expected() string        { return p._expected }
func (p bfuPair) errorType() reflect.Type { return p._errorType }

var bfuPairs = []bfuPair{
	{bfuInput{"http://maven.java.net", "nexus", map[string]string{}}, "http://maven.java.net/nexus", nil},
	{bfuInput{"http://maven.java.net", "///nexus", map[string]string{}}, "http://maven.java.net/nexus", nil},
	{bfuInput{"http://maven.java.net////", "/nexus", map[string]string{}}, "http://maven.java.net/nexus", nil},
	{bfuInput{"http:/maven.java.net", "/nexus", map[string]string{}}, "", reflect.TypeOf(&MalformedUrlError{})},
	{bfuInput{"http://maven.java.net///", "/nexus", map[string]string{"p": "1"}}, "http://maven.java.net/nexus?p=1", nil},
	{bfuInput{"http://maven.java.net///", "/nexus", map[string]string{"p": "1", "q": "2"}}, "http://maven.java.net/nexus?p=1&q=2", nil},
}

func TestBuildFullUrl(t *testing.T) {
	for _, p := range bfuPairs {
		actual, err := BuildFullUrl(p.input.host, p.input.path, p.input.query)

		checkResults(t, p, actual, err)
	}
}

func TestIfMalformedUrlErrorIsError(t *testing.T) {
	// type assertion only works on interface types, so...
	if _, ok := interface{}(&MalformedUrlError{}).(error); !ok {
		t.Errorf("util.MalformedUrlError does not implement the error interface!")
	}
}<commit_msg>Simplifying tests for util.<commit_after>package util

import (
	"reflect"
	"testing"
)

var cleanSlashesOK = []struct {
	input    string
	expected string
}{
	{"http://maven.java.net", "http://maven.java.net"},
	{"http://maven.java.net/", "http://maven.java.net/"},
	{"http://maven.java.net/////", "http://maven.java.net/"},
	{"http://maven.java.net/nexus", "http://maven.java.net/nexus"},
	{"http://maven.java.net/////nexus", "http://maven.java.net/nexus"},
}

var cleanSlashesErr = []struct {
	input    string
	expected reflect.Type
}{
	{"http:/maven.java.net", reflect.TypeOf(&MalformedUrlError{})},
}

func TestCleanSlashes(t *testing.T) {
	for _, p := range cleanSlashesOK {
		actual, err := cleanSlashes(p.input)

		if err != nil {
			t.Errorf("expected %v, got an error %v", p.expected, err)
		} else if actual != p.expected {
			t.Errorf("expected %v, got %v", p.expected, actual)
		}
	}

	for _, p := range cleanSlashesErr {
		actual, err := cleanSlashes(p.input)

		if actual != "" {
			t.Errorf("expected an error %v, got a value %v", p.expected, actual)
		} else if reflect.TypeOf(err) != p.expected {
			t.Errorf("expected an error %v, got the error %v", p.expected, err)
		}
	}
}

var bfuOk = []struct {
	host  string
	path  string
	query map[string]string

	expected string
}{
	{"http://maven.java.net", "nexus", map[string]string{}, "http://maven.java.net/nexus"},
	{"http://maven.java.net", "///nexus", map[string]string{}, "http://maven.java.net/nexus"},
	{"http://maven.java.net////", "/nexus", map[string]string{}, "http://maven.java.net/nexus"},
	{"http://maven.java.net///", "/nexus", map[string]string{"p": "1"}, "http://maven.java.net/nexus?p=1"},
	{"http://maven.java.net///", "/nexus", map[string]string{"p": "1", "q": "2"}, "http://maven.java.net/nexus?p=1&q=2"},
}

var bfuErr = []struct {
	host  string
	path  string
	query map[string]string

	expected reflect.Type
}{
	{"http:/maven.java.net", "/nexus", map[string]string{}, reflect.TypeOf(&MalformedUrlError{})},
}

func TestBuildFullUrl(t *testing.T) {
	for _, p := range bfuOk {
		actual, err := BuildFullUrl(p.host, p.path, p.query)

		if err != nil {
			t.Errorf("expected %v, got an error %v", p.expected, err)
		} else if actual != p.expected {
			t.Errorf("expected %v, got %v", p.expected, actual)
		}
	}

	for _, p := range bfuErr {
		actual, err := BuildFullUrl(p.host, p.path, p.query)

		if actual != "" {
			t.Errorf("expected an error %v, got a value %v", p.expected, actual)
		} else if reflect.TypeOf(err) != p.expected {
			t.Errorf("expected an error %v, got an error %v", p.expected, err)
		}
	}
}

func TestIfMalformedUrlErrorIsError(t *testing.T) {
	// type assertion only works on interface types, so...
	if _, ok := interface{}(&MalformedUrlError{}).(error); !ok {
		t.Errorf("util.MalformedUrlError does not implement the error interface!")
	}
}
{'fraction_non_alphanumeric': 0.2040133779264214, 'fraction_numerical': 0.002006688963210702, 'mean_word_length': 3.8824489795918367, 'pattern_counts': {'":': 6, '<': 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': '3578179', 'n_tokens_mistral': 2282, 'n_tokens_neox': 2173, 'n_words': 497}