Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
4c1dd1b9
H
hub
项目概览
github
/
hub
大约 1 年 前同步成功
通知
3
Star
22523
Fork
2406
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4c1dd1b9
编写于
10月 28, 2018
作者:
T
tariqibrahim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adding unit tests for util methods
上级
b15d8de5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
63 addition
and
1 deletion
+63
-1
utils/utils.go
utils/utils.go
+3
-1
utils/utils_test.go
utils/utils_test.go
+60
-0
未找到文件。
utils/utils.go
浏览文件 @
4c1dd1b9
...
...
@@ -14,6 +14,8 @@ import (
"github.com/github/hub/ui"
)
var
timeNow
=
time
.
Now
func
Check
(
err
error
)
{
if
err
!=
nil
{
ui
.
Errorln
(
err
)
...
...
@@ -113,7 +115,7 @@ func (c *Color) Brightness() float32 {
}
func
TimeAgo
(
t
time
.
Time
)
string
{
duration
:=
time
.
Since
(
t
)
duration
:=
time
Now
()
.
Sub
(
t
)
minutes
:=
duration
.
Minutes
()
hours
:=
duration
.
Hours
()
days
:=
hours
/
24
...
...
utils/utils_test.go
浏览文件 @
4c1dd1b9
...
...
@@ -3,6 +3,7 @@ package utils
import
(
"github.com/bmizerany/assert"
"testing"
"time"
)
func
TestSearchBrowserLauncher
(
t
*
testing
.
T
)
{
...
...
@@ -16,3 +17,62 @@ func TestSearchBrowserLauncher(t *testing.T) {
func
TestConcatPaths
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
"foo/bar/baz"
,
ConcatPaths
(
"foo"
,
"bar"
,
"baz"
))
}
func
TestTimeAgo
(
t
*
testing
.
T
)
{
timeNow
=
func
()
time
.
Time
{
return
time
.
Date
(
2018
,
10
,
28
,
14
,
34
,
58
,
651387237
,
time
.
UTC
)
}
now
:=
timeNow
()
secAgo
:=
now
.
Add
(
-
1
*
time
.
Second
)
actual
:=
TimeAgo
(
secAgo
)
assert
.
Equal
(
t
,
"now"
,
actual
)
minAgo
:=
now
.
Add
(
-
1
*
time
.
Minute
)
actual
=
TimeAgo
(
minAgo
)
assert
.
Equal
(
t
,
"1 minute ago"
,
actual
)
minsAgo
:=
now
.
Add
(
-
5
*
time
.
Minute
)
actual
=
TimeAgo
(
minsAgo
)
assert
.
Equal
(
t
,
"5 minutes ago"
,
actual
)
hourAgo
:=
now
.
Add
(
-
1
*
time
.
Hour
)
actual
=
TimeAgo
(
hourAgo
)
assert
.
Equal
(
t
,
"1 hour ago"
,
actual
)
hoursAgo
:=
now
.
Add
(
-
3
*
time
.
Hour
)
actual
=
TimeAgo
(
hoursAgo
)
assert
.
Equal
(
t
,
"3 hours ago"
,
actual
)
dayAgo
:=
now
.
Add
(
-
1
*
24
*
time
.
Hour
)
actual
=
TimeAgo
(
dayAgo
)
assert
.
Equal
(
t
,
"1 day ago"
,
actual
)
daysAgo
:=
now
.
Add
(
-
5
*
24
*
time
.
Hour
)
actual
=
TimeAgo
(
daysAgo
)
assert
.
Equal
(
t
,
"5 days ago"
,
actual
)
monthAgo
:=
now
.
Add
(
-
1
*
24
*
31
*
time
.
Hour
)
actual
=
TimeAgo
(
monthAgo
)
assert
.
Equal
(
t
,
"1 month ago"
,
actual
)
monthsAgo
:=
now
.
Add
(
-
2
*
24
*
31
*
time
.
Hour
)
actual
=
TimeAgo
(
monthsAgo
)
assert
.
Equal
(
t
,
"2 months ago"
,
actual
)
yearAgo
:=
now
.
Add
(
-
1
*
24
*
31
*
12
*
time
.
Hour
)
actual
=
TimeAgo
(
yearAgo
)
assert
.
Equal
(
t
,
"1 year ago"
,
actual
)
yearsAgo
:=
now
.
Add
(
-
2
*
24
*
31
*
12
*
time
.
Hour
)
actual
=
TimeAgo
(
yearsAgo
)
assert
.
Equal
(
t
,
"2 years ago"
,
actual
)
}
func
TestColorBrightness
(
t
*
testing
.
T
)
{
c
,
err
:=
NewColor
(
"880000"
)
assert
.
Equal
(
t
,
nil
,
err
)
actual
:=
c
.
Brightness
()
assert
.
Equal
(
t
,
float32
(
0.15946665406227112
),
actual
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录