mirror of
https://github.com/go-gitea/gitea.git
synced 2025-11-04 21:26:27 +01:00
33 lines
995 B
Go
33 lines
995 B
Go
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repository
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestParseCodeOwnersLine(t *testing.T) {
|
|
type CodeOwnerTest struct {
|
|
Line string
|
|
Tokens []string
|
|
}
|
|
|
|
given := []CodeOwnerTest{
|
|
{Line: "", Tokens: nil},
|
|
{Line: "# comment", Tokens: []string{}},
|
|
{Line: "!.* @user1 @org1/team1", Tokens: []string{"!.*", "@user1", "@org1/team1"}},
|
|
{Line: `.*\\.js @user2 #comment`, Tokens: []string{`.*\.js`, "@user2"}},
|
|
{Line: `docs/(aws|google|azure)/[^/]*\\.(md|txt) @org3 @org2/team2`, Tokens: []string{`docs/(aws|google|azure)/[^/]*\.(md|txt)`, "@org3", "@org2/team2"}},
|
|
{Line: `\#path @org3`, Tokens: []string{`#path`, "@org3"}},
|
|
{Line: `path\ with\ spaces/ @org3`, Tokens: []string{`path with spaces/`, "@org3"}},
|
|
}
|
|
|
|
for _, g := range given {
|
|
tokens := TokenizeCodeOwnersLine(g.Line)
|
|
assert.Equal(t, g.Tokens, tokens, "Codeowners tokenizer failed")
|
|
}
|
|
}
|