modalsupport 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -3,5 +3,29 @@ module Enumerable
3
3
  def grep_each(pattern)
4
4
  grep(pattern){|str| yield(Regexp.last_match)}
5
5
  end
6
+
7
+ if RUBY_VERSION < "1.8.7"
8
+ require 'enumerator'
9
+ alias enumerator_each_slice each_slice
10
+ def each_slice(n, &blk)
11
+ if blk
12
+ # each_slice is implemented in the enumerator extension, requiring a block, and is used by enum_slice
13
+ enumerator_each_slice(n, &blk)
14
+ else
15
+ enum_slice(n, &blk)
16
+ end
17
+ end
18
+ end
19
+
20
+ def each_pair(&blk)
21
+ each_slice(2, &blk)
22
+ end
23
+
24
+ # Convert to pairs [[e1,e2], [e3,e4], ...]
25
+ # Note that for a Hash, this is equivalent to hash.to_a.to_pairs which may not be what's intended; hash.to_a is
26
+ # an array of key-value pairs; to_pairs is an array of pairs of key-value pairs.
27
+ def to_pairs
28
+ each_pair.to_a
29
+ end
6
30
 
7
31
  end
data/modalsupport.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{modalsupport}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Javier Goizueta"]
12
- s.date = %q{2010-01-24}
12
+ s.date = %q{2010-02-05}
13
13
  s.description = %q{additional support extensions to ActiveSupport and HoboSupport}
14
14
  s.email = %q{jgoizueta@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
34
34
  "test/test_gsub.rb",
35
35
  "test/test_match.rb",
36
36
  "test/test_relative_path.rb",
37
+ "test/test_slice.rb",
37
38
  "test/test_unindent.rb"
38
39
  ]
39
40
  s.homepage = %q{http://github.com/jgoizueta/modalsupport}
@@ -47,6 +48,7 @@ Gem::Specification.new do |s|
47
48
  "test/test_gsub.rb",
48
49
  "test/test_match.rb",
49
50
  "test/test_relative_path.rb",
51
+ "test/test_slice.rb",
50
52
  "test/test_unindent.rb"
51
53
  ]
52
54
 
data/test/test_grep.rb CHANGED
@@ -2,14 +2,18 @@ require 'helper'
2
2
 
3
3
  class TestGrep < Test::Unit::TestCase
4
4
 
5
- should "pass match info to a block" do
6
- assert_equal %w{AXA AYA AZA}, %w{xxx axa yue asx aya aza}.grep_each(/a.a/){|match| match.to_s.upcase}
7
- end
5
+ context "Applying grep_each to an array" do
6
+
7
+ should "pass match info to a block" do
8
+ assert_equal %w{AXA AYA AZA}, %w{xxx axa yue asx aya aza}.grep_each(/a.a/){|match| match.to_s.upcase}
9
+ end
8
10
 
9
- should "not modify the array" do
10
- str = %w{xxx axa yue asx aya aza}
11
- str.grep_each(/a.a/){|match| match.to_s.upcase}
12
- assert_equal %w{xxx axa yue asx aya aza}, str
11
+ should "not modify the array" do
12
+ str = %w{xxx axa yue asx aya aza}
13
+ str.grep_each(/a.a/){|match| match.to_s.upcase}
14
+ assert_equal %w{xxx axa yue asx aya aza}, str
15
+ end
16
+
13
17
  end
14
18
 
15
19
  end
data/test/test_gsub.rb CHANGED
@@ -1,21 +1,25 @@
1
1
  require 'helper'
2
2
 
3
- class TestMatch < Test::Unit::TestCase
3
+ class TestGsub < Test::Unit::TestCase
4
+
5
+ context "Applying gsub_each to string" do
4
6
 
