Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SEARCH function with test cases #33

Merged
merged 2 commits into from
Dec 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
});