<commit_before>package reader

import (
	"testing"

	"os"

	"github.com/stretchr/testify/assert"
)

func TestNewInstanceHavingInputFile(t *testing.T) {
	// given
	file := new(os.File)
	c := newFileReaderMockedConfiguration(file)

	// when
	sut := newFileReader(c)

	// then
	assert.Equal(t, file, sut.inputFile, "Expected file is different than the specified in configuration.")
}

func TestPipe(t *testing.T) {

}
<commit_msg>File reader test<commit_after>package reader

import (
	"testing"

	"os"

	"path/filepath"

	"github.com/stretchr/testify/assert"
)

func TestNewInstanceHavingInputFile(t *testing.T) {
	assert := assert.New(t)

	// given
	file := new(os.File)
	c := newFileReaderMockedConfiguration(file)

	// when
	sut := newFileReader(c)

	// then
	assert.Equal(file, sut.inputFile, "Expected file is different than the specified in configuration.")
}

func TestPipe(t *testing.T) {
	assert := assert.New(t)

	// given
	file, error := openFuzzSetFile("fuzz_01.txt")
	assert.Nil(error, "Fuzz set file must be available, error: %v", error)

	c := newFileReaderMockedConfiguration(file)
	sut := newFileReader(c)

	var in = make(chan string, 3) // number of lines in fuzz file
	var done = make(chan bool, 1)

	// when
	sut.pipe(in, done)

	// then
	assert.True(<-done, "Reading file should be finished.")
	assert.Equal("001", <-in, "Invalid line read from file.")
	assert.Equal("002", <-in, "Invalid line read from file.")
	assert.Equal("003", <-in, "Invalid line read from file.")
	assert.Len(in, 0, "Read buffer should empty now.")

	assert.Equal(^(uintptr(0)), file.Fd(), "File descriptor should be closed now.")
}

func TestCloseFile(t *testing.T) {
	assert := assert.New(t)

	// given
	file, error := openFuzzSetFile("fuzz_01.txt")
	assert.Nil(error, "Fuzz set file must be available, error: %v", error)

	c := newFileReaderMockedConfiguration(file)
	sut := newFileReader(c)

	// when
	sut.closeFile()

	// then
	assert.Equal(^(uintptr(0)), file.Fd(), "File descriptor should be closed now.")
}

func openFuzzSetFile(fileName string) (*os.File, error) {
	fuzzSetFile := filepath.Join("../../../input-data/", fileName)
	absoluteFilePath, _ := filepath.Abs(fuzzSetFile)

	file, error := os.OpenFile(absoluteFilePath, os.O_RDONLY, 0666)
	if nil != error {
		return nil, error
	}

	_, error = file.Stat()
	if nil != error {
		return nil, error
	}

	return file, nil
}

{'fraction_non_alphanumeric': 0.15145140933950357, 'fraction_numerical': 0.009255363904080775, 'mean_word_length': 4.113978494623656, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2000013', 'n_tokens_mistral': 881, 'n_tokens_neox': 834, 'n_words': 218}