File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ package utils
2+
3+ import (
4+ "testing"
5+ "time"
6+ )
7+
8+ // TODO test FuzzyAgo
9+
10+ func TestFuzzyAgo (t * testing.T ) {
11+
12+ cases := map [string ]string {
13+ "1s" : "less than a minute ago" ,
14+ "30s" : "less than a minute ago" ,
15+ "1m08s" : "about 1 minute ago" ,
16+ "15m0s" : "about 15 minutes ago" ,
17+ "59m10s" : "about 59 minutes ago" ,
18+ "1h10m02s" : "about 1 hour ago" ,
19+ "15h0m01s" : "about 15 hours ago" ,
20+ "30h10m" : "about 1 day ago" ,
21+ "50h" : "about 2 days ago" ,
22+ }
23+
24+ for duration , expected := range cases {
25+ d , e := time .ParseDuration (duration )
26+ if e != nil {
27+ t .Errorf ("failed to create a duration: %s" , e )
28+ }
29+
30+ fuzzy := FuzzyAgo (d )
31+ if fuzzy != expected {
32+ t .Errorf ("unexpected fuzzy duration value: %s for %s" , fuzzy , duration )
33+ }
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments