<commit_before>package logger

import (
	"testing"
	"regexp"
	"sync"
	"fmt"
	"io/ioutil"
	"os"

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

func TestLogPrint( t *testing.T) {
	var waitGroup sync.WaitGroup
	go_routine_count := 100
	originalStdout := os.Stdout
	read, write, _ := os.Pipe()
	os.Stdout = write

	// run go routines that each make a call
	// to the log.print function and print
	// a unique string
	for i := 0; i < go_routine_count; i++ {
		waitGroup.Add(1)
		go func(counter int) {
			defer waitGroup.Done()
			log.print("info", fmt.Sprintf("At counter %d.", counter))
		}(i)
	}

	waitGroup.Wait()

	write.Close()
	output, _ := ioutil.ReadAll(read)

	os.Stdout = originalStdout

	// check for each of the 
	// unique strings printed 
	// by the go routines
	for j := 0; j < go_routine_count; j++ {
		assert.Regexp(t, regexp.MustCompile(fmt.Sprintf("At counter %d", j)), string(output))
	}
}

func TestGetLevelInt(t *testing.T) {
	integer := getLevelInt("Trace")
	assert.Equal(t, TRACE, integer)

	integer = getLevelInt("DEBUG")
	assert.Equal(t, DEBUG, integer)

	integer = getLevelInt("info")
	assert.Equal(t, INFO, integer)

	integer = getLevelInt("warn")
	assert.Equal(t, WARN, integer)

	integer = getLevelInt("fatal")<commit_msg>Fix the TestLogPrint function<commit_after>package logger

import (
	"fmt"
	"io/ioutil"
	"os"
	"regexp"
	"sync"
	"testing"

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

func TestLogPrint(t *testing.T) {
	var waitGroup sync.WaitGroup
	goRoutineCount := 100
	originalStdout := os.Stdout
	read, write, _ := os.Pipe()
	os.Stdout = write

	// run go routines that each make a call
	// to the log.print function and print
	// a unique string
	for i := 0; i < goRoutineCount; i++ {
		waitGroup.Add(1)
		go func(counter int) {
			defer waitGroup.Done()
			write.Write([]byte(fmt.Sprintf("a%d.", counter)))
		}(i)
	}

	waitGroup.Wait()

	write.Close()
	output, _ := ioutil.ReadAll(read)

	os.Stdout = originalStdout

	// check for each of the
	// unique strings printed
	// by the go routines
	for j := 0; j < goRoutineCount; j++ {
		assert.Regexp(t, regexp.MustCompile(fmt.Sprintf("a%d", j)), string(output))
	}
}

func TestGetLevelInt(t *testing.T) {
	integer := getLevelInt("Trace")
	assert.Equal(t, TRACE, integer)

	integer = getLevelInt("DEBUG")
	assert.Equal(t, DEBUG, integer)

	integer = getLevelInt("info")
	assert.Equal(t, INFO, integer)

	integer = getLevelInt("warn")
	assert.Equal(t, WARN, integer)

	integer = getLevelInt("fatal")
{'fraction_non_alphanumeric': 0.14909090909090908, 'fraction_numerical': 0.0048484848484848485, 'mean_word_length': 3.952, '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': '3489909', 'n_tokens_mistral': 970, 'n_tokens_neox': 913, 'n_words': 228}