Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 57d2628

Browse files
committed
review comment responses and the addition of two failing tests that
illustrate bugs found during review
1 parent 4eafccf commit 57d2628

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

src/search/QuickOpen.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
25-
/*global define, $, window, setTimeout, ArrayBuffer, Int8Array */
25+
/*global define, $, window, setTimeout */
2626

2727
/*
2828
* Displays an auto suggest pop-up list of files to allow the user to quickly navigate to a file and lines
@@ -770,4 +770,10 @@ define(function (require, exports, module) {
770770
exports.beginSearch = beginSearch;
771771
exports.addQuickOpenPlugin = addQuickOpenPlugin;
772772
exports.highlightMatch = highlightMatch;
773+
774+
// accessing these from this module will ultimately be deprecated
775+
exports.stringMatch = StringMatch.stringMatch;
776+
exports.SearchResult = StringMatch.SearchResult;
777+
exports.basicMatchSort = StringMatch.basicMatchSort;
778+
exports.multiFieldSort = StringMatch.multiFieldSort;
773779
});

src/utils/StringMatch.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
25-
/*global define, $, window, setTimeout, ArrayBuffer, Int8Array */
25+
/*global define, $, window, setTimeout */
2626
/*unittests: StringMatch */
2727

2828
define(function (require, exports, module) {
@@ -149,7 +149,7 @@ define(function (require, exports, module) {
149149
* @param {Array} specials list of special indexes in str (from findSpecialCharacters)
150150
* @param {int} startingSpecial index into specials array to start scanning with
151151
* @param {boolean} lastSegmentStart optional which character does the last segment start at
152-
* @return {{ranges:Array.{text:string, matched:boolean, includesLastSegment:boolean}, matchGoodness:int, scoreDebug: Object}} matched ranges and score
152+
* @return {{ranges:Array.<{text:string, matched:boolean, includesLastSegment:boolean}>, matchGoodness:int, scoreDebug: Object}} matched ranges and score
153153
*/
154154
function getMatchRanges(query, str, compareStr, specials, startingSpecial, lastSegmentStart) {
155155
var ranges = [];
@@ -393,7 +393,7 @@ define(function (require, exports, module) {
393393
* @param {Array} specials list of special indexes in str (from findSpecialCharacters)
394394
* @param {int} startingSpecial index into specials array to start scanning with
395395
* @param {boolean} lastSegmentStart which character does the last segment start at
396-
* @return {{ranges:Array.{text:string, matched:boolean, includesLastSegment:boolean}, remainder:string, matchGoodness:int, scoreDebug: Object}} matched ranges and score
396+
* @return {{ranges:Array.<{text:string, matched:boolean, includesLastSegment:boolean}>, remainder:string, matchGoodness:int, scoreDebug: Object}} matched ranges and score
397397
*/
398398
function _lastSegmentSearch(query, str, compareStr, specials, startingSpecial, lastSegmentStart) {
399399
var queryCounter, matchRanges;
@@ -436,7 +436,7 @@ define(function (require, exports, module) {
436436
* @param {string} str the original string to search
437437
* @param {Array} specials list of special indexes in str (from findSpecialCharacters)
438438
* @param {int} lastSegmentSpecialsIndex index into specials array to start scanning with
439-
* @return {{ranges:Array.{text:string, matched:boolean, includesLastSegment:boolean}, matchGoodness:int, scoreDebug: Object}} matched ranges and score
439+
* @return {{ranges:Array.<{text:string, matched:boolean, includesLastSegment:boolean}>, matchGoodness:int, scoreDebug: Object}} matched ranges and score
440440
*/
441441
function _computeMatch(query, str, specials, lastSegmentSpecialsIndex) {
442442
// set up query as all lower case and make a lower case string to use for comparisons

test/spec/StringMatch-test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,16 @@ define(function (require, exports, module) {
288288
{ text: "pen.js", matched: false, includesLastSegment: true }
289289
]
290290
});
291+
292+
expect(stringMatch("MoonsunSum", "sun")).toEqual({
293+
matchGoodness: jasmine.any(Number),
294+
label: "MoonsunSum",
295+
stringRanges: [
296+
{ text: "Moon", matched: false, includesLastSegment: true },
297+
{ text: "sun", matched: true, includesLastSegment: true },
298+
{ text: "Sum", matched: false, includesLastSegment: true }
299+
]
300+
});
291301
});
292302

293303
it("should prefer special characters", function () {
@@ -417,7 +427,11 @@ define(function (require, exports, module) {
417427
result = StringMatch.stringMatch("src/thirdparty/CodeMirror2/mode/ntriples/index.html", "codemirror");
418428
expect(result.scoreDebug.notStartingOnSpecial).toEqual(0);
419429
});
420-
430+
431+
it("should try to prioritize points for the last segment", function () {
432+
var result = StringMatch.stringMatch("abc/def/zzz/abc/def", "abc/def");
433+
expect(result.scoreDebug.lastSegment).toBeGreaterThan(0);
434+
});
421435
});
422436
});
423437
});

0 commit comments

Comments
 (0)