5
- should "pass match info to a block and use result for substitution" do
6
- assert_equal "xxx AXA yue asx AYA AZA", "xxx axa yue asx aya aza".gsub_each(/a.a/){|match| match.to_s.upcase}
7
- end
7
+ should "pass match info to a block and use result for substitution" do
8
+ assert_equal "xxx AXA yue asx AYA AZA", "xxx axa yue asx aya aza".gsub_each(/a.a/){|match| match.to_s.upcase}
9
+ end
8
10
 
9
- should "not modify the string" do
10
- str = "xxx axa yue asx aya aza"
11
- str.gsub_each(/a.a/){|match| match.to_s.upcase}
12
- assert_equal "xxx axa yue asx aya aza", str
13
- end
11
+ should "not modify the string" do
12
+ str = "xxx axa yue asx aya aza"
13
+ str.gsub_each(/a.a/){|match| match.to_s.upcase}
14
+ assert_equal "xxx axa yue asx aya aza", str
15
+ end
14
16
 
15
- should "have a mutating version" do
16
- str = "xxx axa yue asx aya aza"
17
- str.gsub_each!(/a.a/){|match| match.to_s.upcase}
18
- assert_equal "xxx AXA yue asx AYA AZA", str
17
+ should "have a mutator version" do
18
+ str = "xxx axa yue asx aya aza"
19
+ str.gsub_each!(/a.a/){|match| match.to_s.upcase}
20
+ assert_equal "xxx AXA yue asx AYA AZA", str
21
+ end
22
+
19
23
  end
20
24
 
21
25
  end
data/test/test_match.rb CHANGED
@@ -1,22 +1,30 @@
1
1
  require 'helper'
2
2
 
3
- class TestGsub < Test::Unit::TestCase
3
+ class TestMatch < Test::Unit::TestCase
4
4
 
5
- should "pass match info to a block and return the block result" do
6
- assert_equal "axa", "xxx axa yue asx aya aza".match_one(/a.a/){|match| match.to_s}
7
- assert_equal "axa", /a.a/.match_one("xxx axa yue asx aya aza"){|match| match.to_s}
8
- end
5
+ context "Applying match_one to a string or regular expression" do
6
+
7
+ should "pass match info to a block and return the block result" do
8
+ assert_equal "axa", "xxx axa yue asx aya aza".match_one(/a.a/){|match| match.to_s}
9
+ assert_equal "axa", /a.a/.match_one("xxx axa yue asx aya aza"){|match| match.to_s}
10
+ end
9
11
 
10
- should "return nil if no match" do
11
- assert_equal "axa", "xxx axa yue asx aya aza".match_one(/a.a/){|match| match.to_s}
12
- assert_equal "axa", /a.a/.match_one("xxx axa yue asx aya aza"){|match| match.to_s}
13
- assert_nil "xxx axa yue asx aya aza".match_one(/b.b/){|match| match.to_s}
14
- assert_nil /b.b/.match_one("xxx axa yue asx aya aza"){|match| match.to_s}
12
+ should "return nil if no match" do
13
+ assert_equal "axa", "xxx axa yue asx aya aza".match_one(/a.a/){|match| match.to_s}
14
+ assert_equal "axa", /a.a/.match_one("xxx axa yue asx aya aza"){|match| match.to_s}
15
+ assert_nil "xxx axa yue asx aya aza".match_one(/b.b/){|match| match.to_s}
16
+ assert_nil /b.b/.match_one("xxx axa yue asx aya aza"){|match| match.to_s}
17
+ end
18
+
15
19
  end
16
20
 
17
- should "map all matches to an array" do
18
- assert_equal ["axa", "aya", "aza"], "xxx axa yue asx aya aza".match_all(/a.a/){|match| match.to_s}
19
- assert_equal ["axa", "aya", "aza"], /a.a/.match_all("xxx axa yue asx aya aza"){|match| match.to_s}
21
+ context "Applying match_all to a string or regular expression" do
22
+
23
+ should "map all matches to an array" do
24
+ assert_equal ["axa", "aya", "aza"], "xxx axa yue asx aya aza".match_all(/a.a/){|match| match.to_s}
25
+ assert_equal ["axa", "aya", "aza"], /a.a/.match_all("xxx axa yue asx aya aza"){|match| match.to_s}
26
+ end
27
+
20
28
  end
