Skip to content

Commit 2010a9b

Browse files
committed
Merge pull request #33 from petermoresi/master
Fix SEARCH function with test cases
2 parents ab20084 + 3bac730 commit 2010a9b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/text.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,13 @@ exports.RIGHT = function(text, number) {
235235
};
236236

237237
exports.SEARCH = function(find_text, within_text, position) {
238+
var foundAt;
238239
if (typeof find_text !== 'string' || typeof within_text !== 'string') {
239240
return error.value;
240241
}
241242
position = (position === undefined) ? 0 : position;
242-
return within_text.toLowerCase().indexOf(find_text.toLowerCase(), position - 1) + 1;
243+
foundAt = within_text.toLowerCase().indexOf(find_text.toLowerCase(), position - 1)+1;
244+
return (foundAt === 0)?error.value:foundAt;
243245
};
244246

245247
exports.SPLIT = function (text, separator) {

test/text.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ suite('Text', function() {
160160
text.SEARCH('e', 'Statements', 6).should.equal(7);
161161
text.SEARCH('margin', 'Profit Margin').should.equal(8);
162162
text.SEARCH(true, 'bool').should.equal(error.value);
163+
text.SEARCH("foo", "bar").should.equal(error.value);
164+
text.SEARCH("ba", "bar").should.equal(1);
163165
});
164166

165167
test('SPLIT', function() {
@@ -219,4 +221,4 @@ suite('Text', function() {
219221
text.VALUE('16:48:00').should.equal(60480);
220222
text.VALUE(true).should.equal(error.value);
221223
});
222-
});
224+
});

0 commit comments

Comments
 (0)