-
Notifications
You must be signed in to change notification settings - Fork 1
/
screen_size_test.go
77 lines (56 loc) · 1.86 KB
/
screen_size_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
69
70
71
72
73
74
75
76
77
package main
import (
"testing"
)
func TestParseScreenSize(t *testing.T) {
scr1 := parseScreenSize("portrait-primary", "1376x774", "1376x389", "1.3953488372093024", "24")
if scr1.ScrColorDepth != 24 {
t.Errorf("invalid color depth")
}
if scr1.ScrDevicePixelRatio != 1.3953488372093024 {
t.Errorf("invalid device pixel ratio")
}
if scr1.ScrResolution != "1920x1080" || !scr1.ScrScreenOrientationIsPortrait {
t.Errorf("invalid screen orientation")
}
if scr1.ScrResolution == "" {
t.Errorf("invalid Resolution")
}
scr11 := parseScreenSize("portrait-secondary", "1376x774", "1376x389", "1", "16")
if scr11.ScrColorDepth != 16 {
t.Errorf("invalid color depth")
}
if scr11.ScrDevicePixelRatio != 1 {
t.Errorf("invalid device pixel ratio")
}
if !scr11.ScrScreenOrientationIsPortrait || !scr11.ScrScreenOrientationIsSecondary {
t.Errorf("invalid screen orientation")
}
scr12 := parseScreenSize("landscape-primary", "1376x774", "1376x389", "", "24")
if scr12.ScrResolution != "" {
t.Errorf("invalid resolution")
}
if scr12.ScrScreenOrientationIsPortrait || scr12.ScrScreenOrientationIsSecondary {
t.Errorf("invalid screen orientation")
}
}
func TestParseScreenSize2(t *testing.T) {
scr1 := parseScreenSize("landscape-secondary", "1376x774", "1376x389", "1.3953488372093024", "24")
if scr1.ScrColorDepth != 24 {
t.Errorf("invalid color depth")
}
if scr1.ScrDevicePixelRatio != 1.3953488372093024 {
t.Errorf("invalid device pixel ratio")
}
if scr1.ScrResolution != "1920x1080" || scr1.ScrScreenOrientationIsPortrait || !scr1.ScrScreenOrientationIsSecondary {
t.Errorf("invalid screen orientation")
}
if scr1.ScrResolution == "" {
t.Errorf("invalid resolution")
}
}
func BenchmarkParseScreenSize(b *testing.B) {
for n := 0; n < b.N; n++ {
parseScreenSize("landscape-primary", "1376x774", "1376x389", "1.3953488372093024", "24")
}
}