summaryrefslogtreecommitdiffstats
path: root/modules/regexplru/regexplru_test.go
blob: 8c0c72233658d706cf79add1108d72b861adf0ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright 2022 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package regexplru

import (
	"testing"

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

func TestRegexpLru(t *testing.T) {
	r, err := GetCompiled("a")
	require.NoError(t, err)
	assert.True(t, r.MatchString("a"))

	r, err = GetCompiled("a")
	require.NoError(t, err)
	assert.True(t, r.MatchString("a"))

	assert.EqualValues(t, 1, lruCache.Len())

	_, err = GetCompiled("(")
	require.Error(t, err)
	assert.EqualValues(t, 2, lruCache.Len())
}