-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewriting old path_utils based on new path syntax
With the new, simplified path syntax, we can replace the old path_utils with a simpler, more efficient new version.
- Loading branch information
Lucas Hinderberger
committed
Jun 7, 2024
1 parent
deb5472
commit d4bbb2b
Showing
4 changed files
with
133 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParsePathSpec(t *testing.T) { | ||
t.Run("happy path", func(t *testing.T) { | ||
testCases := []struct { | ||
s string | ||
expected PathSpec | ||
}{ | ||
{ | ||
s: "@foo.json", | ||
expected: PathSpec{ | ||
Repetitions: 1, | ||
Path: "foo.json", | ||
}, | ||
}, | ||
{ | ||
s: "5@bar.json", | ||
expected: PathSpec{ | ||
Repetitions: 5, | ||
Path: "bar.json", | ||
}, | ||
}, | ||
{ | ||
s: "123@baz.json", | ||
expected: PathSpec{ | ||
Repetitions: 123, | ||
Path: "baz.json", | ||
}, | ||
}, | ||
} | ||
|
||
for i := range testCases { | ||
testCase := testCases[i] | ||
|
||
t.Run(testCase.s, func(t *testing.T) { | ||
actual, ok := ParsePathSpec(testCase.s) | ||
require.True(t, ok) | ||
require.Equal(t, testCase.expected, actual) | ||
}) | ||
|
||
t.Run(testCase.s+" quoted", func(t *testing.T) { | ||
s := `"` + testCase.s + `"` | ||
|
||
actual, ok := ParsePathSpec(s) | ||
require.True(t, ok) | ||
require.Equal(t, testCase.expected, actual) | ||
}) | ||
} | ||
}) | ||
|
||
t.Run("invalid path specs are detected", func(t *testing.T) { | ||
testCases := []string{ | ||
"", // empty | ||
`"@foo.json`, `@foo.json"`, // superfluous quotes | ||
`foo@bar.baz`, `1.23@foo.json`, // non-digit repetitions | ||
`p@old.syntax`, `p5@old.syntax`, `p123@old.syntax`, // old syntax | ||
} | ||
|
||
for _, testCase := range testCases { | ||
s := testCase | ||
|
||
t.Run(s, func(t *testing.T) { | ||
actual, ok := ParsePathSpec(s) | ||
require.False(t, ok) | ||
require.Zero(t, actual) | ||
}) | ||
|
||
t.Run(s+" quoted", func(t *testing.T) { | ||
sq := `"` + s + `"` | ||
|
||
actual, ok := ParsePathSpec(sq) | ||
require.False(t, ok) | ||
require.Zero(t, actual) | ||
}) | ||
} | ||
}) | ||
} |