pathname-common_prefix 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +92 -0
- data/Rakefile +7 -0
- data/bin/common-prefix +22 -0
- data/lib/pathname/common_prefix.rb +23 -0
- data/pathname-common_prefix.gemspec +21 -0
- data/setup.rb +1585 -0
- data/test/test_common_prefix.rb +81 -0
- metadata +55 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require_relative '../lib/pathname/common_prefix'
|
3
|
+
|
4
|
+
class CommonPrefixTest < Test::Unit::TestCase
|
5
|
+
def test_returns_common_prefix
|
6
|
+
paths = %w[
|
7
|
+
/full/path/to/somewhere
|
8
|
+
/full/path/to/anywhere
|
9
|
+
/full/path/to/nowhere
|
10
|
+
/full/path/to/somewhere/else
|
11
|
+
].map {|path| Pathname(path)}
|
12
|
+
assert_equal Pathname('/full/path/to'), Pathname.common_prefix(*paths)
|
13
|
+
|
14
|
+
paths = %w[
|
15
|
+
/full/path/to/somewhere
|
16
|
+
/full/path
|
17
|
+
/full/path/to/nowhere
|
18
|
+
/full/path/to/somewhere/else
|
19
|
+
].map {|path| Pathname(path)}
|
20
|
+
assert_equal Pathname('/full/path'), Pathname.common_prefix(*paths)
|
21
|
+
|
22
|
+
paths = %w[
|
23
|
+
/full/path/to/somewhere
|
24
|
+
/full/path
|
25
|
+
/full/path/to/nowhere
|
26
|
+
/full
|
27
|
+
].map {|path| Pathname(path)}
|
28
|
+
assert_equal Pathname('/full'), Pathname.common_prefix(*paths)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_returns_common_prefix_with_String
|
32
|
+
paths = %w[
|
33
|
+
/full/path/to/somewhere
|
34
|
+
/full/path/to/anywhere
|
35
|
+
/full/path/to/nowhere
|
36
|
+
/full/path/to/somewhere/else
|
37
|
+
]
|
38
|
+
assert_equal Pathname('/full/path/to'), Pathname.common_prefix(*paths)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_returns_nil_when_no_common_prefix
|
42
|
+
paths = %w[
|
43
|
+
/absolute/path
|
44
|
+
relative/path
|
45
|
+
].map {|path| Pathname(path)}
|
46
|
+
assert_nil Pathname.common_prefix(*paths)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_returns_nil_when_empty_array_passed
|
50
|
+
assert_nil Pathname.common_prefix(*[])
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_returns_nil_when_no_argument_passed
|
54
|
+
assert_nil Pathname.common_prefix
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_accept_array_of_pathnames_and_or_path_strings
|
58
|
+
paths = %[
|
59
|
+
/path/to/file
|
60
|
+
Pathname(/path/to/another/file)
|
61
|
+
]
|
62
|
+
assert_nothing_raised do
|
63
|
+
Pathname.common_prefix paths
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_flatten_argument
|
68
|
+
paths = [
|
69
|
+
'/path/to/file',
|
70
|
+
'/path/to/other/file',
|
71
|
+
['/path/to/another/file', '/path/to/some/file/s']
|
72
|
+
]
|
73
|
+
assert_equal Pathname.common_prefix(*paths), Pathname.common_prefix(paths)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_returns_start_with
|
77
|
+
assert_same true, Pathname('/full/path/to/somewhere').start_with?('/full/path/to')
|
78
|
+
assert_same true, Pathname('/full/path/to/somewhere').start_with?('/')
|
79
|
+
assert_same false, Pathname('/full/path/to/somewhere').start_with?('/path/to')
|
80
|
+
end
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pathname-common_prefix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- KITAITI Makoto
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-30 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: This file provides `Pathname.common_prefix` and `Pathname#common_prefix`
|
15
|
+
which calcurate the common prefix in the passed paths.
|
16
|
+
email:
|
17
|
+
- KitaitiMakoto@gmail.com
|
18
|
+
executables:
|
19
|
+
- common-prefix
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- lib/pathname/common_prefix.rb
|
24
|
+
- test/test_common_prefix.rb
|
25
|
+
- bin/common-prefix
|
26
|
+
- README.markdown
|
27
|
+
- Rakefile
|
28
|
+
- setup.rb
|
29
|
+
- pathname-common_prefix.gemspec
|
30
|
+
homepage: https://github.com/KitaitiMakoto/pathname-common_prefix
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.8.8
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: Calcurate prefix commont to some pathnames
|
54
|
+
test_files:
|
55
|
+
- test/test_common_prefix.rb
|