<commit_before>package pansi

import "testing"

func TestInvalidStrings(t *testing.T) {
	invalid := []string{"", "", " ", "OOOOOO", "[", "jj"}

	for _, s := range invalid {
		result := Parse(s)
		if result != nil {
			t.Errorf("AnsiEscapeCode %v is not nil", result.Type)
		}
	}
}

func TestEscapeState(t *testing.T) {
	p := NewParser()

	if p.Result() != nil {
		t.Errorf("NewParser's result is not nil")
	}

	p.Feed('')

	_, ok := p.state.(*escape)

	if !ok {
		t.Errorf("%T is not %T; %+v", p.state, escape{}, ok)
	}

}
<commit_msg>Add tests<commit_after>package pansi

import (
	"github.com/stretchr/testify/assert"
	"reflect"
	"testing"
)

func TestInvalidStrings(t *testing.T) {
	invalid := []string{"", "", " ", "OOOOOO", "[", "jj"}

	for _, s := range invalid {
		result := Parse(s)
		if result != nil {
			t.Errorf("AnsiEscapeCode %v is not nil", result.Type)
		}
	}
}

func TestInitalState(t *testing.T) {
	p := NewParser()
	if p.Result() != nil {
		t.Errorf("NewParser's result is not nil")
	}
}

func TestEscapeState(t *testing.T) {
	p := NewParser()
	p.FeedRune('')
	_, ok := p.state.(*escape)
	if !ok {
		t.Errorf("%T is not %T", p.state, escape{})
	}
}

func TestColorCodes(t *testing.T) {
	codes := []string{"[38;5;49m", "[0m", "[38;5;49m", "[0m", "[38;5;48m", "[0m", "[38;5;48m", "[0m", "[38;5;48m"}
	for _, code := range codes {
		res := Parse(code)
		if res.Type != SetGraphicMode {
			t.Errorf("%T is not %T; %+v", res.Type, SetGraphicMode)
		}
	}
}

func TestColorCode(t *testing.T) {
	type L struct {
		b byte
		s State
	}
	bytes := []L{
		L{0x1B, &escape{}},
		L{0x5b, &csiEntry{}},
		L{0x33, &csiParam{}},
		L{0x38, &csiParam{}},
		L{0x3B, &csiParam{}},
		L{0x35, &csiParam{}},
		L{0x3B, &csiParam{}},
		L{0x34, &csiParam{}},
		L{0x39, &csiParam{}},
		L{0x6D, nil},
	}
	p := NewParser()
	for _, l := range bytes {
		p.Feed(l.b)
		if reflect.TypeOf(p.state) != reflect.TypeOf(l.s) {
			t.Errorf("%T is not %T", p.state, escape{})
		}
	}
	res := p.Result()
	assert.NotNil(t, res, "p.Result() should not be nil")
	assert.Equal(t, res.Type, SetGraphicMode, "res.Type should be SetGraphicMode")
	assert.Equal(t, res.Values, []int{38, 5, 49}, "res.Values got borked")
}

func BenchmarkEscapeState(b *testing.B) {
	for i := 0; i < b.N; i++ {
		p := NewParser()
		p.Feed('')
	}
}

{'fraction_non_alphanumeric': 0.226447709593777, 'fraction_numerical': 0.02592912705272256, 'mean_word_length': 3.6957403651115617, 'pattern_counts': {'":': 0, '<': 4, '<?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': '6569968', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1018, 'n_words': 215}