<commit_before>package lynx

import (
	"encoding/json"
	"reflect"
	"testing"
)

func TestJSONUnmarshalEJ(t *testing.T) {
	ej := EncryptedJSON{}
	err := json.Unmarshal([]byte(`{"foo":"bar"}`), &ej)
	if err != nil {
		t.Errorf("unexpected error unmarshalling value: %s", err)
		return
	}
	if ej.String() != `{"foo":"bar"}` {
		t.Errorf("unexpected string value: %s", ej.String())
		return
	}
}

func TestJSONMarshalEJ(t *testing.T) {
	ej := NewEncryptedJSON(`{"foo":"bar"}`)
	m, err := json.Marshal(ej)
	if err != nil {
		t.Errorf("unexpected error marshalling value: %s", err)
		return
	}

	if !reflect.DeepEqual(m, []byte(`{"foo":"bar"}`)) {
		t.Errorf("unexpected marshalled value: %s", string(m))
		return
	}
}

func TestUpdatingStringPointerEJ(t *testing.T) {
	ej := NewEncryptedJSON(`{"foo":"bar"}`)
	s := ej.EncryptableString()
	*s = `{"foo":"bar"}`
	if ej.String() != `{"foo":"bar"}` {
		t.Errorf("unexpected string value: %s", ej.String())
		return
	}
}

func TestScanEJ(t *testing.T) {
	for _, e := range []struct {
		Type   string
		Value  interface{}
		Valid  bool
		Output string
	}{
		{"string", `{"foo":"bar"}`, true, `{"foo":"bar"}`},
		{"[]byte", []byte(`{"foo":"bar"}`), true, `{"foo":"bar"}`},
	} {
		ej := EncryptedJSON{}
		err := ej.Scan(e.Value)
		if e.Valid && err != nil {
			t.Errorf("Failed to scan %s: %s", e.Type, err)
			continue
		} else if !e.Valid && err == nil {
			t.Errorf("Failed to not scan %s", e.Type)
			continue
		}

		if !e.Valid {
			continue
		}
	}
}
<commit_msg>Added more tests<commit_after>package lynx

import (
	"encoding/json"
	"reflect"
	"testing"
)

func TestJSONUnmarshalEJ(t *testing.T) {
	ej := EncryptedJSON{}
	err := json.Unmarshal([]byte(`{"foo":"bar"}`), &ej)
	if err != nil {
		t.Errorf("unexpected error unmarshalling value: %s", err)
		return
	}
	if ej.String() != `{"foo":"bar"}` {
		t.Errorf("unexpected string value: %s", ej.String())
		return
	}
}

func TestJSONUnmarshalJSONEJ(t *testing.T) {
	ej := NewEncryptedJSON(``)
	err := ej.UnmarshalJSON([]byte(nil))

	if err == nil {
		t.Error("Expected error: EncryptedJSON: UnmarshalJSON on nil data")
		return
	}
}

func TestJSONMarshalEJ(t *testing.T) {
	ej := NewEncryptedJSON(`{"foo":"bar"}`)
	m, err := json.Marshal(ej)
	if err != nil {
		t.Errorf("unexpected error marshalling value: %s", err)
		return
	}

	if !reflect.DeepEqual(m, []byte(`{"foo":"bar"}`)) {
		t.Errorf("unexpected marshalled value: %s", string(m))
		return
	}
}

func TestUpdatingStringPointerEJ(t *testing.T) {
	ej := NewEncryptedJSON(`{"foo":"bar"}`)
	s := ej.EncryptableString()
	*s = `{"foo":"bar"}`
	if ej.String() != `{"foo":"bar"}` {
		t.Errorf("unexpected string value: %s", ej.String())
		return
	}
}

func TestScanEJ(t *testing.T) {
	for _, e := range []struct {
		Type   string
		Value  interface{}
		Valid  bool
		Output string
	}{
		{"string", `{"foo":"bar"}`, true, `{"foo":"bar"}`},
		{"[]byte", []byte(`{"foo":"bar"}`), true, `{"foo":"bar"}`},
		{"nil", nil, true, ""},
	} {
		ej := EncryptedJSON{}
		err := ej.Scan(e.Value)
		if e.Valid && err != nil {
			t.Errorf("Failed to scan %s: %s", e.Type, err)
			continue
		} else if !e.Valid && err == nil {
			t.Errorf("Failed to not scan %s", e.Type)
			continue
		}

		if !e.Valid {
			continue
		}
	}
}

{'fraction_non_alphanumeric': 0.21887488472179525, 'fraction_numerical': 0.0, 'mean_word_length': 3.9528158295281584, 'pattern_counts': {'":': 22, '<': 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': '7613586', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1259, 'n_words': 287}