<commit_before>package lcf

import (
	"errors"
	"testing"

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

type MockSysCall struct {
	mode                uint32
	getStdHandleError   error
	getConsoleModeError error
	setConsoleModeR1    uintptr
	setConsoleModeError error
}

func (s *MockSysCall) getStdHandle() error {
	return s.getStdHandleError
}

func (s *MockSysCall) getConsoleMode(mode *uint32) error {
	*mode = s.mode
	return s.getConsoleModeError
}

func (s *MockSysCall) setConsoleMode(mode uintptr) (uintptr, error) {
	s.mode = uint32(mode)
	return s.setConsoleModeR1, s.setConsoleModeError
}
<commit_msg>Added tests for ConEmu and ANSICON color support.<commit_after>package lcf

import (
	"errors"
	"os"
	"testing"

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

type MockSysCall struct {
	mode                uint32
	getStdHandleError   error
	getConsoleModeError error
	setConsoleModeR1    uintptr
	setConsoleModeError error
}

func (s *MockSysCall) getStdHandle() error {
	return s.getStdHandleError
}

func (s *MockSysCall) getConsoleMode(mode *uint32) error {
	*mode = s.mode
	return s.getConsoleModeError
}

func (s *MockSysCall) setConsoleMode(mode uintptr) (uintptr, error) {
	s.mode = uint32(mode)
	return s.setConsoleModeR1, s.setConsoleModeError
}

// Clear any environment variables indicating colors are supported by ANSICON or ConEmu.
func disableNonnative() {
	os.Setenv("ConEmuANSI", "")
	os.Setenv("ANSICON", "")
	os.Setenv("ANSICON_VER", "")
}

// Enable ConEmu ANSI support.
func enableConEmu() {
	os.Setenv("ConEmuANSI", "ON")
}

// Enable ConEmu ANSI support.
func enableANSICON() {
	// Typical ANSICON environment variables.
	os.Setenv("ANSICON", "80x300")
	os.Setenv("ANSICON_VER", "166")
}

// Keep native disabled and test nonnative color support.
func Test_windowsNativeANSI_NonNative(t *testing.T) {
	assert := require.New(t)
	sc := &MockSysCall{3, nil, nil, 1, nil}

	// No nonnative support.
	disableNonnative()
	enabled, err := windowsNativeANSI(false, false, sc)
	assert.NoError(err)
	assert.False(enabled)

	// Enable ConEmu color support.
	enableConEmu()
	enabled, err = windowsNativeANSI(false, false, sc)
	assert.NoError(err)
	assert.True(enabled)
	disableNonnative()

	// Enable ANSICON color support.
	enableANSICON()
	enabled, err = windowsNativeANSI(false, false, sc)
	assert.NoError(err)
	assert.True(enabled)

	// Enable ConEmu now, meaning both are enabled.
	enableConEmu()
	enabled, err = windowsNativeANSI(false, false, sc)
	assert.NoError(err)
	assert.True(enabled)
	disableNonnative()
}

{'fraction_non_alphanumeric': 0.11049723756906077, 'fraction_numerical': 0.010260457774269928, 'mean_word_length': 4.671140939597316, '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': '4701410', 'n_tokens_mistral': 923, 'n_tokens_neox': 895, 'n_words': 214}