modalsupport 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/lib/modalsupport/enumerable.rb +7 -0
- data/lib/modalsupport/file.rb +19 -0
- data/lib/modalsupport/regexp.rb +34 -0
- data/lib/modalsupport/string.rb +70 -0
- data/lib/modalsupport.rb +6 -0
- data/modalsupport.gemspec +72 -0
- data/test/helper.rb +10 -0
- data/test/test_grep.rb +15 -0
- data/test/test_gsub.rb +21 -0
- data/test/test_match.rb +15 -0
- data/test/test_relative_path.rb +77 -0
- data/test/test_unindent.rb +49 -0
- metadata +107 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Javier Goizueta
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= modalsupport
|
2
|
+
|
3
|
+
Some simple Ruby core extensions. This gem requires ActiveSupport and HoboSupport and adds a few additional
|
4
|
+
extensions.
|
5
|
+
|
6
|
+
== Note on Patches/Pull Requests
|
7
|
+
|
8
|
+
* Fork the project.
|
9
|
+
* Make your feature addition or bug fix.
|
10
|
+
* Add tests for it. This is important so I don't break it in a
|
11
|
+
future version unintentionally.
|
12
|
+
* Commit, do not mess with rakefile, version, or history.
|
13
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2010 Javier Goizueta. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "modalsupport"
|
8
|
+
gem.summary = %Q{simple extensions to core classes}
|
9
|
+
gem.description = %Q{additional support extensions to ActiveSupport and HoboSupport}
|
10
|
+
gem.email = "jgoizueta@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/jgoizueta/modalsupport"
|
12
|
+
gem.authors = ["Javier Goizueta"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
gem.add_dependency "hobosupport"
|
15
|
+
gem.add_dependency "activesupport"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "modalsupport #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,19 @@
|
|
1
|
+
def File.relative_path(path, base=nil)
|
2
|
+
base ||= '.'
|
3
|
+
casefold = File::ALT_SEPARATOR=='\\'
|
4
|
+
base = File.expand_path(base)
|
5
|
+
base = base.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
6
|
+
base.downcase! if casefold
|
7
|
+
base += File::SEPARATOR unless base[-1,1]==File::SEPARATOR
|
8
|
+
xpath = File.expand_path(path)
|
9
|
+
xpath = xpath.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
10
|
+
if xpath.size >= base.size
|
11
|
+
pre = xpath[0...base.size]
|
12
|
+
pre.downcase! if casefold
|
13
|
+
if pre == base
|
14
|
+
path = xpath[base.size..-1] # skip separator
|
15
|
+
# path = '.' if path==''
|
16
|
+
end
|
17
|
+
end
|
18
|
+
path
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Regexp
|
2
|
+
|
3
|
+
if RUBY_VERSION < "1.9"
|
4
|
+
alias match_old match
|
5
|
+
# Modify String#match to work as in Ruby 1.9
|
6
|
+
def match(str, i=0)
|
7
|
+
str = str[i..-1] if i>0
|
8
|
+
m = self.match_old(str)
|
9
|
+
if block_given?
|
10
|
+
yield m
|
11
|
+
else
|
12
|
+
m
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Pass each match to a block: string.match_all{|match_data| ...}
|
18
|
+
def match_all(str)
|
19
|
+
result = []
|
20
|
+
i = 0
|
21
|
+
while r=str.index(self, i)
|
22
|
+
match = Regexp.last_match
|
23
|
+
i = r + match.to_s.length
|
24
|
+
result << yield(match)
|
25
|
+
end
|
26
|
+
result
|
27
|
+
end
|
28
|
+
|
29
|
+
# Pass the first match to a block: string.match_one{|match_data| ...}
|
30
|
+
def match_one(str, i=0, &blk)
|
31
|
+
match str, i, &blk
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
if RUBY_VERSION < "1.9"
|
4
|
+
alias match_old match
|
5
|
+
# Modify String#match to work as in Ruby 1.9
|
6
|
+
def match(re, i=0)
|
7
|
+
str = i>0 ? self[i..-1] : self
|
8
|
+
m = str.match_old(re)
|
9
|
+
if block_given?
|
10
|
+
yield m
|
11
|
+
else
|
12
|
+
m
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Pass each match to a block: string.match_all{|match_data| ...}; returns array of block results
|
18
|
+
def match_all(re, i=0)
|
19
|
+
result = []
|
20
|
+
while r=self.index(re, i)
|
21
|
+
match = Regexp.last_match
|
22
|
+
i = r + match.to_s.length
|
23
|
+
result << yield(match)
|
24
|
+
end
|
25
|
+
result
|
26
|
+
end
|
27
|
+
|
28
|
+
# Pass the first match to a block: string.match_one{|match_data| ...}; returns the block result
|
29
|
+
def match_one(re, i=0, &blk)
|
30
|
+
match re, i, &blk
|
31
|
+
end
|
32
|
+
|
33
|
+
# For each substitution, pass the match data to a block that should return substitution value
|
34
|
+
def gsub_each(pattern)
|
35
|
+
gsub(pattern){|str| yield(Regexp.last_match)}
|
36
|
+
end
|
37
|
+
|
38
|
+
# Mutable version of gsub_each
|
39
|
+
def gsub_each!(pattern)
|
40
|
+
gsub!(pattern){|str| yield(Regexp.last_match)}
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
class String
|
48
|
+
|
49
|
+
# Remove indentation of a string (or replace by the indentation defined by the parameters)
|
50
|
+
def unindent(indent=nil)
|
51
|
+
txt = self.gsub(/\t/, ' '*8)
|
52
|
+
mx = txt.scan(/^ *[^\n\r]/).flatten.map{|s| s[-1,1]==' ' ? nil : (s.size-1)}.compact.min
|
53
|
+
if mx && mx>0
|
54
|
+
re = Regexp.new('^ {1,'+mx.to_s+"}")
|
55
|
+
txt.gsub!(/^ {1,#{mx}}/, "")
|
56
|
+
end
|
57
|
+
lines = txt.split(/\r?\n/)
|
58
|
+
if lines.first.strip.empty? || lines.last.strip.empty?
|
59
|
+
lines.shift while lines.first.strip.empty?
|
60
|
+
lines.pop while lines.last.strip.empty?
|
61
|
+
end
|
62
|
+
if indent
|
63
|
+
indent = " "*indent if indent.kind_of?(Numeric)
|
64
|
+
lines = lines.map{|line| "#{indent}#{line}"}
|
65
|
+
end
|
66
|
+
lines.join("\n")
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
data/lib/modalsupport.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{modalsupport}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Javier Goizueta"]
|
12
|
+
s.date = %q{2010-01-24}
|
13
|
+
s.description = %q{additional support extensions to ActiveSupport and HoboSupport}
|
14
|
+
s.email = %q{jgoizueta@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/modalsupport.rb",
|
27
|
+
"lib/modalsupport/enumerable.rb",
|
28
|
+
"lib/modalsupport/file.rb",
|
29
|
+
"lib/modalsupport/regexp.rb",
|
30
|
+
"lib/modalsupport/string.rb",
|
31
|
+
"modalsupport.gemspec",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_grep.rb",
|
34
|
+
"test/test_gsub.rb",
|
35
|
+
"test/test_match.rb",
|
36
|
+
"test/test_relative_path.rb",
|
37
|
+
"test/test_unindent.rb"
|
38
|
+
]
|
39
|
+
s.homepage = %q{http://github.com/jgoizueta/modalsupport}
|
40
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.3.5}
|
43
|
+
s.summary = %q{simple extensions to core classes}
|
44
|
+
s.test_files = [
|
45
|
+
"test/helper.rb",
|
46
|
+
"test/test_grep.rb",
|
47
|
+
"test/test_gsub.rb",
|
48
|
+
"test/test_match.rb",
|
49
|
+
"test/test_relative_path.rb",
|
50
|
+
"test/test_unindent.rb"
|
51
|
+
]
|
52
|
+
|
53
|
+
if s.respond_to? :specification_version then
|
54
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
55
|
+
s.specification_version = 3
|
56
|
+
|
57
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
58
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
59
|
+
s.add_runtime_dependency(%q<hobosupport>, [">= 0"])
|
60
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
63
|
+
s.add_dependency(%q<hobosupport>, [">= 0"])
|
64
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
65
|
+
end
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
68
|
+
s.add_dependency(%q<hobosupport>, [">= 0"])
|
69
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
data/test/helper.rb
ADDED
data/test/test_grep.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestGrep < Test::Unit::TestCase
|
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
|
8
|
+
|
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
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/test/test_gsub.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestMatch < Test::Unit::TestCase
|
4
|
+
|
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
|
8
|
+
|
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
|
14
|
+
|
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
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/test/test_match.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestGsub < Test::Unit::TestCase
|
4
|
+
|
5
|
+
should "pass match info to a block" 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
|
9
|
+
|
10
|
+
should "map all matches to an array" do
|
11
|
+
assert_equal ["axa", "aya", "aza"], "xxx axa yue asx aya aza".match_all(/a.a/){|match| match.to_s}
|
12
|
+
assert_equal ["axa", "aya", "aza"], /a.a/.match_all("xxx axa yue asx aya aza"){|match| match.to_s}
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestRelativePaths < Test::Unit::TestCase
|
4
|
+
|
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
|
12
|
+
|
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
|
20
|
+
|
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
|
29
|
+
|
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
|
40
|
+
|
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
|
53
|
+
|
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
|
63
|
+
|
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')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestUnindent < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@unindented_text = "First line\nSecond line\n Third line\nFourth line"
|
7
|
+
@indented_text = " First line\n Second line\n Third line\n Fourth line"
|
8
|
+
end
|
9
|
+
|
10
|
+
should "remove indentation from indented text" do
|
11
|
+
assert_equal @unindented_text, @indented_text.unindent
|
12
|
+
end
|
13
|
+
|
14
|
+
should "preserve unindented text" do
|
15
|
+
assert_equal @unindented_text, @unindented_text.unindent
|
16
|
+
end
|
17
|
+
|
18
|
+
should "not remove indentation if first line is not indented" do
|
19
|
+
txt = %{First line
|
20
|
+
Second line
|
21
|
+
Third line
|
22
|
+
Fourh line}
|
23
|
+
assert_equal txt, txt.unindent
|
24
|
+
end
|
25
|
+
should "remove empty lines at the beginning and end" do
|
26
|
+
assert_equal @unindented_text, %{
|
27
|
+
First line
|
28
|
+
Second line
|
29
|
+
Third line
|
30
|
+
Fourth line
|
31
|
+
}.unindent
|
32
|
+
end
|
33
|
+
should "replace indentation by a given number of spaces" do
|
34
|
+
assert_equal @indented_text, %{
|
35
|
+
First line
|
36
|
+
Second line
|
37
|
+
Third line
|
38
|
+
Fourth line
|
39
|
+
}.unindent(4)
|
40
|
+
end
|
41
|
+
should "replace indentation by a string" do
|
42
|
+
assert_equal @indented_text, %{
|
43
|
+
First line
|
44
|
+
Second line
|
45
|
+
Third line
|
46
|
+
Fourth line
|
47
|
+
}.unindent(" ")
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: modalsupport
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Javier Goizueta
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-24 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hobosupport
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activesupport
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description: additional support extensions to ActiveSupport and HoboSupport
|
46
|
+
email: jgoizueta@gmail.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
53
|
+
- README.rdoc
|
54
|
+
files:
|
55
|
+
- .document
|
56
|
+
- .gitignore
|
57
|
+
- LICENSE
|
58
|
+
- README.rdoc
|
59
|
+
- Rakefile
|
60
|
+
- VERSION
|
61
|
+
- lib/modalsupport.rb
|
62
|
+
- lib/modalsupport/enumerable.rb
|
63
|
+
- lib/modalsupport/file.rb
|
64
|
+
- lib/modalsupport/regexp.rb
|
65
|
+
- lib/modalsupport/string.rb
|
66
|
+
- modalsupport.gemspec
|
67
|
+
- test/helper.rb
|
68
|
+
- test/test_grep.rb
|
69
|
+
- test/test_gsub.rb
|
70
|
+
- test/test_match.rb
|
71
|
+
- test/test_relative_path.rb
|
72
|
+
- test/test_unindent.rb
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://github.com/jgoizueta/modalsupport
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options:
|
79
|
+
- --charset=UTF-8
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: "0"
|
87
|
+
version:
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: "0"
|
93
|
+
version:
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.3.5
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: simple extensions to core classes
|
101
|
+
test_files:
|
102
|
+
- test/helper.rb
|
103
|
+
- test/test_grep.rb
|
104
|
+
- test/test_gsub.rb
|
105
|
+
- test/test_match.rb
|
106
|
+
- test/test_relative_path.rb
|
107
|
+
- test/test_unindent.rb
|