-
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.
Merge pull request #5 from svityashchuk/ticket-4-allow-unicode-charac…
…ters-in-query Ticket #4 Allow arabic / chinese script characters
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package provider | ||
|
||
import "testing" | ||
|
||
func TestIsValidQuery(t *testing.T) { | ||
testCases := []struct { | ||
Address string | ||
Lat float64 | ||
Lng float64 | ||
Query map[string]string | ||
ShouldBeValid bool | ||
}{ | ||
// Valid - place_id is not empty | ||
{"", 0, 0, map[string]string{"place_id": "foo"}, true}, | ||
// Invalid - address, coordinates and place_id are empty | ||
{"", 0, 0, map[string]string{"place_id": ""}, false}, | ||
{"", 0, 0, map[string]string{}, false}, | ||
// Valid - coordinates present and in correct range | ||
{"", 42, 42, map[string]string{}, true}, | ||
// Invalid - coordinate value out of range | ||
{"", 91, 0, map[string]string{}, false}, | ||
{"", -91, 0, map[string]string{}, false}, | ||
{"", 0, 181, map[string]string{}, false}, | ||
{"", 0, -181, map[string]string{}, false}, | ||
// Valid - address is not empty. Unicode is supported | ||
{"foo-bar (baz)", 0, 0, map[string]string{}, true}, | ||
{"روات", 0, 0, map[string]string{}, true}, | ||
{"北京", 0, 0, map[string]string{}, true}, | ||
{"İstanbul", 0, 0, map[string]string{}, true}, | ||
// Invalid - does not contain language or mark characters | ||
{"___", 0, 0, map[string]string{}, false}, | ||
{" ", 0, 0, map[string]string{}, false}, | ||
{"()", 0, 0, map[string]string{}, false}, | ||
} | ||
|
||
for i, tc := range testCases { | ||
q := Query{ | ||
Address: tc.Address, | ||
Lat: tc.Lat, | ||
Lng: tc.Lng, | ||
Query: tc.Query, | ||
} | ||
|
||
var expectedValidity string | ||
if tc.ShouldBeValid { | ||
expectedValidity = "valid" | ||
} else { | ||
expectedValidity = "invalid" | ||
} | ||
|
||
if q.IsValid() != tc.ShouldBeValid { | ||
t.Errorf("%d: %#v is expected to be %s but it is not", i, q, expectedValidity) | ||
} | ||
} | ||
} |