File: //usr/share/nodejs/fast-glob/out/providers/matchers/partial.spec.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const assert = require("assert");
const settings_1 = require("../../settings");
const partial_1 = require("./partial");
function getMatcher(patterns, options = {}) {
return new partial_1.default(patterns, new settings_1.default(), options);
}
function assertMatch(patterns, filepath) {
const matcher = getMatcher(patterns);
assert.ok(matcher.match(filepath), `Path "${filepath}" should match: ${patterns}`);
}
function assertNotMatch(patterns, filepath) {
const matcher = getMatcher(patterns);
assert.ok(!matcher.match(filepath), `Path "${filepath}" should do not match: ${patterns}`);
}
describe('Providers → Matchers → Partial', () => {
describe('.match', () => {
it('should handle patterns with globstar', () => {
assertMatch(['**'], 'a');
assertMatch(['**'], './a');
assertMatch(['**/a'], 'a');
assertMatch(['**/a'], 'b/a');
assertMatch(['a/**'], 'a/b');
assertNotMatch(['a/**'], 'b');
});
it('should do not match the latest segment', () => {
assertMatch(['b/*'], 'b');
assertNotMatch(['*'], 'a');
assertNotMatch(['a/*'], 'a/b');
});
it('should trying to match all patterns', () => {
assertMatch(['a/*', 'b/*'], 'b');
assertMatch(['non-match/b/c', 'a/*/c'], 'a/b');
assertNotMatch(['non-match/d/c', 'a/b/c'], 'a/d');
});
it('should match a static segment', () => {
assertMatch(['a/b'], 'a');
assertNotMatch(['b/b'], 'a');
});
it('should match a dynamic segment', () => {
assertMatch(['*/b'], 'a');
assertMatch(['{a,b}/*'], 'a');
assertNotMatch(['{a,b}/*'], 'c');
});
});
});