<commit_before>package rego

import (
	"bytes"
	"fmt"
	"testing"
)

func Test_buildURL(t *testing.T) {
	//func Test_buildURL(method string, secure bool) string {
	var tests = []struct {
		method string
		secure bool
		result string
	}{
		{"/notls", false, "http://www.reddit.com/notls"},
		{"/withtls", true, "https://www.reddit.com/withtls"},
	}

	for _, test := range tests {
		s := buildURL(test.method, test.secure)
		if s != test.result {
			fmt.Printf("%s != %s\n", s, test.result)
			t.Fail()
		}
	}
}

func Test_getJSON(t *testing.T) {
	var tests = []struct {
		json      string
		err       string
		ratelimit bool
	}{
		{"{\"json\": {\"ratelimit\": 1234, \"errors\": [[\"RATELIMIT\", \"Test\",     \"vdelay\"]]}}", "RATELIMIT: Test", true},
		{"{\"json\": {\"errors\": [[\"WRONG_PASSWORD\", \"Test\",     \"passwd\"]]}}", "WRONG_PASSWORD: <PASSWORD>", false},
	}

	for _, test := range tests {
		_, err := getJSON(bytes.NewBufferString(test.json))
		if err.Error() != test.err {
			fmt.Printf("Error is '%s', should be '%s'\n", err, test.err)
			t.Fail()
		}

		if err.(APIError).IsRatelimited() != test.ratelimit {
			fmt.Printf("IsRatelimited '%t', should be '%t'\n", err.(APIError).IsRatelimited(), test.ratelimit)
			t.Fail()
		}
	}
	//func Test_getJSON(rc io.ReadCloser) (*jsonAPIReply, error) {
}
<commit_msg>More tests added<commit_after>package rego

import (
	"bytes"
	"encoding/json"
	"fmt"
	"testing"
	"time"
)

func Test_buildURL(t *testing.T) {
	//func Test_buildURL(method string, secure bool) string {
	var tests = []struct {
		method string
		secure bool
		result string
	}{
		{"/notls", false, "http://www.reddit.com/notls"},
		{"/withtls", true, "https://www.reddit.com/withtls"},
	}

	for _, test := range tests {
		s := buildURL(test.method, test.secure)
		if s != test.result {
			fmt.Printf("%s != %s\n", s, test.result)
			t.Fail()
		}
	}
}

func TestAPIError(t *testing.T) {
	var tests = []struct {
		json      string
		hasError  bool
		ratelimit int
	}{
		{"{\"json\": {\"ratelimit\": 600, \"errors\": [[\"RATELIMIT\", \"Test\",     \"vdelay\"]]}}", true, 599},
		{"{\"json\": {\"errors\": [[\"WRONG_PASSWORD\", \"Test\",     \"passwd\"]]}}", true, 0},
		{"{\"json\": {totallybroken:  }}", true, 0},
		{"{\"json\": { }}", false, 0},
	}

	for _, test := range tests {
		json, err := getJSON(bytes.NewBufferString(test.json))
		if err != nil {
			if !test.hasError {
				fmt.Printf("getJSON() failed but should not. (%s)\n", err)
				t.Fail()
			}
			switch err.(type) {
			case APIError:
				actualErr := fmt.Sprintf("%s: %s", json.Errors[0][0], json.Errors[0][1])
				if err.Error() != actualErr {
					fmt.Printf("Error is '%s', should be '%s'\n", err, actualErr)
					t.Fail()
				}
				if err.(APIError).IsRatelimited() && test.ratelimit == 0 {
					fmt.Printf("IsRatelimited returns '%t', expeced ratelimit is '%d'\n", err.(APIError).IsRatelimited(), test.ratelimit)
					t.Fail()
				}
				if int(err.(APIError).Duration().Seconds()) != test.ratelimit {
					fmt.Printf("Duration is %d, expected %d\n", int(err.(APIError).Duration().Seconds()), test.ratelimit)
					t.Fail()
				}
			}
		} else {
			if test.hasError {
				t.Fail()
				fmt.Printf("getJSON() did not failed but should\n")
			}
		}
	}
}

func Test_timeFromNumber(t *testing.T) {
	var tests = []struct {
		number json.Number
		time   time.Time
	}{
		{"12345.6789", time.Unix(12345, 6789)},
		{"12345", time.Unix(12345, 0)},
		{"123oops456.789", time.Unix(0, 789)},
		{"123oops456", time.Unix(0, 0)},
	}

	for _, test := range tests {
		if timeFromNumber(test.number) != test.time {
			fmt.Printf("%s != %s\n", timeFromNumber(test.number), test.time)
			t.Fail()
		}
	}
}

{'fraction_non_alphanumeric': 0.21584104518236255, 'fraction_numerical': 0.018508437670114317, 'mean_word_length': 3.1808873720136517, 'pattern_counts': {'":': 12, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, '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': '1010872', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1418, 'n_words': 303}