File: gitconfig_test.go

package info (click to toggle)
git-sizer 1.5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 616 kB
  • sloc: sh: 100; makefile: 61
file content (36 lines) | stat: -rw-r--r-- 870 bytes parent folder | download
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
28
29
30
31
32
33
34
35
36
package git

import (
	"fmt"
	"testing"

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

func TestConfigKeyMatchesPrefix(t *testing.T) {
	for _, p := range []struct {
		key, prefix    string
		expectedBool   bool
		expectedString string
	}{
		{"foo.bar", "", true, "foo.bar"},
		{"foo.bar", "foo", true, "bar"},
		{"foo.bar", "foo.", true, "bar"},
		{"foo.bar", "foo.bar", true, ""},
		{"foo.bar", "foo.bar.", false, ""},
		{"foo.bar", "foo.bar.baz", false, ""},
		{"foo.bar", "foo.barbaz", false, ""},
		{"foo.bar.baz", "foo.bar", true, "baz"},
		{"foo.barbaz", "foo.bar", false, ""},
		{"foo.bar", "bar", false, ""},
	} {
		t.Run(
			fmt.Sprintf("TestConfigKeyMatchesPrefix(%q, %q)", p.key, p.prefix),
			func(t *testing.T) {
				ok, s := configKeyMatchesPrefix(p.key, p.prefix)
				assert.Equal(t, p.expectedBool, ok)
				assert.Equal(t, p.expectedString, s)
			},
		)
	}
}