-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_test.go
133 lines (107 loc) · 2.75 KB
/
parser_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package wttr
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestParseWeather(t *testing.T) {
body := `stockholm
\ / Partly cloudy
_ /"".-. -3(-6) °C
\_( ). → 4 km/h
/(___(__) 10 km
0.0 mm
`
expected := &Weather{
Location: "stockholm",
Description: "Partly cloudy",
Temperature: -3,
WindSpeed: 4,
}
compareWeather(t, body, expected)
}
func TestParseWeather_Mist(t *testing.T) {
body := `szczecin
Mist
_ - _ - _ - -1(-3) °C
_ - _ - _ ← 7 km/h
_ - _ - _ - 3 km
0.0 mm
`
expected := &Weather{
Location: "szczecin",
Description: "Mist",
Temperature: -1,
WindSpeed: 7,
}
compareWeather(t, body, expected)
}
func TestParseWeather_Clear(t *testing.T) {
body := `berlin
\ / Clear
.-. +5(3) °C
― ( ) ― ↘ 4 km/h
` + "`" + `-’ 10 km
/ \ 0.0 mm
`
expected := &Weather{
Location: "berlin",
Description: "Clear",
Temperature: 5,
WindSpeed: 4,
}
compareWeather(t, body, expected)
}
func TestParseWeather_Drizzle(t *testing.T) {
body := `tokyo
_` + "`" + `/"".-. Patchy light drizzle
,\_( ). 17 °C
/(___(__) ↗ 40 km/h
‘ ‘ ‘ ‘ 5 km
‘ ‘ ‘ ‘ 0.2 mm
`
expected := &Weather{
Location: "tokyo",
Description: "Patchy light drizzle",
Temperature: 17,
WindSpeed: 40,
}
compareWeather(t, body, expected)
}
func compareWeather(t *testing.T, body string, expected *Weather) {
actual, err := ParseWeather(body)
if assert.Nil(t, err) {
assert.Equal(t, expected, actual, "ParseWeather: incorrectly parsed weather")
}
}
func TestParseWeather_Empty(t *testing.T) {
_, err := ParseWeather("")
assert.NotNil(t, err, "ParseWeather: empty body error did not occur")
}
func TestParseWeather_MissingLines(t *testing.T) {
body := `stockholm
`
_, err := ParseWeather(body)
assert.NotNil(t, err, "ParseWeather: missing lines error did not occur")
}
func TestParseWeather_MalformedTemperature(t *testing.T) {
body := `stockholm
\ / Partly cloudy
_ /"".-. xxx °C
\_( ). → 4 km/h
/(___(__) 10 km
0.0 mm
`
_, err := ParseWeather(body)
assert.NotNil(t, err, "ParseWeather: malformed temperature error did not occur")
}
func TestParseWeather_MalformedWindSpeed(t *testing.T) {
body := `stockholm
\ / Partly cloudy
_ /"".-. -3(-6) °C
\_( ). → xxxxx
/(___(__) 10 km
0.0 mm
`
_, err := ParseWeather(body)
assert.NotNil(t, err, "ParseWeather: malformed temperature error did not ocur")
}