13
13
def test_s_returns_file_separator
14
14
sep = File::ALT_SEPARATOR || File::SEPARATOR
15
15
assert_equal sep, "abc.rb".pathmap("%s")
16
assert_equal sep, "".pathmap("%s")
16
17
assert_equal "a#{sep}b", "a/b".pathmap("%d%s%f")
19
def test_b_returns_basename
20
def test_f_returns_basename
20
21
assert_equal "abc.rb", "abc.rb".pathmap("%f")
21
22
assert_equal "abc.rb", "this/is/a/dir/abc.rb".pathmap("%f")
22
23
assert_equal "abc.rb", "/this/is/a/dir/abc.rb".pathmap("%f")
25
def test_B_returns_basename_without_extension
26
def test_n_returns_basename_without_extension
26
27
assert_equal "abc", "abc.rb".pathmap("%n")
27
28
assert_equal "abc", "abc".pathmap("%n")
28
29
assert_equal "abc", "this/is/a/dir/abc.rb".pathmap("%n")
37
38
assert_equal "/this/is/a/dir", "/this/is/a/dir/abc.rb".pathmap("%d")
40
def test_nnnd_returns_partial_dirname
41
def test_9d_returns_partial_dirname
41
42
assert_equal "this/is", "this/is/a/dir/abc.rb".pathmap("%2d")
42
43
assert_equal "this", "this/is/a/dir/abc.rb".pathmap("%1d")
43
44
assert_equal ".", "this/is/a/dir/abc.rb".pathmap("%0d")
47
48
assert_equal "this/is/a/dir", "this/is/a/dir/abc.rb".pathmap("%-100d")
51
def test_x_returns_extension
52
assert_equal "", "abc".pathmap("%x")
53
assert_equal ".rb", "abc.rb".pathmap("%x")
54
assert_equal ".rb", "abc.xyz.rb".pathmap("%x")
55
assert_equal "", ".depends".pathmap("%x")
56
assert_equal "", "dir/.depends".pathmap("%x")
59
def test_X_returns_everything_but_extension
60
assert_equal "abc", "abc".pathmap("%X")
61
assert_equal "abc", "abc.rb".pathmap("%X")
62
assert_equal "abc.xyz", "abc.xyz.rb".pathmap("%X")
63
assert_equal ".depends", ".depends".pathmap("%X")
64
assert_equal "a/dir/.depends", "a/dir/.depends".pathmap("%X")
65
assert_equal "/.depends", "/.depends".pathmap("%X")
68
def test_p_returns_entire_pathname
69
assert_equal "abc.rb", "abc.rb".pathmap("%p")
70
assert_equal "this/is/a/dir/abc.rb", "this/is/a/dir/abc.rb".pathmap("%p")
71
assert_equal "/this/is/a/dir/abc.rb", "/this/is/a/dir/abc.rb".pathmap("%p")
74
def test_dash_returns_empty_string
75
assert_equal "", "abc.rb".pathmap("%-")
76
assert_equal "abc.rb", "abc.rb".pathmap("%X%-%x")
79
def test_percent_percent_returns_percent
80
assert_equal "a%b", "".pathmap("a%%b")
83
def test_undefined_percent_causes_error
84
ex = assert_raise(ArgumentError) {
85
"dir/abc.rb".pathmap("%z")
50
89
def test_pattern_returns_substitutions
51
90
assert_equal "bin/org/osb",
52
91
"src/org/osb/Xyz.java".pathmap("%{src,bin}d")
92
131
assert_match(/unknown.*pathmap.*spec.*z/i, ex.message)
95
def test_x_returns_extension
96
assert_equal "", "abc".pathmap("%x")
97
assert_equal ".rb", "abc.rb".pathmap("%x")
98
assert_equal ".rb", "abc.xyz.rb".pathmap("%x")
99
assert_equal "", ".depends".pathmap("%x")
100
assert_equal "", "dir/.depends".pathmap("%x")
103
def test_X_returns_everything_but_extension
104
assert_equal "abc", "abc".pathmap("%X")
105
assert_equal "abc", "abc.rb".pathmap("%X")
106
assert_equal "abc.xyz", "abc.xyz.rb".pathmap("%X")
107
assert_equal ".depends", ".depends".pathmap("%X")
108
assert_equal "a/dir/.depends", "a/dir/.depends".pathmap("%X")
109
assert_equal "/.depends", "/.depends".pathmap("%X")
112
def test_p_returns_entire_pathname
113
assert_equal "abc.rb", "abc.rb".pathmap("%p")
114
assert_equal "this/is/a/dir/abc.rb", "this/is/a/dir/abc.rb".pathmap("%p")
115
assert_equal "/this/is/a/dir/abc.rb", "/this/is/a/dir/abc.rb".pathmap("%p")
118
def test_percent_percent_returns_percent
119
assert_equal "a%b", "".pathmap("a%%b")
122
def test_undefined_percent_causes_error
123
ex = assert_raise(ArgumentError) {
124
"dir/abc.rb".pathmap("%z")
128
134
def test_works_with_windows_separators
129
135
if File::ALT_SEPARATOR
130
136
assert_equal "abc", 'dir\abc.rb'.pathmap("%n")