Skip to content

Commit

Permalink
fix: #5
Browse files Browse the repository at this point in the history
  • Loading branch information
srfrnk committed Feb 23, 2018
1 parent 13348b6 commit da51ebf
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
17 changes: 17 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Gulp test-server",
"program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js",
"args": ["test-server"],
"outputCapture": "std",
"runtimeExecutable": "/home/shahar/.nvm/versions/node/v6.9.1/bin/node"
}
]
}
6 changes: 3 additions & 3 deletions gulpfile.js
Expand Up @@ -16,16 +16,16 @@ gulp.task('minify', function () {
/**
* Run test once and exit
*/
gulp.task('test', ['test client', 'test server']);
gulp.task('test', ['test-client', 'test-server']);

gulp.task('test client', function (done) {
gulp.task('test-client', function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done);
});

gulp.task('test server', function () {
gulp.task('test-server', function () {
return gulp.src('test/server.js')
.pipe(jasmine());
});
Expand Down
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions re-tree.js
Expand Up @@ -44,6 +44,22 @@
return (!!res) ? res : exec(string, item);
}, null);
}
else if (regex && Array.isArray(regex.and)) {
if(test(string,regex))
{
return exec(string,regex.and);
}
else
{
return null;
}
}
else if (regex && Array.isArray(regex.or)) {
return exec(string,regex.or);
}
else if (regex && regex.not) {
return !exec(string, regex.not)?[]:null;
}
else {
return null;
}
Expand Down
19 changes: 19 additions & 0 deletions test/server.js
Expand Up @@ -196,6 +196,25 @@ var re = {
expect(reTree.exec("1234d5678",[/^\d+([a-z]+)\d+$/,/^\d+a([a-z]+)\d+$/])).toEqual(/^\d+([a-z]+)\d+$/.exec("1234d5678"));
expect(reTree.exec("1234d5678",[/^\d+([a-z]+)\d+$/,/^\d+a([a-z]+)\d+$/])).not.toEqual(/^\d+(a[a-z]+)\d+$/.exec("1234d5678"));
});

// Issue #5
it('should handle AND expressions',function(){
expect(reTree.exec("1234d5678",{and:[/2(.)/,/3/]})).toEqual(/2(.)/.exec("1234d5678"));
expect(reTree.exec("1234d5678",{and:[/2(.)/,/9/]})).toEqual(null);
});
it('should handle OR expressions',function(){
expect(reTree.exec("1234d5678",{or:[/2(.)/,/3/]})).toEqual(/2(.)/.exec("1234d5678"));
expect(reTree.exec("1234d5678",{or:[/9(.)/,/3(.)/]})).toEqual(/3(.)/.exec("1234d5678"));
expect(reTree.exec("1234d5678",{or:[/9(.)/,/10/]})).toEqual(null);
});
it('should handle NOT expressions',function(){
expect(reTree.exec("1234d5678",{not:/9/})).toEqual([]);
expect(reTree.exec("1234d5678",{not:/8/})).toEqual(null);
});
it('should handle complex expressions',function(){
expect(reTree.exec("1234d5678",{and:[{or:[/2(.)/,/3/]},{not:/9/}]})).toEqual(/2(.)/.exec("1234d5678"));
expect(reTree.exec("1234d5678",{and:[{or:[/2(.)/,/3/]},/9/]})).toEqual(null);
});
});
});
})();

0 comments on commit da51ebf

Please sign in to comment.