<commit_before>package regexp_test

import (
	"github.com/Shopify/go-lua"
	"github.com/Shopify/goluago/regexp"
	"testing"
)

func TestLuaRegexp(t *testing.T) {
	l := lua.NewState()

	lua.OpenLibraries(l)
	regexp.Open(l)

	failHook := func(l *lua.State) int {
		str, ok := lua.ToString(l, -1)
		if !ok {
			t.Fatalf("need a string on the lua stack for calls to fail()")
		}
		lua.Pop(l, 1)
		t.Error(str)
		return 0
	}
	lua.Register(l, "fail", failHook)
	wantTop := lua.Top(l)

	if err := lua.LoadFile(l, "testdata/regexptest.lua", "t"); err != nil {
		t.Fatalf("loading lua test script in VM, %v", err)
	}

	if err := lua.ProtectedCall(l, 0, 0, 0); err != nil {
		t.Errorf("executing lua test script, %v", err)
	}
	gotTop := lua.Top(l)

	if wantTop != gotTop {
		t.Errorf("Unbalanced stack!, want %d, got %d", wantTop, gotTop)
	}<commit_msg>Use `CheckString` for test harness related func arguments.<commit_after>package regexp_test

import (
	"github.com/Shopify/go-lua"
	"github.com/Shopify/goluago/regexp"
	"testing"
)

func TestLuaRegexp(t *testing.T) {
	l := lua.NewState()

	lua.OpenLibraries(l)
	regexp.Open(l)

	failHook := func(l *lua.State) int {
		str := lua.CheckString(l, -1)
		lua.Pop(l, 1)
		t.Error(str)
		return 0
	}
	lua.Register(l, "fail", failHook)
	wantTop := lua.Top(l)

	if err := lua.LoadFile(l, "testdata/regexptest.lua", "t"); err != nil {
		t.Fatalf("loading lua test script in VM, %v", err)
	}

	if err := lua.ProtectedCall(l, 0, 0, 0); err != nil {
		t.Errorf("executing lua test script, %v", err)
	}
	gotTop := lua.Top(l)

	if wantTop != gotTop {
		t.Errorf("Unbalanced stack!, want %d, got %d", wantTop, gotTop)
	}
{'fraction_non_alphanumeric': 0.17507598784194528, 'fraction_numerical': 0.00729483282674772, 'mean_word_length': 3.7435158501440924, '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': '3274206', 'n_tokens_mistral': 736, 'n_tokens_neox': 677, 'n_words': 165}