path-to-regex
Advanced tools
Comparing version 1.3.3 to 1.3.4
70
index.js
@@ -29,3 +29,3 @@ module.exports = Regex; | ||
Regex.prototype.init = function( | ||
Regex.prototype.init = function ( | ||
path = "/", | ||
@@ -35,6 +35,6 @@ options = {} | ||
this.options = { | ||
case: typeof options.case === "boolean"? options.case : true, | ||
separators: typeof options.separators === "string"? options.separators : "/", | ||
fromStart: typeof options.fromStart === "boolean"? options.fromStart : true, | ||
toEnd: typeof options.toEnd === "boolean"? options.toEnd : true | ||
case: typeof options.case === "boolean" ? options.case : true, | ||
separators: typeof options.separators === "string" ? options.separators : "/", | ||
fromStart: typeof options.fromStart === "boolean" ? options.fromStart : true, | ||
toEnd: typeof options.toEnd === "boolean" ? options.toEnd : true | ||
}; | ||
@@ -55,5 +55,5 @@ this.options.separator = "[" + this.escape(this.options.separators) + "]"; | ||
*/ | ||
Regex.prototype.restructureRegExp = function(regexp) { | ||
regexp = defaultParam(regexp, /.*/); | ||
this.keys = []; | ||
Regex.prototype.restructureRegExp = function (regexp) { | ||
regexp = defaultParam(regexp, /.*/); | ||
this.keys = []; | ||
this.path = undefined; | ||
@@ -74,5 +74,5 @@ this.regstr = ("" + regexp); | ||
*/ | ||
Regex.prototype.restructurePath = function(path) { | ||
path = defaultParam(path, '/'); | ||
this.keys = []; | ||
Regex.prototype.restructurePath = function (path) { | ||
path = defaultParam(path, '/'); | ||
this.keys = []; | ||
this.path = path; | ||
@@ -108,4 +108,4 @@ this.regstr = ""; | ||
// const startChar = path.charAt(index-1); | ||
const isStarted = (!index)?true:this.separator(path.charAt(index-1)); | ||
const isStoped = (index+str.length>=path.length)?true:this.separator(path.charAt(index+str.length)); | ||
const isStarted = (!index) ? true : this.separator(path.charAt(index - 1)); | ||
const isStoped = (index + str.length >= path.length) ? true : this.separator(path.charAt(index + str.length)); | ||
const isToken = isStarted && isStoped; | ||
@@ -119,13 +119,13 @@ | ||
if( isToken && index && ( !isMultiple || !isRequired) ) | ||
this.regstr+="?"; | ||
if (isToken && index && (!isMultiple || !isRequired)) | ||
this.regstr += "?"; | ||
const regstr = | ||
isMultiple ? | ||
isToken? | ||
isToken ? | ||
"((?:" + separator + "?" + pattern + ")" + quantifier + ")" : | ||
"((?:" + notseparator + "*" + pattern + ")" + quantifier + ")" : | ||
isToken? | ||
"(" + pattern + "?)" + quantifier: | ||
"(" + pattern + (pat?"":"?")+")" + quantifier; | ||
isToken ? | ||
"(" + pattern + "?)" + quantifier : | ||
"(" + pattern + (pat ? "" : "?") + ")" + quantifier; | ||
@@ -161,4 +161,8 @@ this.regstr += regstr; | ||
this.regstr + | ||
separator + "?" + | ||
(this.options.toEnd ? "$" : ""), | ||
(this.options.toEnd | ||
? | ||
separator + "?" + "$" | ||
: | ||
"(" + separator + "|" + separator + "?" + "$" + ")" | ||
), | ||
this.options.case ? "" : "i" | ||
@@ -175,3 +179,3 @@ ); | ||
*/ | ||
Regex.prototype.escape = function(text) { | ||
Regex.prototype.escape = function (text) { | ||
return text.replace(escapeRe, s => { | ||
@@ -187,3 +191,3 @@ return "\\" + s | ||
*/ | ||
Regex.prototype.separator = function(char) { | ||
Regex.prototype.separator = function (char) { | ||
return !!(this.options.separators.indexOf(char) + 1); | ||
@@ -194,17 +198,17 @@ } | ||
Regex.prototype.match = function(path) { | ||
// console.log("match 01"); | ||
Regex.prototype.match = function (path) { | ||
// console.log("match 01"); | ||
if (typeof path !== "string") return; | ||
// console.log("match 02"); | ||
// console.log("match 02"); | ||
const result = path.match(this.regexp); | ||
// console.log("match 03"); | ||
// console.log("match 03"); | ||
if (!result) return; | ||
// console.log("match 04"); | ||
// console.log("match 04"); | ||
const data = {}; | ||
// console.log("match 05"); | ||
// console.log("match 05"); | ||
this.keys.forEach(item => { | ||
@@ -228,3 +232,3 @@ // console.log("match foreach 01"); | ||
let value = result[item.index]?result[item.index]:undefined; | ||
let value = result[item.index] ? result[item.index] : undefined; | ||
@@ -243,4 +247,4 @@ if (!isMultiple && !item.multiple) { | ||
result[item.index].replace(item.regexp, str => { | ||
if(str) data[item.key].push( | ||
str.replace(new RegExp(this.options.separator+"*$"), "") | ||
if (str) data[item.key].push( | ||
str.replace(new RegExp(this.options.separator + "*$"), "") | ||
); | ||
@@ -250,4 +254,4 @@ }); | ||
}); | ||
// console.log("match 06"); | ||
// console.log("match 06"); | ||
return data; | ||
}; |
{ | ||
"name": "path-to-regex", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"description": "Turn a path string such as /user/:id or /user/:id(\\d+) into a regular expression", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
const PathToRegex = require("../index.js"); | ||
const chai = require('chai'); | ||
const assert = chai.assert; | ||
const expect = chai.expect; | ||
const assert = chai.assert; | ||
const expect = chai.expect; | ||
// const should = chai.should; | ||
describe("Тестируем модуль преобразования пути в RegExp", function() { | ||
describe("Тестируем модуль преобразования пути в RegExp", function () { | ||
describe("01. Тестируем шаблон '/:path'", function() { | ||
describe("01. Тестируем шаблон '/:path'", function () { | ||
const re = new PathToRegex("/:path"); | ||
console.log("01. REGEXP:",re.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function() { | ||
assert.equal( re.match(""), undefined); | ||
const reend = new PathToRegex("/:path", { case: false, toEnd: false }); | ||
console.log("01. REGEXP toEnd[true]:", re.regexp); | ||
console.log("01. REGEXP toEnd[false]:", reend.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function () { | ||
assert.equal(re.match(""), undefined); | ||
assert.equal(reend.match(""), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function() { | ||
assert.equal( re.match("/"), undefined); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/"), undefined); | ||
assert.equal(reend.match("/"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:'user'}`", function() { | ||
expect( re.match("user") ).to.deep.equal({path:'user'}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:'user'}`", function () { | ||
expect(re.match("user")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("user")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:'user'}`", function() { | ||
expect( re.match("/user") ).to.deep.equal({path:'user'}); | ||
}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:'user'}`", function() { | ||
expect( re.match("user/") ).to.deep.equal({path:'user'}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:'user'}`", function () { | ||
expect(re.match("/user")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("/user")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:'user'}`", function() { | ||
expect( re.match("/user/") ).to.deep.equal({path:'user'}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:'user'}`", function () { | ||
expect(re.match("user/")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("user/")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон не совпадает со строкой 'user/12345'. результат: `undefined`", function() { | ||
assert.equal( re.match("user/12345"), undefined); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:'user'}`", function () { | ||
expect(re.match("/user/")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("/user/")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон не совпадает со строкой '/user/12345'. результат: `undefined`", function() { | ||
assert.equal( re.match("/user/12345"), undefined); | ||
it("шаблон не совпадает со строкой 'user/12345'. результат: `undefined`", function () { | ||
assert.equal(re.match("user/12345"), undefined); | ||
expect(reend.match("/user/12345")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон не совпадает со строкой 'user/12345/'. результат: `undefined`", function() { | ||
assert.equal( re.match("user/12345/"), undefined); | ||
it("шаблон не совпадает со строкой '/user/12345'. результат: `undefined`", function () { | ||
assert.equal(re.match("/user/12345"), undefined); | ||
expect(reend.match("/user/12345")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон не совпадает со строкой '/user/12345/'. результат: `undefined`", function() { | ||
assert.equal( re.match("/user/12345/"), undefined); | ||
it("шаблон не совпадает со строкой 'user/12345/'. результат: `undefined`", function () { | ||
assert.equal(re.match("user/12345/"), undefined); | ||
expect(reend.match("/user/12345")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон не совпадает со строкой '/user/12345/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/user/12345/"), undefined); | ||
expect(reend.match("/user/12345")).to.deep.equal({ path: 'user' }); | ||
}); | ||
}); | ||
}); | ||
describe("02. Тестируем шаблон '/:path*'", function() { | ||
describe("02. Тестируем шаблон '/:path*'", function () { | ||
const re = new PathToRegex("/:path*"); | ||
console.log("02. REGEXP:",re.regexp); | ||
it("шаблон совпадает со строкой ''. результат: `{path:[]}`", function() { | ||
expect( re.match("") ).to.deep.equal({path:[]}); | ||
const reend = new PathToRegex("/:path*", { case: false, toEnd: false }); | ||
console.log("02. REGEXP toEnd[true]:", re.regexp); | ||
console.log("02. REGEXP toEnd[false]:", reend.regexp); | ||
it("шаблон совпадает со строкой ''. результат: `{path:[]}`", function () { | ||
expect(re.match("")).to.deep.equal({ path: [] }); | ||
expect(reend.match("")).to.deep.equal({ path: [] }); | ||
}); | ||
it("шаблон совпадает со строкой '/'. результат: `{path:[]}`", function() { | ||
expect( re.match("/") ).to.deep.equal({path:[]}); | ||
it("шаблон совпадает со строкой '/'. результат: `{path:[]}`", function () { | ||
expect(re.match("/")).to.deep.equal({ path: [] }); | ||
expect(reend.match("/")).to.deep.equal({ path: [] }); | ||
}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:['user']}`", function() { | ||
expect( re.match("user") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:['user']}`", function () { | ||
expect(re.match("user")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("user")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:['user']}`", function() { | ||
expect( re.match("/user") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:['user']}`", function () { | ||
expect(re.match("/user")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("/user")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:['user']}`", function() { | ||
expect( re.match("user/") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:['user']}`", function () { | ||
expect(re.match("user/")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("user/")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:['user']}`", function() { | ||
expect( re.match("/user/") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:['user']}`", function () { | ||
expect(re.match("/user/")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("/user/")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/12345'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("user/12345") ).to.deep.equal({path:['user','12345']}); | ||
it("шаблон совпадает со строкой 'user/12345'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/12345'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("/user/12345") ).to.deep.equal({path:['user','12345']}); | ||
it("шаблон совпадает со строкой '/user/12345'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("/user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("/user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/12345/'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("user/12345/") ).to.deep.equal({path:['user','12345']}); | ||
}); | ||
it("шаблон совпадает со строкой '/user/12345/'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("/user/12345/") ).to.deep.equal({path:['user','12345']}); | ||
it("шаблон совпадает со строкой 'user/12345/'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/12345/'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("/user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("/user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
}); | ||
describe("03. Тестируем шаблон '/:path+'", function() { | ||
describe("03. Тестируем шаблон '/:path+'", function () { | ||
const re = new PathToRegex("/:path+"); | ||
console.log("03. REGEXP:",re.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function() { | ||
assert.equal( re.match(""), undefined); | ||
const reend = new PathToRegex("/:path+", { case: false, toEnd: false }); | ||
console.log("03. REGEXP toEnd[true]:", re.regexp); | ||
console.log("03. REGEXP toEnd[false]:", reend.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function () { | ||
assert.equal(re.match(""), undefined); | ||
assert.equal(reend.match(""), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function() { | ||
assert.equal( re.match("/"), undefined); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/"), undefined); | ||
assert.equal(reend.match("/"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:['user']}`", function() { | ||
expect( re.match("user") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:['user']}`", function () { | ||
expect(re.match("user")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("user")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:['user']}`", function() { | ||
expect( re.match("/user") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:['user']}`", function () { | ||
expect(re.match("/user")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("/user")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:['user']}`", function() { | ||
expect( re.match("user/") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:['user']}`", function () { | ||
expect(re.match("user/")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("user/")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:['user'}`", function() { | ||
expect( re.match("/user/") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:['user'}`", function () { | ||
expect(re.match("/user/")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("/user/")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/12345'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("user/12345") ).to.deep.equal({path:['user','12345']}); | ||
it("шаблон совпадает со строкой 'user/12345'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/12345'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("/user/12345") ).to.deep.equal({path:['user','12345']}); | ||
it("шаблон совпадает со строкой '/user/12345'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("/user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("/user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/12345/'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("user/12345/") ).to.deep.equal({path:['user','12345']}); | ||
it("шаблон совпадает со строкой 'user/12345/'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/12345/'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("/user/12345/") ).to.deep.equal({path:['user','12345']}); | ||
it("шаблон совпадает со строкой '/user/12345/'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("/user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("/user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
}); | ||
}); | ||
describe("04. Тестируем шаблон '/:path(.*)'", function() { | ||
describe("04. Тестируем шаблон '/:path(.*)'", function () { | ||
const re = new PathToRegex("/:path(.*)"); | ||
console.log("04. REGEXP:",re.regexp); | ||
it("шаблон совпадает со строкой ''. результат: `{path: undefined}`", function() { | ||
expect( re.match("") ).to.deep.equal({path:undefined}); | ||
const reend = new PathToRegex("/:path(.*)", { case: false, toEnd: false }); | ||
console.log("04. REGEXP toEnd[true]:", re.regexp); | ||
console.log("04. REGEXP toEnd[false]:", reend.regexp); | ||
it("шаблон совпадает со строкой ''. результат: `{path: undefined}`", function () { | ||
expect(re.match("")).to.deep.equal({ path: undefined }); | ||
expect(reend.match("")).to.deep.equal({ path: undefined }); | ||
}); | ||
it("шаблон совпадает со строкой '/'. результат: `{path: undefined}`", function() { | ||
expect( re.match("/") ).to.deep.equal({path:undefined}); | ||
it("шаблон совпадает со строкой '/'. результат: `{path: undefined}`", function () { | ||
expect(re.match("/")).to.deep.equal({ path: undefined }); | ||
expect(reend.match("/")).to.deep.equal({ path: undefined }); | ||
}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:'user'}`", function() { | ||
expect( re.match("user") ).to.deep.equal({path:'user'}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:'user'}`", function () { | ||
expect(re.match("user")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("user")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:'user'}`", function() { | ||
expect( re.match("/user") ).to.deep.equal({path:'user'}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:'user'}`", function () { | ||
expect(re.match("/user")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("/user")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:'user'}`", function() { | ||
expect( re.match("user/") ).to.deep.equal({path:'user'}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:'user'}`", function () { | ||
expect(re.match("user/")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("user/")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:'user'}`", function() { | ||
expect( re.match("/user/") ).to.deep.equal({path:'user'}); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:'user'}`", function () { | ||
expect(re.match("/user/")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("/user/")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/12345'. результат: `{path:'user/12345'}`", function() { | ||
expect( re.match("user/12345") ).to.deep.equal({path:'user/12345'}); | ||
it("шаблон совпадает со строкой 'user/12345'. результат: `{path:'user/12345'}`", function () { | ||
expect(re.match("user/12345")).to.deep.equal({ path: 'user/12345' }); | ||
expect(reend.match("user/12345")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/12345'. результат: `{path:'user/12345'}`", function() { | ||
expect( re.match("/user/12345") ).to.deep.equal({path:'user/12345'}); | ||
it("шаблон совпадает со строкой '/user/12345'. результат: `{path:'user/12345'}`", function () { | ||
expect(re.match("/user/12345")).to.deep.equal({ path: 'user/12345' }); | ||
expect(reend.match("/user/12345")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/12345/'. результат: `{path:'user/12345'}`", function() { | ||
expect( re.match("user/12345/") ).to.deep.equal({path:'user/12345'}); | ||
it("шаблон совпадает со строкой 'user/12345/'. результат: `{path:'user/12345'}`", function () { | ||
expect(re.match("user/12345/")).to.deep.equal({ path: 'user/12345' }); | ||
expect(reend.match("user/12345/")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/12345/'. результат: `{path:'user/12345'}`", function() { | ||
expect( re.match("/user/12345/") ).to.deep.equal({path:'user/12345'}); | ||
it("шаблон совпадает со строкой '/user/12345/'. результат: `{path:'user/12345'}`", function () { | ||
expect(re.match("/user/12345/")).to.deep.equal({ path: 'user/12345' }); | ||
expect(reend.match("/user/12345/")).to.deep.equal({ path: 'user' }); | ||
}); | ||
}); | ||
}); | ||
describe("05. Тестируем шаблон ':path'", function() { | ||
describe("05. Тестируем шаблон ':path'", function () { | ||
const re = new PathToRegex(":path"); | ||
console.log("05. REGEXP:",re.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function() { | ||
assert.equal( re.match(""), undefined); | ||
const reend = new PathToRegex(":path", { case: false, toEnd: false }); | ||
console.log("05. REGEXP toEnd[true]:", re.regexp); | ||
console.log("05. REGEXP toEnd[false]:", reend.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function () { | ||
assert.equal(re.match(""), undefined); | ||
assert.equal(reend.match(""), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function() { | ||
assert.equal( re.match("/"), undefined); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/"), undefined); | ||
assert.equal(reend.match("/"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:'user'}`", function() { | ||
expect( re.match("user") ).to.deep.equal({path:'user'}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:'user'}`", function () { | ||
expect(re.match("user")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("user")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:'user'}`", function() { | ||
expect( re.match("/user") ).to.deep.equal({path:'user'}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:'user'}`", function () { | ||
expect(re.match("/user")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("/user")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:'user'}`", function() { | ||
expect( re.match("user/") ).to.deep.equal({path:'user'}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:'user'}`", function () { | ||
expect(re.match("user/")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("user/")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:'user'}`", function() { | ||
expect( re.match("/user/") ).to.deep.equal({path:'user'}); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:'user'}`", function () { | ||
expect(re.match("/user/")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("/user/")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон не совпадает со строкой 'user/12345'. результат: `undefined`", function() { | ||
assert.equal( re.match("user/12345"), undefined); | ||
it("шаблон не совпадает со строкой 'user/12345'. результат: `undefined`", function () { | ||
assert.equal(re.match("user/12345"), undefined); | ||
expect(reend.match("user/12345")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон не совпадает со строкой '/user/12345'. результат: `undefined`", function() { | ||
assert.equal( re.match("/user/12345"), undefined); | ||
it("шаблон не совпадает со строкой '/user/12345'. результат: `undefined`", function () { | ||
assert.equal(re.match("/user/12345"), undefined); | ||
expect(reend.match("/user/12345")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон не совпадает со строкой 'user/12345/'. результат: `undefined`", function() { | ||
assert.equal( re.match("user/12345/"), undefined); | ||
it("шаблон не совпадает со строкой 'user/12345/'. результат: `undefined`", function () { | ||
assert.equal(re.match("user/12345/"), undefined); | ||
expect(reend.match("user/12345/")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон не совпадает со строкой '/user/12345/'. результат: `undefined`", function() { | ||
assert.equal( re.match("/user/12345/"), undefined); | ||
it("шаблон не совпадает со строкой '/user/12345/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/user/12345/"), undefined); | ||
expect(reend.match("/user/12345/")).to.deep.equal({ path: 'user' }); | ||
}); | ||
}); | ||
}); | ||
describe("06. Тестируем шаблон ':path*'", function() { | ||
describe("06. Тестируем шаблон ':path*'", function () { | ||
const re = new PathToRegex(":path*"); | ||
console.log("06. REGEXP:",re.regexp); | ||
it("шаблон совпадает со строкой ''. результат: `{path:[]}", function() { | ||
expect( re.match("") ).to.deep.equal({path:[]}); | ||
const reend = new PathToRegex(":path*", { case: false, toEnd: false }); | ||
console.log("06. REGEXP toEnd[true]:", re.regexp); | ||
console.log("06. REGEXP toEnd[false]:", reend.regexp); | ||
it("шаблон совпадает со строкой ''. результат: `{path:[]}", function () { | ||
expect(re.match("")).to.deep.equal({ path: [] }); | ||
expect(reend.match("")).to.deep.equal({ path: [] }); | ||
}); | ||
it("шаблон совпадает со строкой '/'. результат: `{path:[]}", function() { | ||
expect( re.match("/") ).to.deep.equal({path:[]}); | ||
it("шаблон совпадает со строкой '/'. результат: `{path:[]}", function () { | ||
expect(re.match("/")).to.deep.equal({ path: [] }); | ||
expect(reend.match("/")).to.deep.equal({ path: [] }); | ||
}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:['user']}`", function() { | ||
expect( re.match("user") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:['user']}`", function () { | ||
expect(re.match("user")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("user")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:['user']}`", function() { | ||
expect( re.match("/user") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:['user']}`", function () { | ||
expect(re.match("/user")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("/user")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:['user']}`", function() { | ||
expect( re.match("user/") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:['user']}`", function () { | ||
expect(re.match("user/")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("user/")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:['user']}`", function() { | ||
expect( re.match("/user/") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:['user']}`", function () { | ||
expect(re.match("/user/")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("/user/")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/12345'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("user/12345") ).to.deep.equal({path:['user','12345']}); | ||
it("шаблон совпадает со строкой 'user/12345'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/12345'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("/user/12345") ).to.deep.equal({path:['user','12345']}); | ||
it("шаблон совпадает со строкой '/user/12345'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("/user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("/user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/12345/'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("user/12345/") ).to.deep.equal({path:['user','12345']}); | ||
it("шаблон совпадает со строкой 'user/12345/'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/12345/'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("/user/12345/") ).to.deep.equal({path:['user','12345']}); | ||
it("шаблон совпадает со строкой '/user/12345/'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("/user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("/user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
}); | ||
describe("07. Тестируем шаблон ':path+'", function() { | ||
describe("07. Тестируем шаблон ':path+'", function () { | ||
const re = new PathToRegex(":path+"); | ||
console.log("07. REGEXP:",re.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function() { | ||
assert.equal( re.match(""), undefined); | ||
const reend = new PathToRegex(":path+", { case: false, toEnd: false }); | ||
console.log("07. REGEXP toEnd[true]:", re.regexp); | ||
console.log("07. REGEXP toEnd[false]:", reend.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function () { | ||
assert.equal(re.match(""), undefined); | ||
assert.equal(reend.match(""), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function() { | ||
assert.equal( re.match("/"), undefined); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/"), undefined); | ||
assert.equal(reend.match("/"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:['user']}`", function() { | ||
expect( re.match("user") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:['user']}`", function () { | ||
expect(re.match("user")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("user")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:['user']}`", function() { | ||
expect( re.match("/user") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:['user']}`", function () { | ||
expect(re.match("/user")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("/user")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:['user']}`", function() { | ||
expect( re.match("user/") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:['user']}`", function () { | ||
expect(re.match("user/")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("user/")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:['user']}`", function() { | ||
expect( re.match("/user/") ).to.deep.equal({path:['user']}); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:['user']}`", function () { | ||
expect(re.match("/user/")).to.deep.equal({ path: ['user'] }); | ||
expect(reend.match("/user/")).to.deep.equal({ path: ['user'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/12345'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("user/12345") ).to.deep.equal({path:['user','12345']}); | ||
it("шаблон совпадает со строкой 'user/12345'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/12345'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("/user/12345") ).to.deep.equal({path:['user','12345']}); | ||
it("шаблон совпадает со строкой '/user/12345'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("/user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("/user/12345")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/12345/'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("user/12345/") ).to.deep.equal({path:['user','12345']}); | ||
it("шаблон совпадает со строкой 'user/12345/'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/12345/'. результат: `{path:['user','12345']}`", function() { | ||
expect( re.match("/user/12345/") ).to.deep.equal({path:['user','12345']}); | ||
it("шаблон совпадает со строкой '/user/12345/'. результат: `{path:['user','12345']}`", function () { | ||
expect(re.match("/user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
expect(reend.match("/user/12345/")).to.deep.equal({ path: ['user', '12345'] }); | ||
}); | ||
}); | ||
describe("08. Тестируем шаблон ':path(.*)'", function() { | ||
describe("08. Тестируем шаблон ':path(.*)'", function () { | ||
const re = new PathToRegex(":path(.*)"); | ||
console.log("08. REGEXP:",re.regexp); | ||
it("шаблон совпадает со строкой '/'. результат: `{path: undefined}`", function() { | ||
expect( re.match("/") ).to.deep.equal({path:undefined}); | ||
const reend = new PathToRegex(":path(.*)", { case: false, toEnd: false }); | ||
console.log("08. REGEXP toEnd[true]:", re.regexp); | ||
console.log("08. REGEXP toEnd[false]:", reend.regexp); | ||
it("шаблон совпадает со строкой '/'. результат: `{path: undefined}`", function () { | ||
expect(re.match("/")).to.deep.equal({ path: undefined }); | ||
expect(reend.match("/")).to.deep.equal({ path: undefined }); | ||
}); | ||
it("шаблон совпадает со строкой ''. результат: `{path:undefined}`", function() { | ||
expect( re.match("") ).to.deep.equal({path:undefined}); | ||
it("шаблон совпадает со строкой ''. результат: `{path:undefined}`", function () { | ||
expect(re.match("")).to.deep.equal({ path: undefined }); | ||
expect(reend.match("")).to.deep.equal({ path: undefined }); | ||
}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:'user'}`", function() { | ||
expect( re.match("user") ).to.deep.equal({path:'user'}); | ||
it("шаблон совпадает со строкой 'user'. результат: `{path:'user'}`", function () { | ||
expect(re.match("user")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("user")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:'user'}`", function() { | ||
expect( re.match("/user") ).to.deep.equal({path:'user'}); | ||
it("шаблон совпадает со строкой '/user'. результат: `{path:'user'}`", function () { | ||
expect(re.match("/user")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("/user")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:'user'}`", function() { | ||
expect( re.match("user/") ).to.deep.equal({path:'user'}); | ||
it("шаблон совпадает со строкой 'user/'. результат: `{path:'user'}`", function () { | ||
expect(re.match("user/")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("user/")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:'user'}`", function() { | ||
expect( re.match("/user/") ).to.deep.equal({path:'user'}); | ||
it("шаблон совпадает со строкой '/user/'. результат: `{path:'user'}`", function () { | ||
expect(re.match("/user/")).to.deep.equal({ path: 'user' }); | ||
expect(reend.match("/user/")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/12345'. результат: `{path:'user/12345'}`", function() { | ||
expect( re.match("user/12345") ).to.deep.equal({path:'user/12345'}); | ||
it("шаблон совпадает со строкой 'user/12345'. результат: `{path:'user/12345'}`", function () { | ||
expect(re.match("user/12345")).to.deep.equal({ path: 'user/12345' }); | ||
expect(reend.match("user/12345")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/12345'. результат: `{path:'user/12345'}`", function() { | ||
expect( re.match("/user/12345") ).to.deep.equal({path:'user/12345'}); | ||
it("шаблон совпадает со строкой '/user/12345'. результат: `{path:'user/12345'}`", function () { | ||
expect(re.match("/user/12345")).to.deep.equal({ path: 'user/12345' }); | ||
expect(reend.match("/user/12345")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой 'user/12345/'. результат: `{path:'user/12345'}`", function() { | ||
expect( re.match("user/12345/") ).to.deep.equal({path:'user/12345'}); | ||
it("шаблон совпадает со строкой 'user/12345/'. результат: `{path:'user/12345'}`", function () { | ||
expect(re.match("user/12345/")).to.deep.equal({ path: 'user/12345' }); | ||
expect(reend.match("user/12345/")).to.deep.equal({ path: 'user' }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/12345/'. результат: `{path:'user/12345'}`", function() { | ||
expect( re.match("/user/12345/") ).to.deep.equal({path:'user/12345'}); | ||
it("шаблон совпадает со строкой '/user/12345/'. результат: `{path:'user/12345'}`", function () { | ||
expect(re.match("/user/12345/")).to.deep.equal({ path: 'user/12345' }); | ||
expect(reend.match("/user/12345/")).to.deep.equal({ path: 'user' }); | ||
}); | ||
@@ -310,271 +403,351 @@ }); | ||
describe("09. Тестируем шаблон '/foo/:bar'", function() { | ||
describe("09. Тестируем шаблон '/foo/:bar'", function () { | ||
const re = new PathToRegex("/foo/:bar"); | ||
console.log("09. REGEXP:",re.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function() { | ||
assert.equal( re.match(""), undefined); | ||
const reend = new PathToRegex("/foo/:bar", { case: false, toEnd: false }); | ||
console.log("09. REGEXP toEnd[true]:", re.regexp); | ||
console.log("09. REGEXP toEnd[false]:", reend.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function () { | ||
assert.equal(re.match(""), undefined); | ||
assert.equal(reend.match(""), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function() { | ||
assert.equal( re.match("/"), undefined); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/"), undefined); | ||
assert.equal(reend.match("/"), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой 'foo'. результат: `undefined`", function() { | ||
assert.equal( re.match("foo"), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/foo'. результат: `undefined`", function() { | ||
assert.equal( re.match("/foo"), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой 'foo/'. результат: `undefined`", function() { | ||
assert.equal( re.match("foo/"), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/foo/'. результат: `undefined`", function() { | ||
assert.equal( re.match("/foo/"), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой 'foo'. результат: `undefined`", function () { | ||
assert.equal(re.match("foo"), undefined); | ||
assert.equal(reend.match("foo"), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/foo'. результат: `undefined`", function () { | ||
assert.equal(re.match("/foo"), undefined); | ||
assert.equal(reend.match("/foo"), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой 'foo/'. результат: `undefined`", function () { | ||
assert.equal(re.match("foo/"), undefined); | ||
assert.equal(reend.match("foo/"), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/foo/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/foo/"), undefined); | ||
assert.equal(reend.match("/foo/"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar'. результат: `{bar:'bar'}`", function() { | ||
expect( re.match("foo/bar") ).to.deep.equal({bar:'bar'}); | ||
it("шаблон совпадает со строкой 'foo/bar'. результат: `{bar:'bar'}`", function () { | ||
expect(re.match("foo/bar")).to.deep.equal({ bar: 'bar' }); | ||
expect(reend.match("foo/bar")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar'. результат: `{bar:'bar'}`", function() { | ||
expect( re.match("/foo/bar") ).to.deep.equal({bar:'bar'}); | ||
it("шаблон совпадает со строкой '/foo/bar'. результат: `{bar:'bar'}`", function () { | ||
expect(re.match("/foo/bar")).to.deep.equal({ bar: 'bar' }); | ||
expect(reend.match("/foo/bar")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar/'. результат: `{bar:'bar'}`", function() { | ||
expect( re.match("foo/bar/") ).to.deep.equal({bar:'bar'}); | ||
it("шаблон совпадает со строкой 'foo/bar/'. результат: `{bar:'bar'}`", function () { | ||
expect(re.match("foo/bar/")).to.deep.equal({ bar: 'bar' }); | ||
expect(reend.match("foo/bar/")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/'. результат: `{bar:'bar'}`", function() { | ||
expect( re.match("/foo/bar/") ).to.deep.equal({bar:'bar'}); | ||
it("шаблон совпадает со строкой '/foo/bar/'. результат: `{bar:'bar'}`", function () { | ||
expect(re.match("/foo/bar/")).to.deep.equal({ bar: 'bar' }); | ||
expect(reend.match("/foo/bar/")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон не совпадает со строкой 'foo/bar/baz'. результат: `undefined`", function() { | ||
assert.equal( re.match("foo/bar/baz"), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/foo/bar/baz'. результат: `undefined`", function() { | ||
assert.equal( re.match("/foo/bar/baz"), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой 'foo/bar/baz/'. результат: `undefined`", function() { | ||
assert.equal( re.match("foo/bar/baz/"), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/foo/bar/baz/'. результат: `undefined`", function() { | ||
assert.equal( re.match("/foo/bar/baz/"), undefined); | ||
it("шаблон не совпадает со строкой 'foo/bar/baz'. результат: `undefined`", function () { | ||
assert.equal(re.match("foo/bar/baz"), undefined); | ||
expect(reend.match("foo/bar/baz")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон не совпадает со строкой '/foo/bar/baz'. результат: `undefined`", function () { | ||
assert.equal(re.match("/foo/bar/baz"), undefined); | ||
expect(reend.match("/foo/bar/baz")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон не совпадает со строкой 'foo/bar/baz/'. результат: `undefined`", function () { | ||
assert.equal(re.match("foo/bar/baz/"), undefined); | ||
expect(reend.match("foo/bar/baz/")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон не совпадает со строкой '/foo/bar/baz/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/foo/bar/baz/"), undefined); | ||
expect(reend.match("/foo/bar/baz/")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
}); | ||
describe("10. Тестируем шаблон '/foo/:bar?'", function() { | ||
describe("10. Тестируем шаблон '/foo/:bar?'", function () { | ||
const re = new PathToRegex("/foo/:bar?"); | ||
console.log("10. REGEXP:",re.regexp); | ||
it("шаблон совпадает со строкой ''. результат: `undefined`", function() { | ||
assert.equal( re.match(""), undefined); | ||
const reend = new PathToRegex("/foo/:bar?", { case: false, toEnd: false }); | ||
console.log("10. REGEXP toEnd[true]:", re.regexp); | ||
console.log("10. REGEXP toEnd[false]:", reend.regexp); | ||
it("шаблон совпадает со строкой ''. результат: `undefined`", function () { | ||
assert.equal(re.match(""), undefined); | ||
assert.equal(reend.match(""), undefined); | ||
}); | ||
it("шаблон совпадает со строкой '/'. результат: `undefined`", function() { | ||
assert.equal( re.match("/"), undefined); | ||
it("шаблон совпадает со строкой '/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/"), undefined); | ||
assert.equal(reend.match("/"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой 'foo'. результат: `{ bar: undefined }`", function() { | ||
expect( re.match("foo") ).to.deep.equal({bar: undefined}); | ||
}); | ||
it("шаблон совпадает со строкой '/foo'. результат: `{ bar: undefined }`", function() { | ||
expect( re.match("/foo") ).to.deep.equal({bar: undefined}); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/'. результат: `{ bar: undefined }`", function() { | ||
expect( re.match("foo/") ).to.deep.equal({bar: undefined}); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/'. результат: `{ bar: undefined }`", function() { | ||
expect( re.match("/foo/") ).to.deep.equal({bar: undefined}); | ||
}); | ||
it("шаблон совпадает со строкой 'foo'. результат: `{ bar: undefined }`", function () { | ||
expect(re.match("foo")).to.deep.equal({ bar: undefined }); | ||
expect(reend.match("foo")).to.deep.equal({ bar: undefined }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo'. результат: `{ bar: undefined }`", function () { | ||
expect(re.match("/foo")).to.deep.equal({ bar: undefined }); | ||
expect(reend.match("/foo")).to.deep.equal({ bar: undefined }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/'. результат: `{ bar: undefined }`", function () { | ||
expect(re.match("foo/")).to.deep.equal({ bar: undefined }); | ||
expect(reend.match("foo/")).to.deep.equal({ bar: undefined }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/'. результат: `{ bar: undefined }`", function () { | ||
expect(re.match("/foo/")).to.deep.equal({ bar: undefined }); | ||
expect(reend.match("/foo/")).to.deep.equal({ bar: undefined }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar'. результат: `{bar:'bar'}`", function() { | ||
expect( re.match("foo/bar") ).to.deep.equal({bar:'bar'}); | ||
it("шаблон совпадает со строкой 'foo/bar'. результат: `{bar:'bar'}`", function () { | ||
expect(re.match("foo/bar")).to.deep.equal({ bar: 'bar' }); | ||
expect(reend.match("foo/bar")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar'. результат: `{bar:'bar'}`", function() { | ||
expect( re.match("/foo/bar") ).to.deep.equal({bar:'bar'}); | ||
it("шаблон совпадает со строкой '/foo/bar'. результат: `{bar:'bar'}`", function () { | ||
expect(re.match("/foo/bar")).to.deep.equal({ bar: 'bar' }); | ||
expect(reend.match("/foo/bar")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar/'. результат: `{bar:'bar'}`", function() { | ||
expect( re.match("foo/bar/") ).to.deep.equal({bar:'bar'}); | ||
it("шаблон совпадает со строкой 'foo/bar/'. результат: `{bar:'bar'}`", function () { | ||
expect(re.match("foo/bar/")).to.deep.equal({ bar: 'bar' }); | ||
expect(reend.match("foo/bar/")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/'. результат: `{bar:'bar'}`", function() { | ||
expect( re.match("/foo/bar/") ).to.deep.equal({bar:'bar'}); | ||
it("шаблон совпадает со строкой '/foo/bar/'. результат: `{bar:'bar'}`", function () { | ||
expect(re.match("/foo/bar/")).to.deep.equal({ bar: 'bar' }); | ||
expect(reend.match("/foo/bar/")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон не совпадает со строкой 'foo/bar/baz'. результат: `undefined`", function() { | ||
assert.equal( re.match("foo/bar/baz"), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/foo/bar/baz'. результат: `undefined`", function() { | ||
assert.equal( re.match("/foo/bar/baz"), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой 'foo/bar/baz/'. результат: `undefined`", function() { | ||
assert.equal( re.match("foo/bar/baz/"), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/foo/bar/baz/'. результат: `undefined`", function() { | ||
assert.equal( re.match("/foo/bar/baz/"), undefined); | ||
it("шаблон не совпадает со строкой 'foo/bar/baz'. результат: `undefined`", function () { | ||
assert.equal(re.match("foo/bar/baz"), undefined); | ||
expect(reend.match("foo/bar/baz")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон не совпадает со строкой '/foo/bar/baz'. результат: `undefined`", function () { | ||
assert.equal(re.match("/foo/bar/baz"), undefined); | ||
expect(reend.match("/foo/bar/baz")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон не совпадает со строкой 'foo/bar/baz/'. результат: `undefined`", function () { | ||
assert.equal(re.match("foo/bar/baz/"), undefined); | ||
expect(reend.match("foo/bar/baz/")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон не совпадает со строкой '/foo/bar/baz/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/foo/bar/baz/"), undefined); | ||
expect(reend.match("/foo/bar/baz/")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
}); | ||
describe("11. Тестируем шаблон '/foo/:bar(.*)'", function() { | ||
describe("11. Тестируем шаблон '/foo/:bar(.*)'", function () { | ||
const re = new PathToRegex("/foo/:bar(.*)"); | ||
console.log("11. REGEXP:",re.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function() { | ||
assert.equal( re.match(""), undefined); | ||
const reend = new PathToRegex("/foo/:bar(.*)", { case: false, toEnd: false }); | ||
console.log("11. REGEXP toEnd[true]:", re.regexp); | ||
console.log("11. REGEXP toEnd[false]:", reend.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function () { | ||
assert.equal(re.match(""), undefined); | ||
assert.equal(reend.match(""), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function() { | ||
assert.equal( re.match("/"), undefined); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/"), undefined); | ||
assert.equal(reend.match("/"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой 'foo'. результат: `{ bar: undefined }`", function() { | ||
expect( re.match("foo") ).to.deep.equal({bar: undefined}); | ||
}); | ||
it("шаблон совпадает со строкой '/foo'. результат: `{ bar: undefined }`", function() { | ||
expect( re.match("/foo") ).to.deep.equal({bar: undefined}); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/'. результат: `{ bar: undefined }`", function() { | ||
expect( re.match("foo/") ).to.deep.equal({bar: undefined}); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/'. результат: `{ bar: undefined }`", function() { | ||
expect( re.match("/foo/") ).to.deep.equal({bar: undefined}); | ||
}); | ||
it("шаблон совпадает со строкой 'foo'. результат: `{ bar: undefined }`", function () { | ||
expect(re.match("foo")).to.deep.equal({ bar: undefined }); | ||
expect(reend.match("foo")).to.deep.equal({ bar: undefined }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo'. результат: `{ bar: undefined }`", function () { | ||
expect(re.match("/foo")).to.deep.equal({ bar: undefined }); | ||
expect(reend.match("/foo")).to.deep.equal({ bar: undefined }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/'. результат: `{ bar: undefined }`", function () { | ||
expect(re.match("foo/")).to.deep.equal({ bar: undefined }); | ||
expect(reend.match("foo/")).to.deep.equal({ bar: undefined }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/'. результат: `{ bar: undefined }`", function () { | ||
expect(re.match("/foo/")).to.deep.equal({ bar: undefined }); | ||
expect(reend.match("/foo/")).to.deep.equal({ bar: undefined }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar'. результат: `{bar:'bar'}`", function() { | ||
expect( re.match("foo/bar") ).to.deep.equal({bar:'bar'}); | ||
it("шаблон совпадает со строкой 'foo/bar'. результат: `{bar:'bar'}`", function () { | ||
expect(re.match("foo/bar")).to.deep.equal({ bar: 'bar' }); | ||
expect(reend.match("foo/bar")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar'. результат: `{bar:'bar'}`", function() { | ||
expect( re.match("/foo/bar") ).to.deep.equal({bar:'bar'}); | ||
it("шаблон совпадает со строкой '/foo/bar'. результат: `{bar:'bar'}`", function () { | ||
expect(re.match("/foo/bar")).to.deep.equal({ bar: 'bar' }); | ||
expect(reend.match("/foo/bar")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar/'. результат: `{bar:'bar'}`", function() { | ||
expect( re.match("foo/bar/") ).to.deep.equal({bar:'bar'}); | ||
it("шаблон совпадает со строкой 'foo/bar/'. результат: `{bar:'bar'}`", function () { | ||
expect(re.match("foo/bar/")).to.deep.equal({ bar: 'bar' }); | ||
expect(reend.match("foo/bar/")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/'. результат: `{bar:'bar'}`", function() { | ||
expect( re.match("/foo/bar/") ).to.deep.equal({bar:'bar'}); | ||
it("шаблон совпадает со строкой '/foo/bar/'. результат: `{bar:'bar'}`", function () { | ||
expect(re.match("/foo/bar/")).to.deep.equal({ bar: 'bar' }); | ||
expect(reend.match("/foo/bar")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar/baz'. результат: `{bar:['bar','baz']}`", function() { | ||
expect( re.match("foo/bar/baz") ).to.deep.equal({ bar: 'bar/baz' }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/baz'. результат: `{bar:['bar','baz']}`", function() { | ||
expect( re.match("/foo/bar/baz") ).to.deep.equal({ bar: 'bar/baz' }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar/baz/'. результат: `{bar:['bar','baz']}`", function() { | ||
expect( re.match("foo/bar/baz/") ).to.deep.equal({ bar: 'bar/baz' }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/baz/'. результат: `{bar:['bar','baz']}`", function() { | ||
expect( re.match("/foo/bar/baz/") ).to.deep.equal({ bar: 'bar/baz' }); | ||
it("шаблон совпадает со строкой 'foo/bar/baz'. результат: `{bar:['bar','baz']}`", function () { | ||
expect(re.match("foo/bar/baz")).to.deep.equal({ bar: 'bar/baz' }); | ||
expect(reend.match("foo/bar/baz")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/baz'. результат: `{bar:['bar','baz']}`", function () { | ||
expect(re.match("/foo/bar/baz")).to.deep.equal({ bar: 'bar/baz' }); | ||
expect(reend.match("/foo/bar/baz")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar/baz/'. результат: `{bar:['bar','baz']}`", function () { | ||
expect(re.match("foo/bar/baz/")).to.deep.equal({ bar: 'bar/baz' }); | ||
expect(reend.match("foo/bar/baz/")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/baz/'. результат: `{bar:['bar','baz']}`", function () { | ||
expect(re.match("/foo/bar/baz/")).to.deep.equal({ bar: 'bar/baz' }); | ||
expect(reend.match("/foo/bar/baz/")).to.deep.equal({ bar: 'bar' }); | ||
}); | ||
}); | ||
describe("12. Тестируем шаблон '/foo/:bar(.*)*'", function() { | ||
describe("12. Тестируем шаблон '/foo/:bar(.*)*'", function () { | ||
const re = new PathToRegex("/foo/:bar(.*)*"); | ||
console.log("12. REGEXP:",re.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function() { | ||
assert.equal( re.match(""), undefined); | ||
const reend = new PathToRegex("/foo/:bar(.*)*", { case: false, toEnd: false }); | ||
console.log("12. REGEXP toEnd[true]:", re.regexp); | ||
console.log("12. REGEXP toEnd[false]:", reend.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function () { | ||
assert.equal(re.match(""), undefined); | ||
assert.equal(reend.match(""), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function() { | ||
assert.equal( re.match("/"), undefined); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/"), undefined); | ||
assert.equal(reend.match("/"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой 'foo'. результат: `{ bar: [] }`", function() { | ||
expect( re.match("foo") ).to.deep.equal({bar: []}); | ||
}); | ||
it("шаблон совпадает со строкой '/foo'. результат: `{ bar: [] }`", function() { | ||
expect( re.match("/foo") ).to.deep.equal({bar: []}); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/'. результат: `{ bar: [] }`", function() { | ||
expect( re.match("foo/") ).to.deep.equal({bar: []}); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/'. результат: `{ bar: [] }`", function() { | ||
expect( re.match("/foo/") ).to.deep.equal({bar: []}); | ||
}); | ||
it("шаблон совпадает со строкой 'foo'. результат: `{ bar: [] }`", function () { | ||
expect(re.match("foo")).to.deep.equal({ bar: [] }); | ||
expect(reend.match("foo")).to.deep.equal({ bar: [] }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo'. результат: `{ bar: [] }`", function () { | ||
expect(re.match("/foo")).to.deep.equal({ bar: [] }); | ||
expect(reend.match("/foo")).to.deep.equal({ bar: [] }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/'. результат: `{ bar: [] }`", function () { | ||
expect(re.match("foo/")).to.deep.equal({ bar: [] }); | ||
expect(reend.match("foo/")).to.deep.equal({ bar: [] }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/'. результат: `{ bar: [] }`", function () { | ||
expect(re.match("/foo/")).to.deep.equal({ bar: [] }); | ||
expect(reend.match("/foo/")).to.deep.equal({ bar: [] }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar'. результат: `{bar:['bar']}`", function() { | ||
expect( re.match("foo/bar") ).to.deep.equal({bar:['bar']}); | ||
it("шаблон совпадает со строкой 'foo/bar'. результат: `{bar:['bar']}`", function () { | ||
expect(re.match("foo/bar")).to.deep.equal({ bar: ['bar'] }); | ||
expect(reend.match("foo/bar")).to.deep.equal({ bar: ['bar'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar'. результат: `{bar:['bar']}`", function() { | ||
expect( re.match("/foo/bar") ).to.deep.equal({bar:['bar']}); | ||
it("шаблон совпадает со строкой '/foo/bar'. результат: `{bar:['bar']}`", function () { | ||
expect(re.match("/foo/bar")).to.deep.equal({ bar: ['bar'] }); | ||
expect(reend.match("/foo/bar")).to.deep.equal({ bar: ['bar'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar/'. результат: `{bar:['bar']}`", function() { | ||
expect( re.match("foo/bar/") ).to.deep.equal({bar:['bar']}); | ||
it("шаблон совпадает со строкой 'foo/bar/'. результат: `{bar:['bar']}`", function () { | ||
expect(re.match("foo/bar/")).to.deep.equal({ bar: ['bar'] }); | ||
expect(reend.match("foo/bar/")).to.deep.equal({ bar: ['bar'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/'. результат: `{bar:['bar']}`", function() { | ||
expect( re.match("/foo/bar/") ).to.deep.equal({bar:['bar']}); | ||
it("шаблон совпадает со строкой '/foo/bar/'. результат: `{bar:['bar']}`", function () { | ||
expect(re.match("/foo/bar/")).to.deep.equal({ bar: ['bar'] }); | ||
expect(reend.match("/foo/bar")).to.deep.equal({ bar: ['bar'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar/baz'. результат: `{bar:['bar/baz']}`", function() { | ||
expect( re.match("foo/bar/baz") ).to.deep.equal({ bar: ['bar/baz'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/baz'. результат: `{bar:['bar/baz']}`", function() { | ||
expect( re.match("/foo/bar/baz") ).to.deep.equal({ bar: ['bar/baz'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar/baz/'. результат: `{bar:['bar/baz']}`", function() { | ||
expect( re.match("foo/bar/baz/") ).to.deep.equal({ bar: ['bar/baz'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/baz/'. результат: `{bar:['bar/baz']}`", function() { | ||
expect( re.match("/foo/bar/baz/") ).to.deep.equal({ bar: ['bar/baz'] }); | ||
it("шаблон совпадает со строкой 'foo/bar/baz'. результат: `{bar:['bar/baz']}`", function () { | ||
expect(re.match("foo/bar/baz")).to.deep.equal({ bar: ['bar/baz'] }); | ||
expect(reend.match("foo/bar/baz")).to.deep.equal({ bar: ['bar/baz'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/baz'. результат: `{bar:['bar/baz']}`", function () { | ||
expect(re.match("/foo/bar/baz")).to.deep.equal({ bar: ['bar/baz'] }); | ||
expect(reend.match("/foo/bar/baz")).to.deep.equal({ bar: ['bar/baz'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar/baz/'. результат: `{bar:['bar/baz']}`", function () { | ||
expect(re.match("foo/bar/baz/")).to.deep.equal({ bar: ['bar/baz'] }); | ||
expect(reend.match("foo/bar/baz/")).to.deep.equal({ bar: ['bar/baz'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/baz/'. результат: `{bar:['bar/baz']}`", function () { | ||
expect(re.match("/foo/bar/baz/")).to.deep.equal({ bar: ['bar/baz'] }); | ||
expect(reend.match("/foo/bar/baz/")).to.deep.equal({ bar: ['bar/baz'] }); | ||
}); | ||
}); | ||
describe("13. Тестируем шаблон '/foo/:bar(.+)+'", function() { | ||
describe("13. Тестируем шаблон '/foo/:bar(.+)+'", function () { | ||
const re = new PathToRegex("/foo/:bar(.+)+"); | ||
console.log("13. REGEXP:",re.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function() { | ||
assert.equal( re.match(""), undefined); | ||
const reend = new PathToRegex("/foo/:bar(.+)+", { case: false, toEnd: false }); | ||
console.log("13. REGEXP toEnd[true]:", re.regexp); | ||
console.log("13. REGEXP toEnd[false]:", reend.regexp); | ||
it("шаблон не совпадает со строкой ''. результат: `undefined`", function () { | ||
assert.equal(re.match(""), undefined); | ||
assert.equal(reend.match(""), undefined); | ||
}); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function() { | ||
assert.equal( re.match("/"), undefined); | ||
it("шаблон не совпадает со строкой '/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/"), undefined); | ||
assert.equal(reend.match("/"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой 'foo'. результат: `undefined`", function() { | ||
assert.equal( re.match("foo"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой '/foo'. результат: `undefined`", function() { | ||
assert.equal( re.match("/foo"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/'. результат: `undefined`", function() { | ||
assert.equal( re.match("foo/"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/'. результат: `undefined`", function() { | ||
assert.equal( re.match("/foo/"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой 'foo'. результат: `undefined`", function () { | ||
assert.equal(re.match("foo"), undefined); | ||
assert.equal(reend.match("foo"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой '/foo'. результат: `undefined`", function () { | ||
assert.equal(re.match("/foo"), undefined); | ||
assert.equal(reend.match("/foo"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/'. результат: `undefined`", function () { | ||
assert.equal(re.match("foo/"), undefined); | ||
assert.equal(reend.match("foo/"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/foo/"), undefined); | ||
assert.equal(reend.match("/foo/"), undefined); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar'. результат: `{bar:['bar']}`", function() { | ||
expect( re.match("foo/bar") ).to.deep.equal({bar:['bar']}); | ||
it("шаблон совпадает со строкой 'foo/bar'. результат: `{bar:['bar']}`", function () { | ||
expect(re.match("foo/bar")).to.deep.equal({ bar: ['bar'] }); | ||
expect(reend.match("foo/bar")).to.deep.equal({ bar: ['bar'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar'. результат: `{bar:['bar']}`", function() { | ||
expect( re.match("/foo/bar") ).to.deep.equal({bar:['bar']}); | ||
it("шаблон совпадает со строкой '/foo/bar'. результат: `{bar:['bar']}`", function () { | ||
expect(re.match("/foo/bar")).to.deep.equal({ bar: ['bar'] }); | ||
expect(reend.match("/foo/bar")).to.deep.equal({ bar: ['bar'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar/'. результат: `{bar:['bar']}`", function() { | ||
expect( re.match("foo/bar/") ).to.deep.equal({bar:['bar']}); | ||
it("шаблон совпадает со строкой 'foo/bar/'. результат: `{bar:['bar']}`", function () { | ||
expect(re.match("foo/bar/")).to.deep.equal({ bar: ['bar'] }); | ||
expect(reend.match("foo/bar/")).to.deep.equal({ bar: ['bar'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/'. результат: `{bar:['bar']}`", function() { | ||
expect( re.match("/foo/bar/") ).to.deep.equal({bar:['bar']}); | ||
it("шаблон совпадает со строкой '/foo/bar/'. результат: `{bar:['bar']}`", function () { | ||
expect(re.match("/foo/bar/")).to.deep.equal({ bar: ['bar'] }); | ||
expect(reend.match("/foo/bar/")).to.deep.equal({ bar: ['bar'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar/baz'. результат: `{bar:['bar/baz']}`", function() { | ||
expect( re.match("foo/bar/baz") ).to.deep.equal({ bar: ['bar/baz'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/baz'. результат: `{bar:['bar/baz']}`", function() { | ||
expect( re.match("/foo/bar/baz") ).to.deep.equal({ bar: ['bar/baz'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar/baz/'. результат: `{bar:['bar/baz']}`", function() { | ||
expect( re.match("foo/bar/baz/") ).to.deep.equal({ bar: ['bar/baz'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/baz/'. результат: `{bar:['bar/baz']}`", function() { | ||
expect( re.match("/foo/bar/baz/") ).to.deep.equal({ bar: ['bar/baz'] }); | ||
it("шаблон совпадает со строкой 'foo/bar/baz'. результат: `{bar:['bar/baz']}`", function () { | ||
expect(re.match("foo/bar/baz")).to.deep.equal({ bar: ['bar/baz'] }); | ||
expect(reend.match("foo/bar/baz")).to.deep.equal({ bar: ['bar/baz'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/baz'. результат: `{bar:['bar/baz']}`", function () { | ||
expect(re.match("/foo/bar/baz")).to.deep.equal({ bar: ['bar/baz'] }); | ||
expect(reend.match("/foo/bar/baz")).to.deep.equal({ bar: ['bar/baz'] }); | ||
}); | ||
it("шаблон совпадает со строкой 'foo/bar/baz/'. результат: `{bar:['bar/baz']}`", function () { | ||
expect(re.match("foo/bar/baz/")).to.deep.equal({ bar: ['bar/baz'] }); | ||
expect(reend.match("foo/bar/baz/")).to.deep.equal({ bar: ['bar/baz'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/foo/bar/baz/'. результат: `{bar:['bar/baz']}`", function () { | ||
expect(re.match("/foo/bar/baz/")).to.deep.equal({ bar: ['bar/baz'] }); | ||
expect(reend.match("/foo/bar/baz/")).to.deep.equal({ bar: ['bar/baz'] }); | ||
}); | ||
}); | ||
describe("14. Тестируем шаблон '/user/:id/bar/:key(\\d+):post?fak/:key(\\d+)*:foo+/test/pictures-:multi(\\w+?\\.png)*/:key?'", function() { | ||
describe("14. Тестируем шаблон '/user/:id/bar/:key(\\d+):post?fak/:key(\\d+)*:foo+/test/pictures-:multi(\\w+?\\.png)*/:key?'", function () { | ||
const re = new PathToRegex("/user/:id/bar/:key(\\d+):post?fak/:key(\\d+)*:foo+/test/pictures-:multi(\\w+?\\.png)*/:key?"); | ||
console.log("14. REGEXP:",re.regexp); | ||
it("шаблон совпадает со строкой '/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png/333'. \n\tрезультат: `{ id: '123', key: [ '111', '222', '333' ], post: 'qwerty', foo: [ 'foo' ], multi: [ 'p01.png', 'p02.png', 'p03.png' ] }`", function() { | ||
expect( re.match("/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png/333") ).to.deep.equal({ id: '123', key: [ '111', '222', '333' ], post: 'qwerty', foo: [ 'foo' ], multi: [ 'p01.png', 'p02.png', 'p03.png' ] }); | ||
console.log("14. REGEXP:", re.regexp); | ||
it("шаблон совпадает со строкой '/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png/333'. \n\tрезультат: `{ id: '123', key: [ '111', '222', '333' ], post: 'qwerty', foo: [ 'foo' ], multi: [ 'p01.png', 'p02.png', 'p03.png' ] }`", function () { | ||
expect(re.match("/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png/333")).to.deep.equal({ id: '123', key: ['111', '222', '333'], post: 'qwerty', foo: ['foo'], multi: ['p01.png', 'p02.png', 'p03.png'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png'. \n\tрезультат: `{ id: '123', key: [ '111', '222' ], post: 'qwerty', foo: [ 'foo' ], multi: [ 'p01.png', 'p02.png', 'p03.png' ] }`", function() { | ||
expect( re.match("/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png") ).to.deep.equal({ id: '123', key: [ '111', '222' ], post: 'qwerty', foo: [ 'foo' ], multi: [ 'p01.png', 'p02.png', 'p03.png' ] }); | ||
it("шаблон совпадает со строкой '/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png'. \n\tрезультат: `{ id: '123', key: [ '111', '222' ], post: 'qwerty', foo: [ 'foo' ], multi: [ 'p01.png', 'p02.png', 'p03.png' ] }`", function () { | ||
expect(re.match("/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png")).to.deep.equal({ id: '123', key: ['111', '222'], post: 'qwerty', foo: ['foo'], multi: ['p01.png', 'p02.png', 'p03.png'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/123/bar/111fak/foo/test/pictures-p01.png, p02.png, p03.png'. \n\tрезультат: `{ id: '123', key: [ '111' ], post: undefined, foo: [ 'foo' ], multi: [ 'p01.png', 'p02.png', 'p03.png' ] }`", function() { | ||
expect( re.match("/user/123/bar/111fak/foo/test/pictures-p01.png, p02.png, p03.png") ).to.deep.equal({ id: '123', key: [ '111' ], post: undefined, foo: [ 'foo' ], multi: [ 'p01.png', 'p02.png', 'p03.png' ] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/123/bar/111fak/foo/test/pictures-p01.png'. \n\tрезультат: `{ id: '123', key: [ '111' ], post: undefined, foo: [ 'foo' ], multi: [ 'p01.png' ] }`", function() { | ||
expect( re.match("/user/123/bar/111fak/foo/test/pictures-p01.png") ).to.deep.equal({ id: '123', key: [ '111' ], post: undefined, foo: [ 'foo' ], multi: [ 'p01.png' ] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/123/bar/111fak/foo/test/pictures-p01.png, p02.png, p03.png'. \n\tрезультат: `{ id: '123', key: [ '111' ], post: undefined, foo: [ 'foo' ], multi: [ 'p01.png', 'p02.png', 'p03.png' ] }`", function () { | ||
expect(re.match("/user/123/bar/111fak/foo/test/pictures-p01.png, p02.png, p03.png")).to.deep.equal({ id: '123', key: ['111'], post: undefined, foo: ['foo'], multi: ['p01.png', 'p02.png', 'p03.png'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/123/bar/111fak/foo/test/pictures-p01.png'. \n\tрезультат: `{ id: '123', key: [ '111' ], post: undefined, foo: [ 'foo' ], multi: [ 'p01.png' ] }`", function () { | ||
expect(re.match("/user/123/bar/111fak/foo/test/pictures-p01.png")).to.deep.equal({ id: '123', key: ['111'], post: undefined, foo: ['foo'], multi: ['p01.png'] }); | ||
}); | ||
@@ -617,3 +790,3 @@ }); | ||
// const re3 = new PathToRegex("/foo/:fooid/bar/:barid"); | ||
// it("создаем RegExp из \"/foo/:fooid/bar/:barid\"", function() { | ||
@@ -620,0 +793,0 @@ // assert.equal( re3 instanceof PathToRegex, true); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
76046
948
2