Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
d717ff9e
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
GitCode(gitcode.net)2024年7月9日维护升级公告
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d717ff9e
编写于
9月 05, 2010
作者:
S
Santiago Pastorino
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix indentation errors
上级
88dfe16d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
47 addition
and
47 deletion
+47
-47
actionpack/test/template/number_helper_test.rb
actionpack/test/template/number_helper_test.rb
+47
-47
未找到文件。
actionpack/test/template/number_helper_test.rb
浏览文件 @
d717ff9e
...
...
@@ -184,54 +184,54 @@ def test_number_to_human_size_with_custom_delimiter_and_separator
end
def
test_number_to_human
assert_equal
'0'
,
number_to_human
(
0
)
assert_equal
'123'
,
number_to_human
(
123
)
assert_equal
'1.23 Thousand'
,
number_to_human
(
1234
)
assert_equal
'12.3 Thousand'
,
number_to_human
(
12345
)
assert_equal
'1.23 Million'
,
number_to_human
(
1234567
)
assert_equal
'1.23 Billion'
,
number_to_human
(
1234567890
)
assert_equal
'1.23 Trillion'
,
number_to_human
(
1234567890123
)
assert_equal
'1.23 Quadrillion'
,
number_to_human
(
1234567890123456
)
assert_equal
'1230 Quadrillion'
,
number_to_human
(
1234567890123456789
)
assert_equal
'490 Thousand'
,
number_to_human
(
489939
,
:precision
=>
2
)
assert_equal
'489.9 Thousand'
,
number_to_human
(
489939
,
:precision
=>
4
)
assert_equal
'489 Thousand'
,
number_to_human
(
489000
,
:precision
=>
4
)
assert_equal
'489.0 Thousand'
,
number_to_human
(
489000
,
:precision
=>
4
,
:strip_insignificant_zeros
=>
false
)
assert_equal
'1.2346 Million'
,
number_to_human
(
1234567
,
:precision
=>
4
,
:significant
=>
false
)
assert_equal
'1,2 Million'
,
number_to_human
(
1234567
,
:precision
=>
1
,
:significant
=>
false
,
:separator
=>
','
)
assert_equal
'1 Million'
,
number_to_human
(
1234567
,
:precision
=>
0
,
:significant
=>
true
,
:separator
=>
','
)
#significant forced to false
assert_equal
'0'
,
number_to_human
(
0
)
assert_equal
'123'
,
number_to_human
(
123
)
assert_equal
'1.23 Thousand'
,
number_to_human
(
1234
)
assert_equal
'12.3 Thousand'
,
number_to_human
(
12345
)
assert_equal
'1.23 Million'
,
number_to_human
(
1234567
)
assert_equal
'1.23 Billion'
,
number_to_human
(
1234567890
)
assert_equal
'1.23 Trillion'
,
number_to_human
(
1234567890123
)
assert_equal
'1.23 Quadrillion'
,
number_to_human
(
1234567890123456
)
assert_equal
'1230 Quadrillion'
,
number_to_human
(
1234567890123456789
)
assert_equal
'490 Thousand'
,
number_to_human
(
489939
,
:precision
=>
2
)
assert_equal
'489.9 Thousand'
,
number_to_human
(
489939
,
:precision
=>
4
)
assert_equal
'489 Thousand'
,
number_to_human
(
489000
,
:precision
=>
4
)
assert_equal
'489.0 Thousand'
,
number_to_human
(
489000
,
:precision
=>
4
,
:strip_insignificant_zeros
=>
false
)
assert_equal
'1.2346 Million'
,
number_to_human
(
1234567
,
:precision
=>
4
,
:significant
=>
false
)
assert_equal
'1,2 Million'
,
number_to_human
(
1234567
,
:precision
=>
1
,
:significant
=>
false
,
:separator
=>
','
)
assert_equal
'1 Million'
,
number_to_human
(
1234567
,
:precision
=>
0
,
:significant
=>
true
,
:separator
=>
','
)
#significant forced to false
end
def
test_number_to_human_with_custom_units
#Only integers
volume
=
{
:unit
=>
"ml"
,
:thousand
=>
"lt"
,
:million
=>
"m3"
}
assert_equal
'123 lt'
,
number_to_human
(
123456
,
:units
=>
volume
)
assert_equal
'12 ml'
,
number_to_human
(
12
,
:units
=>
volume
)
assert_equal
'1.23 m3'
,
number_to_human
(
1234567
,
:units
=>
volume
)
#Including fractionals
distance
=
{
:mili
=>
"mm"
,
:centi
=>
"cm"
,
:deci
=>
"dm"
,
:unit
=>
"m"
,
:ten
=>
"dam"
,
:hundred
=>
"hm"
,
:thousand
=>
"km"
}
assert_equal
'1.23 mm'
,
number_to_human
(
0.00123
,
:units
=>
distance
)
assert_equal
'1.23 cm'
,
number_to_human
(
0.0123
,
:units
=>
distance
)
assert_equal
'1.23 dm'
,
number_to_human
(
0.123
,
:units
=>
distance
)
assert_equal
'1.23 m'
,
number_to_human
(
1.23
,
:units
=>
distance
)
assert_equal
'1.23 dam'
,
number_to_human
(
12.3
,
:units
=>
distance
)
assert_equal
'1.23 hm'
,
number_to_human
(
123
,
:units
=>
distance
)
assert_equal
'1.23 km'
,
number_to_human
(
1230
,
:units
=>
distance
)
assert_equal
'1.23 km'
,
number_to_human
(
1230
,
:units
=>
distance
)
assert_equal
'1.23 km'
,
number_to_human
(
1230
,
:units
=>
distance
)
assert_equal
'12.3 km'
,
number_to_human
(
12300
,
:units
=>
distance
)
#The quantifiers don't need to be a continuous sequence
gangster
=
{
:hundred
=>
"hundred bucks"
,
:million
=>
"thousand quids"
}
assert_equal
'1 hundred bucks'
,
number_to_human
(
100
,
:units
=>
gangster
)
assert_equal
'25 hundred bucks'
,
number_to_human
(
2500
,
:units
=>
gangster
)
assert_equal
'25 thousand quids'
,
number_to_human
(
25000000
,
:units
=>
gangster
)
assert_equal
'12300 thousand quids'
,
number_to_human
(
12345000000
,
:units
=>
gangster
)
#Spaces are stripped from the resulting string
assert_equal
'4'
,
number_to_human
(
4
,
:units
=>
{
:unit
=>
""
,
:ten
=>
'tens '
})
assert_equal
'4.5 tens'
,
number_to_human
(
45
,
:units
=>
{
:unit
=>
""
,
:ten
=>
' tens '
})
#Only integers
volume
=
{
:unit
=>
"ml"
,
:thousand
=>
"lt"
,
:million
=>
"m3"
}
assert_equal
'123 lt'
,
number_to_human
(
123456
,
:units
=>
volume
)
assert_equal
'12 ml'
,
number_to_human
(
12
,
:units
=>
volume
)
assert_equal
'1.23 m3'
,
number_to_human
(
1234567
,
:units
=>
volume
)
#Including fractionals
distance
=
{
:mili
=>
"mm"
,
:centi
=>
"cm"
,
:deci
=>
"dm"
,
:unit
=>
"m"
,
:ten
=>
"dam"
,
:hundred
=>
"hm"
,
:thousand
=>
"km"
}
assert_equal
'1.23 mm'
,
number_to_human
(
0.00123
,
:units
=>
distance
)
assert_equal
'1.23 cm'
,
number_to_human
(
0.0123
,
:units
=>
distance
)
assert_equal
'1.23 dm'
,
number_to_human
(
0.123
,
:units
=>
distance
)
assert_equal
'1.23 m'
,
number_to_human
(
1.23
,
:units
=>
distance
)
assert_equal
'1.23 dam'
,
number_to_human
(
12.3
,
:units
=>
distance
)
assert_equal
'1.23 hm'
,
number_to_human
(
123
,
:units
=>
distance
)
assert_equal
'1.23 km'
,
number_to_human
(
1230
,
:units
=>
distance
)
assert_equal
'1.23 km'
,
number_to_human
(
1230
,
:units
=>
distance
)
assert_equal
'1.23 km'
,
number_to_human
(
1230
,
:units
=>
distance
)
assert_equal
'12.3 km'
,
number_to_human
(
12300
,
:units
=>
distance
)
#The quantifiers don't need to be a continuous sequence
gangster
=
{
:hundred
=>
"hundred bucks"
,
:million
=>
"thousand quids"
}
assert_equal
'1 hundred bucks'
,
number_to_human
(
100
,
:units
=>
gangster
)
assert_equal
'25 hundred bucks'
,
number_to_human
(
2500
,
:units
=>
gangster
)
assert_equal
'25 thousand quids'
,
number_to_human
(
25000000
,
:units
=>
gangster
)
assert_equal
'12300 thousand quids'
,
number_to_human
(
12345000000
,
:units
=>
gangster
)
#Spaces are stripped from the resulting string
assert_equal
'4'
,
number_to_human
(
4
,
:units
=>
{
:unit
=>
""
,
:ten
=>
'tens '
})
assert_equal
'4.5 tens'
,
number_to_human
(
45
,
:units
=>
{
:unit
=>
""
,
:ten
=>
' tens '
})
end
def
test_number_to_human_with_custom_format
...
...
@@ -342,7 +342,7 @@ def test_number_helpers_should_raise_error_if_invalid_when_specified
end
assert_raise
InvalidNumberError
do
number_with_delimiter
(
"x"
,
:raise
=>
true
)
number_with_delimiter
(
"x"
,
:raise
=>
true
)
end
begin
number_with_delimiter
(
"x"
,
:raise
=>
true
)
...
...
@@ -351,7 +351,7 @@ def test_number_helpers_should_raise_error_if_invalid_when_specified
end
assert_raise
InvalidNumberError
do
number_to_phone
(
"x"
,
:raise
=>
true
)
number_to_phone
(
"x"
,
:raise
=>
true
)
end
begin
number_to_phone
(
"x"
,
:raise
=>
true
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录