Merge pull request #210 from Shopify/truncate_utf8_test

UTF8 truncate test
This commit is contained in:
Florian Weingarten
2013-06-17 09:45:10 -07:00
3 changed files with 7 additions and 1 deletions
+1
View File
@@ -4,3 +4,4 @@
pkg
*.rbc
.rvmrc
.ruby-version
+2 -1
View File
@@ -43,7 +43,8 @@ module Liquid
if input.nil? then return end
l = length.to_i - truncate_string.length
l = 0 if l < 0
input.length > length.to_i ? input[0...l] + truncate_string : input
truncated = RUBY_VERSION[0,3] == "1.8" ? input.scan(/./mu)[0...l].to_s : input[0...l]
input.length > length.to_i ? truncated + truncate_string : input
end
def truncatewords(input, words = 15, truncate_string = "...")
+4
View File
@@ -1,3 +1,5 @@
# encoding: utf-8
require 'test_helper'
class Filters
@@ -37,6 +39,7 @@ class StandardFiltersTest < Test::Unit::TestCase
assert_equal '1234567890', @filters.truncate('1234567890', 20)
assert_equal '...', @filters.truncate('1234567890', 0)
assert_equal '1234567890', @filters.truncate('1234567890')
assert_equal "测试...", @filters.truncate("测试测试测试测试", 5)
end
def test_strip
@@ -61,6 +64,7 @@ class StandardFiltersTest < Test::Unit::TestCase
assert_equal 'one two...', @filters.truncatewords('one two three', 2)
assert_equal 'one two three', @filters.truncatewords('one two three')
assert_equal 'Two small (13&#8221; x 5.5&#8221; x 10&#8221; high) baskets fit inside one large basket (13&#8221;...', @filters.truncatewords('Two small (13&#8221; x 5.5&#8221; x 10&#8221; high) baskets fit inside one large basket (13&#8221; x 16&#8221; x 10.5&#8221; high) with cover.', 15)
assert_equal "测试测试测试测试", @filters.truncatewords('测试测试测试测试', 5)
end
def test_strip_html