<commit_before>package jsonio

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

type testIO struct {
	*bytes.Buffer
}

func (w *testIO) Seek(offset int64, whence int) (ret int64, err error) {
	if offset != 0 {
		panic("expected offset to be 0")
	}

	if whence != io.SeekStart {
		panic("expected whence to be io.SeekStart")
	}

	return
}

func (w *testIO) Truncate(size int64) error {
	if size != 0 {
		panic("expected size to be 0")
	}

	return nil
}

func newTestIO(s string) *testIO {
	return &testIO{Buffer: bytes.NewBufferString(s)}
}

func TestDecode(t *testing.T) {
	var value struct{ Ok bool }

	r := newTestIO(`{"Ok":true}`)
	if err := Decode(r, &value); err != nil {
		t.Errorf("Decoding unsuccessful: %v", err)
	}

	if !value.Ok {
		t.Errorf("Expected value.Ok to be true, got %v", value)
	}
}

func TestEncode(t *testing.T) {
	var value struct{ Ok bool }
	value.Ok = true

	w := newTestIO("")
	if err := Encode(w, value); err != nil {
		t.Errorf("Encoding unsuccessful: %v", err)
	}

	want := `{"Ok":true}`
	if got, err := w.ReadString('\n'); reflect.DeepEqual(got, want) {
		t.Errorf("Expected %v, got %v %v", want, got, err)
	}
}
<commit_msg>Test bad JSON decodes<commit_after>package jsonio

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

type testIO struct {
	*bytes.Buffer
}

func (w *testIO) Seek(offset int64, whence int) (ret int64, err error) {
	if offset != 0 {
		panic("expected offset to be 0")
	}

	if whence != io.SeekStart {
		panic("expected whence to be io.SeekStart")
	}

	return
}

func (w *testIO) Truncate(size int64) error {
	if size != 0 {
		panic("expected size to be 0")
	}

	return nil
}

func newTestIO(s string) *testIO {
	return &testIO{Buffer: bytes.NewBufferString(s)}
}

func TestDecode(t *testing.T) {
	var value struct{ Ok bool }

	r := newTestIO(`{"Ok":true}`)
	if err := Decode(r, &value); err != nil {
		t.Errorf("Decoding unsuccessful: %v", err)
	}

	if !value.Ok {
		t.Errorf("Expected value.Ok to be true, got %v", value)
	}
}

func TestBadDecode(t *testing.T) {
	var value struct{ Ok bool }

	r := newTestIO(`{"Ok":true`)
	if err := Decode(r, &value); err == nil {
		t.Errorf("Expected error, got %v", err)
	}
}

func TestEncode(t *testing.T) {
	var value struct{ Ok bool }
	value.Ok = true

	w := newTestIO("")
	if err := Encode(w, value); err != nil {
		t.Errorf("Encoding unsuccessful: %v", err)
	}

	want := `{"Ok":true}`
	if got, err := w.ReadString('\n'); reflect.DeepEqual(got, want) {
		t.Errorf("Expected %v, got %v %v", want, got, err)
	}
}

{'fraction_non_alphanumeric': 0.17039106145251395, 'fraction_numerical': 0.007980845969672785, 'mean_word_length': 3.721280602636535, 'pattern_counts': {'":': 5, '<': 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': '2333563', 'n_tokens_mistral': 1028, 'n_tokens_neox': 977, 'n_words': 284}