Skip to content

Commit

Permalink
Created unit test for issue #3
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdeis committed Aug 20, 2017
1 parent 102209d commit 016da57
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/lib/rules/config-issue-2and3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require('fs');

//https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}

const template = fs.readFileSync(`${__dirname}/template-issue-3.js`,"utf8");
const mustMatch = escapeRegExp(template).replace('<%= YEAR %>', '20\\d\\d');

module.exports = {template,mustMatch};
7 changes: 6 additions & 1 deletion tests/lib/rules/notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ function noStyle(){
}
`;

const issue3options = require(`${__dirname}/config-issue-2and3`);
const issue3code = fs.readFileSync(`${__dirname}/sample-issue-3.js`,"utf8");

const issue3 = {options:[issue3options],code:issue3code};


ruleTester.run("notice",rule,{
Expand Down Expand Up @@ -59,5 +63,6 @@ ruleTester.run("notice",rule,{
}
`,
options:[{mustMatch,template}]
}]
},
issue3]
});
17 changes: 17 additions & 0 deletions tests/lib/rules/sample-issue-3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright 2017 Moshe Simantov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
console.error("Don't run `mocha` directly. Use `make test`.");
process.exit(0);
15 changes: 15 additions & 0 deletions tests/lib/rules/template-issue-3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright <%= YEAR %> Moshe Simantov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

0 comments on commit 016da57

Please sign in to comment.