<commit_before>package store_test

import (
	"io/ioutil"
	"os"
	"path"
	"testing"

	"github.com/wx13/genesis/store"
)

func TestFile(t *testing.T) {

	dir, err := ioutil.TempDir("", "genesis_test")
	if err != nil {
		t.Error("Could not create temp dir for testing purposes")
	}
	defer os.RemoveAll(dir)

	storeDir := path.Join(dir, "store")
	os.Mkdir(storeDir, 0755)
	s := store.New(storeDir)
	if s == nil {
		t.Error("Could not create store")
	}

	filename := path.Join(dir, "myfile.txt")
	text := "This is line 1,\nand this is line two.\n\nNow line four.\n"
	ioutil.WriteFile(filename, []byte(text), 0644)

	s.SaveFile(filename, "")
	os.Remove(filename)
	s.RestoreFile(filename, "")

	data, err := ioutil.ReadFile(filename)
	if string(data) != text {
		t.Error("Restored file is not equal to original file.")
	}

}
<commit_msg>more tests for store package<commit_after>package store_test

import (
	"io/ioutil"
	"os"
	"path"
	"testing"

	"github.com/wx13/genesis/store"
)

func TestStore(t *testing.T) {

	dir, err := ioutil.TempDir("", "genesis_test")
	if err != nil {
		t.Error("Could not create temp dir for testing purposes")
	}
	defer os.RemoveAll(dir)

	storeDir := path.Join(dir, "store")
	os.Mkdir(storeDir, 0755)
	s := store.New(storeDir)
	if s == nil {
		t.Error("Could not create store")
	}

	filename := path.Join(dir, "myfile.txt")
	text := "This is line 1,\nand this is line two.\n\nNow line four.\n"
	ioutil.WriteFile(filename, []byte(text), 0644)

	s.SaveFile(filename, "")
	os.Remove(filename)
	s.RestoreFile(filename, "")

	data, err := ioutil.ReadFile(filename)
	if string(data) != text {
		t.Error("Restored file is not equal to original file.")
	}

	text2 := "This is line 27,\nand this is line owt.\n3\nNow line four.\n"
	s.SavePatch(filename, text, text2, "foo")
	ioutil.WriteFile(filename, []byte(text2), 0644)
	s.ApplyPatch(filename, "foo")
	data, err = ioutil.ReadFile(filename)
	if string(data) != text {
		t.Error("Patched file is not equal to original file.")
	}

}

{'fraction_non_alphanumeric': 0.1627441161742614, 'fraction_numerical': 0.01602403605408112, 'mean_word_length': 4.096938775510204, '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': '615926', 'n_tokens_mistral': 814, 'n_tokens_neox': 768, 'n_words': 190}