-
Notifications
You must be signed in to change notification settings - Fork 73
/
path-parsing.spec.js
144 lines (127 loc) · 4.75 KB
/
path-parsing.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
'use strict';
/* global helper */
require('./spec-helper');
var Path = require('path');
describe('gulp-rename path parsing', function() {
describe('dirname', function() {
context('when src pattern contains no globs', function() {
it("dirname is '.'", function(done) {
var srcPattern = 'test/fixtures/hello.txt';
var obj = function(path) {
path.dirname.should.equal('.');
};
helper(srcPattern, obj, null, done);
});
});
context('when src pattern contains filename glob', function() {
it("dirname is '.'", function(done) {
var srcPattern = 'test/fixtures/*.min.txt';
var obj = function(path) {
path.dirname.should.equal('.');
};
helper(srcPattern, obj, null, done);
});
});
var dirnameHelper = function(srcPattern) {
it('dirname is path from directory glob to file', function(done) {
var obj = function(path) {
path.dirname.should.match(/^fixtures[0-9]?$/);
};
helper(srcPattern, obj, null, done);
});
};
context('when src pattern matches a directory with *', function() {
dirnameHelper('test/*/*.min.txt');
});
context('when src pattern matches a directory with **', function() {
dirnameHelper('test/**/*.min.txt');
});
context('when src pattern matches a directory with [...]', function() {
dirnameHelper('test/fixt[a-z]res/*.min.txt');
});
context('when src pattern matches a directory with {...,...}', function() {
dirnameHelper('test/f{ri,ixtur}es/*.min.txt');
});
/* SKIP: glob2base does not handle brace expansion as expected. See wearefractal/glob2base#1 */
context.skip(
'when src pattern matches a directory with {#..#}',
function() {
dirnameHelper('test/fixtures{0..9}/*.min.txt');
}
);
context('when src pattern matches a directory with an extglob', function() {
dirnameHelper('test/f+(ri|ixtur)es/*.min.txt');
});
context('when src pattern includes `base` option', function() {
it('dirname is path from given directory to file', function(done) {
var srcPattern = 'test/**/*.min.txt';
var srcOptions = { base: process.cwd() };
var obj = function(path) {
path.dirname.should.equal(Path.join('test', 'fixtures'));
};
helper({ pattern: srcPattern, options: srcOptions }, obj, null, done);
});
});
});
describe('basename', function() {
it('strips extension like Path.basename(path, ext)', function(done) {
var srcPattern = 'test/fixtures/hello.min.txt';
var obj = function(path) {
path.basename.should.equal('hello.min');
path.basename.should.equal(
Path.basename(srcPattern, Path.extname(srcPattern))
);
};
helper(srcPattern, obj, null, done);
});
});
describe('extname', function() {
it("includes '.' like Path.extname", function(done) {
var srcPattern = 'test/fixtures/hello.txt';
var obj = function(path) {
path.extname.should.equal('.txt');
path.extname.should.equal(Path.extname(srcPattern));
};
helper(srcPattern, obj, null, done);
});
it('excludes multiple extensions like Path.extname', function(done) {
var srcPattern = 'test/fixtures/hello.min.txt';
var obj = function(path) {
path.extname.should.equal('.txt');
path.extname.should.equal(Path.extname(srcPattern));
};
helper(srcPattern, obj, null, done);
});
});
describe('multiExt option', function() {
it('includes multiple extensions in extname', function(done) {
var srcPattern = 'test/fixtures/hello.min.txt';
var obj = function(path) {
path.extname.should.equal('.min.txt');
path.basename.should.equal('hello');
};
helper(srcPattern, obj, null, done, { multiExt: true });
});
});
describe('original file context', function() {
it('passed to plugin as second argument', function(done) {
var srcPattern = 'test/fixtures/hello.min.txt';
var obj = function(path, file) {
file.should.be.instanceof(Object);
file.should.be.ok();
};
helper(srcPattern, obj, null, done, { multiExt: true });
});
it('has expected properties', function(done) {
var srcPattern = 'test/fixtures/hello.min.txt';
var obj = function(path, file) {
file.path.should.equal(Path.resolve(srcPattern));
file.base.should.equal(Path.dirname(Path.resolve(srcPattern)));
file.basename.should.equal(Path.basename(srcPattern));
file.relative.should.equal(Path.basename(srcPattern));
file.extname.should.equal(Path.extname(srcPattern));
};
helper(srcPattern, obj, null, done, { multiExt: true });
});
});
});