typeahead: Handle non-pygments data in compare_language_by_popularity.

This added functionality will be used to compare pygment_language from
Code Playgrounds.

There is a choice of how to sort languages with popularity versus
without popularity. I chose to sort the Code Playground custom language
after other pygment languages based on the reasoning in the comments.
This commit is contained in:
Trident Pancake
2023-01-07 13:08:18 -08:00
committed by Tim Abbott
parent 6f904dbec2
commit f96daca32c
2 changed files with 54 additions and 1 deletions

View File

@@ -825,4 +825,14 @@ test("compare_language", () => {
// "abap" and "amdgpu" both have priority = 0 at this time, so there is a tie.
// Alphabetical order should be used to break that tie.
assert.equal(th.compare_language("abap", "amdgpu"), util.strcmp("abap", "amdgpu"));
// Test with languages that aren't in the generated pygments data.
assert.equal(actual_pygments_data.langs.custom_a, undefined);
assert.equal(actual_pygments_data.langs.custom_b, undefined);
// Since custom_a has no popularity score, it gets sorted behind python.
assert.equal(th.compare_language("custom_a", "python"), 1);
assert.equal(th.compare_language("python", "custom_a"), -1);
// Whenever there is a tie, even in the case neither have a popularity
// score, then alphabetical order is used to break the tie.
assert.equal(th.compare_language("custom_a", "custom_b"), util.strcmp("custom_a", "custom_b"));
});