21
29
 
22
30
  end
@@ -1,77 +1,81 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestRelativePaths < Test::Unit::TestCase
4
+
5
+ context "File.relative_path" do
4
6
 
5
- should "handle relative paths" do
6
- assert_equal 'aaa/bbb/ccc/ddd.eee', File.relative_path('aaa/bbb/ccc/ddd.eee')
7
- assert_equal 'ccc/ddd.eee', File.relative_path('aaa/bbb/ccc/ddd.eee', 'aaa/bbb')
8
- assert_equal 'aaa/bbb/ccc/ddd.eee', File.relative_path('aaa/bbb/ccc/ddd.eee','/aaa/bbb')
9
- assert_equal 'aaa/bbb/ccc/ddd.eee', File.relative_path('aaa/bbb/ccc/ddd.eee','xxx/yyy')
10
- assert_equal 'aaa/bbb/ccc/ddd.eee', File.relative_path('aaa/bbb/ccc/ddd.eee','/xxx/yyy')
11
- end
7
+ should "handle relative paths" do
8
+ assert_equal 'aaa/bbb/ccc/ddd.eee', File.relative_path('aaa/bbb/ccc/ddd.eee')
9
+ assert_equal 'ccc/ddd.eee', File.relative_path('aaa/bbb/ccc/ddd.eee', 'aaa/bbb')
10
+ assert_equal 'aaa/bbb/ccc/ddd.eee', File.relative_path('aaa/bbb/ccc/ddd.eee','/aaa/bbb')
11
+ assert_equal 'aaa/bbb/ccc/ddd.eee', File.relative_path('aaa/bbb/ccc/ddd.eee','xxx/yyy')
12
+ assert_equal 'aaa/bbb/ccc/ddd.eee', File.relative_path('aaa/bbb/ccc/ddd.eee','/xxx/yyy')
13
+ end
12
14
 
13
- should "handle absolute root paths" do
14
- assert_equal '/aaa/bbb/ccc/ddd.eee', File.relative_path('/aaa/bbb/ccc/ddd.eee')
15
- assert_equal 'ccc/ddd.eee', File.relative_path('/aaa/bbb/ccc/ddd.eee', '/aaa/bbb')
16
- assert_equal '/aaa/bbb/ccc/ddd.eee', File.relative_path('/aaa/bbb/ccc/ddd.eee','aaa/bbb')
17
- assert_equal '/aaa/bbb/ccc/ddd.eee', File.relative_path('/aaa/bbb/ccc/ddd.eee','xxx/yyy')
18
- assert_equal '/aaa/bbb/ccc/ddd.eee', File.relative_path('/aaa/bbb/ccc/ddd.eee','/xxx/yyy')
19
- end
15
+ should "handle absolute root paths" do
16
+ assert_equal '/aaa/bbb/ccc/ddd.eee', File.relative_path('/aaa/bbb/ccc/ddd.eee')
17
+ assert_equal 'ccc/ddd.eee', File.relative_path('/aaa/bbb/ccc/ddd.eee', '/aaa/bbb')
18
+ assert_equal '/aaa/bbb/ccc/ddd.eee', File.relative_path('/aaa/bbb/ccc/ddd.eee','aaa/bbb')
19
+ assert_equal '/aaa/bbb/ccc/ddd.eee', File.relative_path('/aaa/bbb/ccc/ddd.eee','xxx/yyy')
20
+ assert_equal '/aaa/bbb/ccc/ddd.eee', File.relative_path('/aaa/bbb/ccc/ddd.eee','/xxx/yyy')
21
+ end
20
22
 
