This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
forked from varstr/uaparser
-
Notifications
You must be signed in to change notification settings - Fork 1
/
do_test.go
68 lines (56 loc) · 1.97 KB
/
do_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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package uaparser
import "testing"
func TestParse(t *testing.T) {
var (
expectedBrowserNames map[string][]string = GetBrowserNames()
expectedOperatingSystems map[string][]string = GetOSNames()
expectedDeviceTypes map[string][]string = GetDeviceTypes()
totalTestCount = 0
)
totalTestCount += _checkExepectations(t, expectedOperatingSystems, "os")
totalTestCount += _checkExepectations(t, expectedBrowserNames, "browser")
totalTestCount += _checkExepectations(t, expectedDeviceTypes, "deviceType")
}
func _checkExepectations(t *testing.T, expectations map[string][]string, testType string) (testCount int) {
var (
uaParseResult *UAInfo
testResult bool
comparedTo string
)
testCount = 0
for expectation := range expectations {
for key := range expectations[expectation] {
uaParseResult = Parse(expectations[expectation][key])
if testType == "browser" {
testResult, comparedTo = _checkBrowser(uaParseResult, expectation)
} else if testType == "os" {
testResult, comparedTo = _checkOs(uaParseResult, expectation)
} else if testType == "deviceType" {
testResult, comparedTo = _checkDeviceType(uaParseResult, expectation)
}
if !testResult {
t.Fatalf("Expected: '%s' got '%s' on: '%s'", expectation, comparedTo, expectations[expectation][key])
}
testCount += 1
}
}
return testCount
}
func _checkBrowser(uainfo *UAInfo, expectation string) (result bool, comparedTo string) {
if uainfo.Browser == nil {
return false, ""
}
return (uainfo.Browser.Name == expectation), uainfo.Browser.Name
}
func _checkOs(uainfo *UAInfo, expectation string) (result bool, comparedTo string) {
if uainfo.OS == nil {
return false, ""
}
return (uainfo.OS.Name == expectation), uainfo.OS.Name
}
func _checkDeviceType(uainfo *UAInfo, expectation string) (result bool, comparedTo string) {
if uainfo.DeviceType == nil {
return false, ""
}
return (uainfo.DeviceType.Name == expectation), uainfo.DeviceType.Name
}