Skip to content

Commit

Permalink
Merge pull request #33 from petermoresi/master
Browse files Browse the repository at this point in the history
Fix SEARCH function with test cases
  • Loading branch information
jalateras committed Dec 29, 2014
2 parents ab20084 + 3bac730 commit 2010a9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,13 @@ exports.RIGHT = function(text, number) {
};

exports.SEARCH = function(find_text, within_text, position) {
var foundAt;
if (typeof find_text !== 'string' || typeof within_text !== 'string') {
return error.value;
}
position = (position === undefined) ? 0 : position;
return within_text.toLowerCase().indexOf(find_text.toLowerCase(), position - 1) + 1;
foundAt = within_text.toLowerCase().indexOf(find_text.toLowerCase(), position - 1)+1;
return (foundAt === 0)?error.value:foundAt;
};

exports.SPLIT = function (text, separator) {
Expand Down
4 changes: 3 additions & 1 deletion test/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ suite('Text', function() {
text.SEARCH('e', 'Statements', 6).should.equal(7);
text.SEARCH('margin', 'Profit Margin').should.equal(8);
text.SEARCH(true, 'bool').should.equal(error.value);
text.SEARCH("foo", "bar").should.equal(error.value);
text.SEARCH("ba", "bar").should.equal(1);
});

test('SPLIT', function() {
Expand Down Expand Up @@ -219,4 +221,4 @@ suite('Text', function() {
text.VALUE('16:48:00').should.equal(60480);
text.VALUE(true).should.equal(error.value);
});
});
});

0 comments on commit 2010a9b

Please sign in to comment.