Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 51 lines (38 sloc) 1.912 kb
b0540be8 »
2008-10-08 Initial import.
1 require 'test/unit'
2 require File.dirname(__FILE__) + '/test_helper'
3
037d2ba2 »
2009-08-13 Removed Object.try as it is now a part of Rails (as of 2.3 version).
4 class RubyExtensionsTest < ActiveSupport::TestCase
b0540be8 »
2008-10-08 Initial import.
5
6 def test_array_extensions
7 assert [].respond_to?(:arithmetic_mean)
8 assert_equal [1, 2, 3, 4, 5].arithmetic_mean, 3.0
9
10 assert [].respond_to?(:geometric_mean)
11 assert_equal [2, 3, 4.5].geometric_mean, 3.0
12 end
13
14 def test_string_extensions
c8f61520 »
2008-10-09 Added sanitize_as_filename method to the String class.
15 assert ''.respond_to?(:to_slug)
b0540be8 »
2008-10-08 Initial import.
16
17 # to_slug: Polish accented characters
c8f61520 »
2008-10-09 Added sanitize_as_filename method to the String class.
18 assert_equal 'ęóąśłżźćń ĘÓĄŚŁŻŹĆŃ'.to_slug, 'eoaslzzcn-eoaslzzcn'
b0540be8 »
2008-10-08 Initial import.
19
20 # to_slug: Kaszubian accented characters
c8f61520 »
2008-10-09 Added sanitize_as_filename method to the String class.
21 assert_equal 'ÃãÉéËëÒòÔôÙù'.to_slug, 'aaeeeeoooouu'
b0540be8 »
2008-10-08 Initial import.
22
23 # to_slug: Iñtërnâtiônàlizætiøn
c8f61520 »
2008-10-09 Added sanitize_as_filename method to the String class.
24 assert_equal 'Iñtërnâtiônàlizætiøn'.to_slug, 'internationalizaetion'
b0540be8 »
2008-10-08 Initial import.
25
26 # to_slug: other accented characters
c8f61520 »
2008-10-09 Added sanitize_as_filename method to the String class.
27 assert_equal 'āčēģīķļņū'.to_slug, 'acegiklnu'
b0540be8 »
2008-10-08 Initial import.
28 assert_equal '中文測試'.to_slug, 'zhong-wen-ce-shi'
29 assert_equal 'fööbär'.to_slug, 'foobar'
30
31 # to_slug: hyphens
c8f61520 »
2008-10-09 Added sanitize_as_filename method to the String class.
32 assert_equal 'a-b‐c‒d–e—f―g⁃h−i­j'.to_slug, 'a-b-c-d-e-f-g-h-i-j'
b0540be8 »
2008-10-08 Initial import.
33
34 # to_slug: various
c8f61520 »
2008-10-09 Added sanitize_as_filename method to the String class.
35 assert_equal '!@#$%^&*()_+[]{}|;\':",./<>?/// aaaa_bbbb \\ ?@#$?`~'.to_slug, 'aaaa-bbbb'
b0540be8 »
2008-10-08 Initial import.
36 assert_equal '////// meph1sto r0x ! \\\\\\'.to_slug, 'meph1sto-r0x'
c8f61520 »
2008-10-09 Added sanitize_as_filename method to the String class.
37 assert_equal '!@ To$Łódź?żółć!pójdź[]do-mnie'.to_slug, 'to-lodz-zolc-pojdz-do-mnie'
38 assert_equal 'zAżÓłĆ_łódź-–--mą_mnĄ–kÔÔ-tęrr'.to_slug, 'zazolc-lodz-ma-mna-koo-terr'
39 assert_equal 'Czy to był kaszëbskô horror w Żarach?'.to_slug, 'czy-to-byl-kaszebsko-horror-w-zarach'
40
41 # sanitize_as_filename
42 assert_equal 'C:\Temp\ęóąśłżźćń.txt'.sanitize_as_filename, 'eoaslzzcn.txt'
b0540be8 »
2008-10-08 Initial import.
43 end
44
ce72c0c8 »
2009-01-02 Added a new Time formatter (:detailed).
45 def test_time_formatters
46 time = Time.now
47 assert_equal time.strftime('%Y-%m-%d %H:%M'), time.to_s(:detailed)
eb76fabb »
2010-02-06 Added new :brief time formatter.
48 assert_equal time.strftime('%Y-%m-%d'), time.to_s(:brief)
ce72c0c8 »
2009-01-02 Added a new Time formatter (:detailed).
49 end
50
b0540be8 »
2008-10-08 Initial import.
51 end
Something went wrong with that request. Please try again.