Passed
Push — v3.0.0 ( 670783...5b9f70 )
by Serhii
01:17
created

tests/location_test.go   A

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 19
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A tests.TestLocationChanges 0 18 4
1
package tests
2
3
import (
4
	"testing"
5
	"time"
6
7
	"github.com/SerhiiCho/timeago/v3"
8
	"github.com/SerhiiCho/timeago/v3/config"
9
)
10
11
func TestLocationChanges(t *testing.T) {
12
	cases := []struct {
13
		loc      string
14
		subHours time.Duration
15
		expect   string
16
	}{
17
		{"Europe/Kiev", 2, "2 hours ago"},
18
		{"America/New_York", 2, "5 hours"},
19
	}
20
21
	for _, tc := range cases {
22
		t.Run(tc.loc, func(test *testing.T) {
23
			timeago.Configure(&config.Config{Location: tc.loc})
24
25
			d := subHours(tc.subHours)
26
27
			if res := timeago.Parse(d); res != tc.expect {
28
				test.Errorf("Result must be %q, but got %q instead", tc.expect, res)
29
			}
30
		})
31
	}
32
}
33