21
- should "handle absolute home paths" do
22
- assert_equal '~/aaa/bbb/ccc/ddd.eee', File.relative_path('~/aaa/bbb/ccc/ddd.eee')
23
- assert_equal 'ccc/ddd.eee', File.relative_path('~/aaa/bbb/ccc/ddd.eee', '~/aaa/bbb')
24
- assert_equal '~/aaa/bbb/ccc/ddd.eee', File.relative_path('~/aaa/bbb/ccc/ddd.eee','aaa/bbb')
25
- assert_equal '~/aaa/bbb/ccc/ddd.eee', File.relative_path('~/aaa/bbb/ccc/ddd.eee','/aaa/bbb')
26
- assert_equal '~/aaa/bbb/ccc/ddd.eee', File.relative_path('~/aaa/bbb/ccc/ddd.eee','xxx/yyy')
27
- assert_equal '~/aaa/bbb/ccc/ddd.eee', File.relative_path('~/aaa/bbb/ccc/ddd.eee','/xxx/yyy')
28
- end
23
+ should "handle absolute home paths" do
24
+ assert_equal '~/aaa/bbb/ccc/ddd.eee', File.relative_path('~/aaa/bbb/ccc/ddd.eee')
25
+ assert_equal 'ccc/ddd.eee', File.relative_path('~/aaa/bbb/ccc/ddd.eee', '~/aaa/bbb')
26
+ assert_equal '~/aaa/bbb/ccc/ddd.eee', File.relative_path('~/aaa/bbb/ccc/ddd.eee','aaa/bbb')
27
+ assert_equal '~/aaa/bbb/ccc/ddd.eee', File.relative_path('~/aaa/bbb/ccc/ddd.eee','/aaa/bbb')
28
+ assert_equal '~/aaa/bbb/ccc/ddd.eee', File.relative_path('~/aaa/bbb/ccc/ddd.eee','xxx/yyy')
29
+ assert_equal '~/aaa/bbb/ccc/ddd.eee', File.relative_path('~/aaa/bbb/ccc/ddd.eee','/xxx/yyy')
30
+ end
29
31
 
30
- should "absolute paths with Windows units" do
31
- assert_equal 'C:/aaa/bbb/ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee')
32
- assert_equal 'ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee', 'C:/aaa/bbb')
33
- assert_equal 'C:/aaa/bbb/ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee','aaa/bbb')
34
- assert_equal 'C:/aaa/bbb/ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee','/aaa/bbb')
35
- assert_equal 'C:/aaa/bbb/ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee','D:/aaa/bbb')
36
- assert_equal 'C:/aaa/bbb/ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee','xxx/yyy')
37
- assert_equal 'C:/aaa/bbb/ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee','/xxx/yyy')
38
- assert_equal 'C:/aaa/bbb/ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee','C:/xxx/yyy')
39
- end
32
+ should "absolute paths with Windows units" do
33
+ assert_equal 'C:/aaa/bbb/ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee')
34
+ assert_equal 'ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee', 'C:/aaa/bbb')
35
+ assert_equal 'C:/aaa/bbb/ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee','aaa/bbb')
36
+ assert_equal 'C:/aaa/bbb/ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee','/aaa/bbb')
37
+ assert_equal 'C:/aaa/bbb/ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee','D:/aaa/bbb')
38
+ assert_equal 'C:/aaa/bbb/ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee','xxx/yyy')
39
+ assert_equal 'C:/aaa/bbb/ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee','/xxx/yyy')
40
+ assert_equal 'C:/aaa/bbb/ccc/ddd.eee', File.relative_path('C:/aaa/bbb/ccc/ddd.eee','C:/xxx/yyy')
41
+ end
40
42
 
