Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add delimit method i.e. delimit(1000) == 1,000. - Make titlecase use mutating string manipulation methods. - Make underscore more robust. - Add additional tests (and rename test to match the actual file).
- Loading branch information
Cyril David
committed
Jul 12, 2012
1 parent
6f4bd87
commit b0e76ed
Showing
3 changed files
with
59 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# encoding: utf-8 | ||
|
||
require_relative "helper" | ||
|
||
setup do | ||
obj = Object.new | ||
obj.extend Cuba::TextHelpers | ||
end | ||
|
||
test "truncate" do |helper| | ||
assert_equal "the q...", helper.truncate("the quick brown", 5) | ||
|
||
assert_equal "same string", helper.truncate("same string", 11) | ||
end | ||
|
||
test "markdown" do |helper| | ||
require "bluecloth" | ||
assert_equal "<h1>Hola Mundo</h1>", helper.markdown("# Hola Mundo") | ||
end | ||
|
||
test "nl2br" do |helper| | ||
assert_equal "Hi<br>there<br>Joe", helper.nl2br("Hi\nthere\r\nJoe") | ||
end | ||
|
||
test "currency" do |helper| | ||
assert_equal "$ 2.22", helper.currency(2.221) | ||
assert_equal "€ 2.22", helper.currency(2.221, "€") | ||
end | ||
|
||
test "delimit" do |helper| | ||
assert_equal "2,000", helper.delimit(2000) | ||
assert_equal "2.000", helper.delimit(2000, ".") | ||
assert_equal "2,000,000", helper.delimit(2000000) | ||
assert_equal "2,000,000.05", helper.delimit(2000000.05) | ||
end | ||
|
||
test "titlecase" do |helper| | ||
assert_equal "Hello World", helper.titlecase("hello world") | ||
end | ||
|
||
test "underscore" do |helper| | ||
assert_equal "foo_bar_baz", helper.underscore("FooBarBaz") | ||
assert_equal "ohm_v1_foo", helper.underscore("OhmV1Foo") | ||
assert_equal "ssl_error", helper.underscore("SSLError") | ||
assert_equal "net_http", helper.underscore("NetHTTP") | ||
end |