-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions_test.go
26 lines (23 loc) · 1.13 KB
/
functions_test.go
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
package shuttle
import "testing"
func TestReadPathElement(t *testing.T) {
assertPathElement(t, "/path/users/value", "users", "value")
assertPathElement(t, "/path/users/value/", "users", "value")
assertPathElement(t, "/path/users/value/other/stuff", "users", "value")
assertPathElement(t, "/not/found/", "users", "")
}
func assertPathElement(t *testing.T, raw, element, expected string) {
Assert(t).That(ReadPathElement(raw, element)).Equals(expected)
}
func TestReadNumericPathElement(t *testing.T) {
assertNumericPathElement(t, "/path/users/123", "users", 123)
assertNumericPathElement(t, "/path/users/123/", "users", 123)
assertNumericPathElement(t, "/path/users/123/other/stuff", "users", 123)
assertNumericPathElement(t, "/path/users/-123/other/stuff", "users", 0)
assertNumericPathElement(t, "/path/users/abc/other/stuff", "users", 0)
assertNumericPathElement(t, "/path/users/abc123/other/stuff", "users", 0)
assertNumericPathElement(t, "/path/users/_123/other/stuff", "users", 0)
}
func assertNumericPathElement(t *testing.T, raw, element string, expected uint64) {
Assert(t).That(ReadNumericPathElement(raw, element)).Equals(expected)
}