TypeScript vs/base/parts/quickopen/common/quickOpenScorer _doScore示例

说明

typescript vs/base/parts/quickopen/common/quickopenscorer _doscore示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: TypeScript

命名空间/包名称: vs/base/parts/quickopen/common/quickOpenScorer

示例#1
文件: quickOpenScorer.test.ts 项目: golf1052/vscode

	test('score (non fuzzy)', function () {
		const target = 'HeLlo-World';

		assert.ok(scorer._doScore(target, 'HelLo-World', false)[0] > 0);
		assert.equal(scorer._doScore(target, 'HelLo-World', false)[1].length, 'HelLo-World'.length);

		assert.ok(scorer._doScore(target, 'hello-world', false)[0] > 0);
		assert.equal(scorer._doScore(target, 'HW', false)[0], 0);
		assert.ok(scorer._doScore(target, 'h', false)[0] > 0);
		assert.ok(scorer._doScore(target, 'ello', false)[0] > 0);
		assert.ok(scorer._doScore(target, 'ld', false)[0] > 0);
		assert.equal(scorer._doScore(target, 'eo', false)[0], 0);
	});

示例#2
文件: quickOpenScorer.test.ts 项目: golf1052/vscode

	test('score (fuzzy)', function () {
		const target = 'HeLlo-World';

		const scores: scorer.Score[] = [];
		scores.push(scorer._doScore(target, 'HelLo-World', true)); // direct case match
		scores.push(scorer._doScore(target, 'hello-world', true)); // direct mix-case match
		scores.push(scorer._doScore(target, 'HW', true)); // direct case prefix (multiple)
		scores.push(scorer._doScore(target, 'hw', true)); // direct mix-case prefix (multiple)
		scores.push(scorer._doScore(target, 'H', true)); // direct case prefix
		scores.push(scorer._doScore(target, 'h', true)); // direct mix-case prefix
		scores.push(scorer._doScore(target, 'ld', true)); // in-string mix-case match (consecutive, avoids scattered hit)
		scores.push(scorer._doScore(target, 'W', true)); // direct case word prefix
		scores.push(scorer._doScore(target, 'w', true)); // direct mix-case word prefix
		scores.push(scorer._doScore(target, 'Ld', true)); // in-string case match (multiple)
		scores.push(scorer._doScore(target, 'L', true)); // in-string case match
		scores.push(scorer._doScore(target, 'l', true)); // in-string mix-case match
		scores.push(scorer._doScore(target, '4', true)); // no match

		// Assert scoring order
		let sortedScores = scores.concat().sort((a, b) => b[0] - a[0]);
		assert.deepEqual(scores, sortedScores);

		// Assert scoring positions
		let positions = scores[0][1];
		assert.equal(positions.length, 'HelLo-World'.length);

		positions = scores[2][1];
		assert.equal(positions.length, 'HW'.length);
		assert.equal(positions[0], 0);
		assert.equal(positions[1], 6);
	});

展开阅读全文