tests.TestJustNowOption   B
last analyzed

Complexity

Conditions 5

Size

Total Lines 29
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 22
dl 0
loc 29
rs 8.8853
c 0
b 0
f 0
nop 1
1
package tests
2
3
import (
4
	"testing"
5
	"time"
6
7
	ago "github.com/SerhiiCho/timeago/v3"
8
	"github.com/SerhiiCho/timeago/v3/internal/utils"
9
)
10
11
func TestJustNowOption(t *testing.T) {
12
	cases := []struct {
13
		date time.Time
14
	}{
15
		{utils.SubSeconds(0)},
16
		{utils.SubSeconds(1)},
17
		{utils.SubSeconds(2)},
18
		{utils.SubSeconds(9)},
19
		{utils.SubSeconds(10)},
20
		{utils.SubSeconds(11)},
21
		{utils.SubSeconds(20)},
22
		{utils.SubSeconds(21)},
23
		{utils.SubSeconds(22)},
24
		{utils.SubSeconds(30)},
25
		{utils.SubSeconds(58)},
26
	}
27
28
	for _, tc := range cases {
29
		t.Run("result for "+tc.date.String(), func(test *testing.T) {
30
			ago.Reconfigure(ago.Config{Language: ago.LangEn})
31
32
			res, err := ago.Parse(tc.date, ago.OptJustNow)
33
34
			if err != nil {
35
				test.Errorf("Error must be nil, but got %v instead", err)
36
			}
37
38
			if res != "Just now" {
39
				test.Errorf("Result must be %q, but got %s instead", "Just now", res)
40
			}
41
		})
42
	}
43
}
44