41
- if File::ALT_SEPARATOR == "\\"
42
- should "handle absolute paths with Windows units and Windows separators" do
43
- assert_equal 'C:\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee')
44
- assert_equal 'ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee', 'C:\\aaa\\bbb')
45
- assert_equal 'C:\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee','aaa\\bbb')
46
- assert_equal 'C:\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee','\\aaa\\bbb')
47
- assert_equal 'C:\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee','D:\\aaa\\bbb')
48
- assert_equal 'C:\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee','xxx\\yyy')
49
- assert_equal 'C:\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee','\\xxx\\yyy')
50
- assert_equal 'C:\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee','C:\\xxx\\yyy')
51
- end
52
- end
43
+ if File::ALT_SEPARATOR == "\\"
44
+ should "handle absolute paths with Windows units and Windows separators" do
45
+ assert_equal 'C:\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee')
46
+ assert_equal 'ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee', 'C:\\aaa\\bbb')
47
+ assert_equal 'C:\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee','aaa\\bbb')
48
+ assert_equal 'C:\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee','\\aaa\\bbb')
49
+ assert_equal 'C:\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee','D:\\aaa\\bbb')
50
+ assert_equal 'C:\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee','xxx\\yyy')
51
+ assert_equal 'C:\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee','\\xxx\\yyy')
52
+ assert_equal 'C:\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('C:\\aaa\\bbb\\ccc\\ddd.eee','C:\\xxx\\yyy')
53
+ end
54
+ end
53
55
 
54
- should "handle absolute UNC paths" do
55
- assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee')
56
- assert_equal 'ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee', '//aaa/bbb')
57
- assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','aaa/bbb')
58
- assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','/aaa/bbb')
59
- assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','xxx/yyy')
60
- assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','/xxx/yyy')
61
- assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','//xxx/yyy')
62
- end
56
+ should "handle absolute UNC paths" do
57
+ assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee')
58
+ assert_equal 'ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee', '//aaa/bbb')
59
+ assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','aaa/bbb')
60
+ assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','/aaa/bbb')
61
+ assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','xxx/yyy')
62
+ assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','/xxx/yyy')
63
+ assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','//xxx/yyy')
64
+ end
63
65
 
64
- if File::ALT_SEPARATOR == "\\"
65
- # This test fails on non-windows platforms because File.expand_path("\\\\...","base") == "base/\\\\..."
66
- should "handle absolute UNC paths with Windows separators" do
67
- assert_equal '\\\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('\\\\aaa\\bbb\\ccc\\ddd.eee')
68
- assert_equal 'ccc\\ddd.eee', File.relative_path('\\\\aaa\\bbb\\ccc\\ddd.eee', '\\\\aaa\\bbb')
69
- assert_equal '\\\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('\\\\aaa\\bbb\\ccc\\ddd.eee','aaa\\bbb')
70
- assert_equal '\\\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('\\\\aaa\\bbb\\ccc\\ddd.eee','\\aaa\\bbb')
71
- assert_equal '\\\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('\\\\aaa\\bbb\\ccc\\ddd.eee','xxx\\yyy')
72
- assert_equal '\\\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('\\\\aaa\\bbb\\ccc\\ddd.eee','\\xxx\\yyy')
73
- assert_equal '\\\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('\\\\aaa\\bbb\\ccc\\ddd.eee','\\\\xxx\\yyy')
66
+ if File::ALT_SEPARATOR == "\\"
67
+ # This test fails on non-windows platforms because File.expand_path("\\\\...","base") == "base/\\\\..."
68
+ should "handle absolute UNC paths with Windows separators" do
69
+ assert_equal '\\\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('\\\\aaa\\bbb\\ccc\\ddd.eee')
70
+ assert_equal 'ccc\\ddd.eee', File.relative_path('\\\\aaa\\bbb\\ccc\\ddd.eee', '\\\\aaa\\bbb')
71
+ assert_equal '\\\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('\\\\aaa\\bbb\\ccc\\ddd.eee','aaa\\bbb')
72
+ assert_equal '\\\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('\\\\aaa\\bbb\\ccc\\ddd.eee','\\aaa\\bbb')
73
+ assert_equal '\\\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('\\\\aaa\\bbb\\ccc\\ddd.eee','xxx\\yyy')
74
+ assert_equal '\\\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('\\\\aaa\\bbb\\ccc\\ddd.eee','\\xxx\\yyy')
75
+ assert_equal '\\\\aaa\\bbb\\ccc\\ddd.eee', File.relative_path('\\\\aaa\\bbb\\ccc\\ddd.eee','\\\\xxx\\yyy')
76
+ end
74
77
  end
