Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
130 lines
5.8 KiB
JavaScript
130 lines
5.8 KiB
JavaScript
"use strict";
|
|
|
|
const assert = require("node:assert/strict");
|
|
|
|
const {$t} = require("./lib/i18n.cjs");
|
|
const {zrequire} = require("./lib/namespace.cjs");
|
|
const {run_test} = require("./lib/test.cjs");
|
|
|
|
const pygments_data = zrequire("pygments_data");
|
|
const realm_playground = zrequire("realm_playground");
|
|
const typeahead_helper = zrequire("typeahead_helper");
|
|
const {initialize_user_settings} = zrequire("user_settings");
|
|
|
|
run_test("get_pygments_typeahead_list_for_composebox", () => {
|
|
// When no Code Playground is configured, the list of candidates should
|
|
// include everything in pygments_data, but nothing more. Order doesn't
|
|
// matter.
|
|
let candidates = realm_playground.get_pygments_typeahead_list_for_composebox();
|
|
assert.ok(Object.keys(pygments_data.langs).every((value) => candidates.includes(value)));
|
|
assert.equal(candidates.length, Object.keys(pygments_data.langs).length);
|
|
|
|
const custom_pygment_language = "Custom_lang";
|
|
const playground_data = [
|
|
{
|
|
id: 2,
|
|
name: "Custom Lang",
|
|
pygments_language: custom_pygment_language,
|
|
url_template: "https://example.com/?q={code}",
|
|
},
|
|
];
|
|
realm_playground.initialize({
|
|
playground_data,
|
|
pygments_comparator_func: typeahead_helper.compare_language,
|
|
});
|
|
|
|
// Verify that Code Playground's pygments_language shows up in the result.
|
|
// As well as all of pygments_data. Order doesn't matter and the result
|
|
// shouldn't include anything else.
|
|
candidates = realm_playground.get_pygments_typeahead_list_for_composebox();
|
|
assert.ok(Object.keys(pygments_data.langs).every((value) => candidates.includes(value)));
|
|
assert.ok(candidates.includes(custom_pygment_language));
|
|
assert.equal(
|
|
candidates.length,
|
|
Object.keys(pygments_data.langs).length + playground_data.length,
|
|
);
|
|
});
|
|
|
|
run_test("get_pygments_typeahead_list_for_settings", () => {
|
|
initialize_user_settings({user_settings: {}});
|
|
|
|
const custom_pygment_language = "custom_lang";
|
|
const playground_data = [
|
|
{
|
|
id: 1,
|
|
name: "Custom Lang #1",
|
|
pygments_language: custom_pygment_language,
|
|
url_template: "https://example.com/?q={code}",
|
|
},
|
|
{
|
|
id: 2,
|
|
name: "Custom Lang #2",
|
|
pygments_language: custom_pygment_language,
|
|
url_template: "https://example.com/?q={code}",
|
|
},
|
|
{
|
|
id: 3,
|
|
name: "Invent a Language",
|
|
pygments_language: "invent_a_lang",
|
|
url_template: "https://example.com/?q={code}",
|
|
},
|
|
];
|
|
realm_playground.initialize({
|
|
playground_data,
|
|
pygments_comparator_func: typeahead_helper.compare_language,
|
|
});
|
|
|
|
let candidates = realm_playground.get_pygments_typeahead_list_for_settings("");
|
|
let iterator = candidates.entries();
|
|
assert.equal(iterator.next().value[1], $t({defaultMessage: "Custom language: custom_lang"}));
|
|
assert.equal(iterator.next().value[1], $t({defaultMessage: "Custom language: invent_a_lang"}));
|
|
assert.equal(iterator.next().value[1], "Text only (text, text)");
|
|
assert.equal(iterator.next().value[1], "quote (quote, quote)");
|
|
assert.equal(iterator.next().value[1], "spoiler (spoiler, spoiler)");
|
|
assert.equal(iterator.next().value[1], "math (math, math)");
|
|
assert.equal(iterator.next().value[1], "JavaScript (javascript, js, javascript, js)");
|
|
assert.equal(
|
|
iterator.next().value[1],
|
|
"Python (python, bazel, py, py3, pyi, python3, sage, starlark, python, bazel, py, py3, pyi, python3, sage, starlark)",
|
|
);
|
|
assert.equal(iterator.next().value[1], "Java (java, java)");
|
|
assert.equal(iterator.next().value[1], "Go (go, golang, go, golang)");
|
|
assert.equal(iterator.next().value[1], "Rust (rust, rs, rust, rs)");
|
|
|
|
// Test typing "cu". Previously added custom languages should show up too.
|
|
candidates = realm_playground.get_pygments_typeahead_list_for_settings("cu");
|
|
iterator = candidates.entries();
|
|
assert.equal(
|
|
iterator.next().value[1],
|
|
$t({defaultMessage: "Custom language: {query}"}, {query: "cu"}),
|
|
);
|
|
assert.equal(iterator.next().value[1], $t({defaultMessage: "Custom language: custom_lang"}));
|
|
assert.equal(iterator.next().value[1], $t({defaultMessage: "Custom language: invent_a_lang"}));
|
|
assert.equal(iterator.next().value[1], "Text only (text, text)");
|
|
assert.equal(iterator.next().value[1], "quote (quote, quote)");
|
|
assert.equal(iterator.next().value[1], "spoiler (spoiler, spoiler)");
|
|
assert.equal(iterator.next().value[1], "math (math, math)");
|
|
assert.equal(iterator.next().value[1], "JavaScript (javascript, js, javascript, js)");
|
|
assert.equal(
|
|
iterator.next().value[1],
|
|
"Python (python, bazel, py, py3, pyi, python3, sage, starlark, python, bazel, py, py3, pyi, python3, sage, starlark)",
|
|
);
|
|
|
|
// Test typing "invent_a_lang". Make sure there is no duplicate entries.
|
|
candidates = realm_playground.get_pygments_typeahead_list_for_settings("invent_a_lang");
|
|
iterator = candidates.entries();
|
|
assert.equal(iterator.next().value[1], $t({defaultMessage: "Custom language: invent_a_lang"}));
|
|
assert.equal(iterator.next().value[1], $t({defaultMessage: "Custom language: custom_lang"}));
|
|
assert.equal(iterator.next().value[1], "Text only (text, text)");
|
|
assert.equal(iterator.next().value[1], "quote (quote, quote)");
|
|
assert.equal(iterator.next().value[1], "spoiler (spoiler, spoiler)");
|
|
|
|
// Test typing a query with diacritics. The "Custom language" option keeps them.
|
|
candidates = realm_playground.get_pygments_typeahead_list_for_settings("Français");
|
|
iterator = candidates.entries();
|
|
assert.deepEqual(iterator.next().value, [
|
|
"français",
|
|
$t({defaultMessage: "Custom language: {query}"}, {query: "français"}),
|
|
]);
|
|
});
|