github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/regexplru/regexplru_test.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package regexplru
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  func TestRegexpLru(t *testing.T) {
    15  	r, err := GetCompiled("a")
    16  	assert.NoError(t, err)
    17  	assert.True(t, r.MatchString("a"))
    18  
    19  	r, err = GetCompiled("a")
    20  	assert.NoError(t, err)
    21  	assert.True(t, r.MatchString("a"))
    22  
    23  	assert.EqualValues(t, 1, lruCache.Len())
    24  
    25  	_, err = GetCompiled("(")
    26  	assert.Error(t, err)
    27  	assert.EqualValues(t, 2, lruCache.Len())
    28  }