Skip to content

Commit 3e19805

Browse files
authored
fix(matchers): name matching case-insensitive (#335)
1 parent 27ed056 commit 3e19805

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Take server state into account in server completions. For example, do not offer started servers as completions for `server start` command.
1313
- Allow using UUID prefix as an argument. For example, if there is only one network available that has an UUID starting with `0316`, details of that network can be listed with `upctl network show 0316` command.
14+
- Match title and name arguments case-insensitively if the given parameter does not resolve with an exact match.
1415

1516
## [3.11.1] - 2024-08-12
1617

internal/resolver/matchers.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ func MatchArgWithWhitespace(arg, value string) MatchType {
1111
if completion.RemoveWordBreaks(value) == arg || value == arg {
1212
return MatchTypeExact
1313
}
14+
if strings.EqualFold(completion.RemoveWordBreaks(value), arg) || strings.EqualFold(value, arg) {
15+
return MatchTypeCaseInsensitive
16+
}
1417
return MatchTypeNone
1518
}
1619

internal/resolver/matchers_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package resolver
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestMatchers(t *testing.T) {
10+
cases := []struct {
11+
name string
12+
execFn func(string, string) MatchType
13+
arg string
14+
value string
15+
expected MatchType
16+
}{
17+
{
18+
name: "Exact match",
19+
execFn: MatchArgWithWhitespace,
20+
arg: "McDuck",
21+
value: "McDuck",
22+
expected: MatchTypeExact,
23+
},
24+
{
25+
name: "Case-insensitive match",
26+
execFn: MatchArgWithWhitespace,
27+
arg: "mcduck",
28+
value: "McDuck",
29+
expected: MatchTypeCaseInsensitive,
30+
},
31+
{
32+
name: "No match",
33+
execFn: MatchArgWithWhitespace,
34+
arg: "scrooge",
35+
value: "McDuck",
36+
expected: MatchTypeNone,
37+
},
38+
}
39+
40+
for _, tt := range cases {
41+
t.Run(tt.name, func(t *testing.T) {
42+
assert.Equal(t, tt.expected, tt.execFn(tt.arg, tt.value))
43+
})
44+
}
45+
}

0 commit comments

Comments
 (0)