2017-11-20 06:10:04 +01:00
|
|
|
// Copyright (c) 2017 Hervé Gouchet. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT License
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
package template // import "miniflux.app/template"
|
2017-11-20 06:10:04 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
2017-12-13 06:48:13 +01:00
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
"miniflux.app/locale"
|
2017-11-20 06:10:04 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestElapsedTime(t *testing.T) {
|
|
|
|
var dt = []struct {
|
|
|
|
in time.Time
|
|
|
|
out string
|
|
|
|
}{
|
|
|
|
{time.Time{}, NotYet},
|
|
|
|
{time.Now().Add(time.Hour), NotYet},
|
|
|
|
{time.Now(), JustNow},
|
|
|
|
{time.Now().Add(-time.Minute), LastMinute},
|
|
|
|
{time.Now().Add(-time.Minute * 40), fmt.Sprintf(Minutes, 40)},
|
|
|
|
{time.Now().Add(-time.Hour), LastHour},
|
|
|
|
{time.Now().Add(-time.Hour * 3), fmt.Sprintf(Hours, 3)},
|
|
|
|
{time.Now().Add(-time.Hour * 32), Yesterday},
|
|
|
|
{time.Now().Add(-time.Hour * 24 * 3), fmt.Sprintf(Days, 3)},
|
|
|
|
{time.Now().Add(-time.Hour * 24 * 14), fmt.Sprintf(Weeks, 2)},
|
|
|
|
{time.Now().Add(-time.Hour * 24 * 60), fmt.Sprintf(Months, 2)},
|
|
|
|
{time.Now().Add(-time.Hour * 24 * 365 * 3), fmt.Sprintf(Years, 3)},
|
|
|
|
}
|
|
|
|
for i, tt := range dt {
|
2018-02-05 00:45:07 +01:00
|
|
|
if out := elapsedTime(&locale.Language{}, "Local", tt.in); out != tt.out {
|
2018-02-04 23:37:42 +01:00
|
|
|
t.Errorf(`%d. content mismatch for "%v": expected=%q got=%q`, i, tt.in, tt.out, out)
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|