Skip to content

Commit

Permalink
Add multiword search in step and fixture docs
Browse files Browse the repository at this point in the history
  • Loading branch information
schipiga committed Mar 13, 2018
1 parent d30c38e commit 530990e
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/tools.js
Expand Up @@ -18,8 +18,6 @@ var d = U.switchColor();
var self = module.exports;

self.listSteps = filter => {
filter = filter || "";

global.SS || load();

var steps = [];
Expand All @@ -43,8 +41,8 @@ self.listSteps = filter => {
if (!util.isFunction(func)) continue;

var doc = getDoc(func);
if (!(s.toLowerCase().includes(filter) ||
(doc && doc.toLowerCase().includes(filter)))) continue;

if (!(contains(s, filter) || contains(doc, filter))) continue;

console.log(d(`${++i}. ${s}:`));
console.log(d(` ${func.toString().split("{")[0]}{...}`));
Expand Down Expand Up @@ -80,8 +78,6 @@ self.listTests = filter => {
};

self.listFixtures = filter => {
filter = filter || "";

load();

var i = 0;
Expand All @@ -90,8 +86,7 @@ self.listFixtures = filter => {

var doc = getDoc(global[fx]);

if (!(fx.toLowerCase().includes(filter) ||
(doc && doc.toLowerCase().includes(filter)))) continue;
if (!(contains(fx, filter) || contains(doc, filter))) continue;

console.log(d(`${++i}. ${fx}`));

Expand All @@ -106,6 +101,19 @@ self.listFixtures = filter => {
};
};

var contains = (string, filter) => {
if (!string) return false;
if (!filter) return true;

string = string.toLowerCase();
filter = filter.split(/ +/g);

for (var f of filter) {
if (!string.includes(f)) return false;
};
return true;
};

var getDoc = func => {
return func
.__doc__
Expand Down

0 comments on commit 530990e

Please sign in to comment.