78
+
75
79
  end
76
80
 
77
81
  end
@@ -0,0 +1,42 @@
1
+ require 'helper'
2
+
3
+ class TestSlice < Test::Unit::TestCase
4
+
5
+ context "Enumerable objects" do
6
+
7
+ should "have each_slice" do
8
+ assert [].respond_to?(:each_slice)
9
+ assert({}.respond_to?(:each_slice))
10
+ end
11
+
12
+ should "iterate into disjoint groups with each_slice" do
13
+ a = (1..8).to_a
14
+
15
+ slices = []
16
+ a.each_slice(2){|s| slices << s}
17
+ assert_equal [[1,2],[3,4],[5,6],[7,8]], slices
18
+
19
+ slices = []
20
+ a.each_slice(3){|s| slices << s}
21
+ assert_equal [[1,2,3],[4,5,6],[7,8]], slices
22
+ end
23
+
24
+ should "convert each_slice to an array" do
25
+ assert_equal [[1,2],[3,4],[5,6],[7,8]], [1,2,3,4,5,6,7,8].each_slice(2).to_a
26
+ assert_equal [[1,2,3],[4,5,6],[7,8]], [1,2,3,4,5,6,7,8].each_slice(3).to_a
27
+ end
28
+
29
+ should "have each_pair" do
30
+ assert_equal [[1,2],[3,4],[5,6],[7,8]], [1,2,3,4,5,6,7,8].each_pair.to_a
31
+ end
32
+
33
+ should "have to_pairs" do
34
+ assert [].respond_to?(:to_pairs)
35
+ assert({}.respond_to?(:to_pairs))
36
+ assert_equal [[1,2],[3,4],[5,6],[7,8]], [1,2,3,4,5,6,7,8].to_pairs
37
+ assert_equal [[1,2],[3,4],[5,6],[7]], [1,2,3,4,5,6,7].to_pairs
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -22,6 +22,7 @@ class TestUnindent < Test::Unit::TestCase
22
22
  Fourh line}
23
23
  assert_equal txt, txt.unindent
24
24
  end
25
+
25
26
  should "remove empty lines at the beginning and end" do
26
27
  assert_equal @unindented_text, %{
27
28
  First line
@@ -30,6 +31,7 @@ class TestUnindent < Test::Unit::TestCase
30
31
  Fourth line
31
32
  }.unindent
32
33
  end
34
+
33
35
  should "replace indentation by a given number of spaces" do
34
36
  assert_equal @indented_text, %{
35
37
  First line
@@ -38,6 +40,7 @@ class TestUnindent < Test::Unit::TestCase
38
40
  Fourth line
39
41
  }.unindent(4)
40
42
  end
43
+
41
44
  should "replace indentation by a string" do
42
45
  assert_equal @indented_text, %{
43
46
  First line
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modalsupport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Goizueta
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-24 00:00:00 +01:00
12
+ date: 2010-02-05 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -69,6 +69,7 @@ files:
69
69
  - test/test_gsub.rb
70
70
  - test/test_match.rb
71
71
  - test/test_relative_path.rb
72
+ - test/test_slice.rb
72
73
  - test/test_unindent.rb
73
74
  has_rdoc: true
74
75
  homepage: http://github.com/jgoizueta/modalsupport
@@ -104,4 +105,5 @@ test_files:
104
105
  - test/test_gsub.rb
105
106
  - test/test_match.rb
106
107
  - test/test_relative_path.rb
108
+ - test/test_slice.rb
107
109
  - test/test_unindent.rb