<commit_before>"use strict";

const {strict: assert} = require("assert");

const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");

const typeahead = zrequire("../shared/js/typeahead");

const unicode_emojis = [
    ["1f43c", "panda_face"],
    ["1f642", "smile"],
    ["1f604", "big_smile"],
    ["1f368", "ice_cream"],
    ["1f366", "soft_ice_cream"],
    ["1f6a5", "horizontal_traffic_light"],
    ["1f6a6", "traffic_light"],
    ["1f537", "large_blue_diamond"],
    ["1f539", "small_blue_diamond"],
];

const emojis = [
    {emoji_name: "japanese_post_office", url: "TBD"},
    {emoji_name: "tada", random_field: "whatever"},
    ...unicode_emojis.map(([emoji_code, emoji_name]) => ({
        emoji_name,
        emoji_code,
    })),
];

run_test("get_emoji_matcher", () => {
    function assert_matches(query, expected) {
        const matcher = typeahead.get_emoji_matcher(query);
        assert.deepEqual(
            emojis
                .filter((emoji) => matcher(emoji))
                .map((emoji) => emoji.emoji_name)
                .sort(),
            expected,
        );
    }

    assert_matches("notaemoji", []);
    assert_matches("da_", []);
    assert_matches("da ", []);

    assert_matches("da", ["panda_face", "tada"]);
    assert_matches("panda ", ["panda_face"]);
    assert_matches("smil", ["big_smile", "smile"]);
    assert_matches("mile", ["big_smile", "smile"]);

    assert_matches("japanese_post_", ["japanese_post_office"]);
    assert_matches("japanese post ", ["japanese_post_office"]);<commit_msg>typeahead tests [nfc]: Split up get_emoji_matcher test function.<commit_after>"use strict";

const {strict: assert} = require("assert");

const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");

const typeahead = zrequire("../shared/js/typeahead");

const unicode_emojis = [
    ["1f43c", "panda_face"],
    ["1f642", "smile"],
    ["1f604", "big_smile"],
    ["1f368", "ice_cream"],
    ["1f366", "soft_ice_cream"],
    ["1f6a5", "horizontal_traffic_light"],
    ["1f6a6", "traffic_light"],
    ["1f537", "large_blue_diamond"],
    ["1f539", "small_blue_diamond"],
];

const emojis = [
    {emoji_name: "japanese_post_office", url: "TBD"},
    {emoji_name: "tada", random_field: "whatever"},
    ...unicode_emojis.map(([emoji_code, emoji_name]) => ({
        emoji_name,
        emoji_code,
    })),
];

function assert_emoji_matches(query, expected) {
    const matcher = typeahead.get_emoji_matcher(query);
    const matches = emojis.filter((emoji) => matcher(emoji));
    assert.deepEqual(matches.map((emoji) => emoji.emoji_name).sort(), expected);
}

run_test("get_emoji_matcher: nonmatches", () => {
    assert_emoji_matches("notaemoji", []);
    assert_emoji_matches("da_", []);
    assert_emoji_matches("da ", []);
});

run_test("get_emoji_matcher: misc matches", () => {
    assert_emoji_matches("da", ["panda_face", "tada"]);
    assert_emoji_matches("panda ", ["panda_face"]);
    assert_emoji_matches("smil", ["big_smile", "smile"]);
    assert_emoji_matches("mile", ["big_smile", "smile"]);

    assert_emoji_matches("japanese_post_", ["japanese_post_office"]);
    assert_emoji_matches("japanese post ", ["japanese_post_office"]);
{'fraction_non_alphanumeric': 0.19430844553243573, 'fraction_numerical': 0.020195838433292534, 'mean_word_length': 4.238782051282051, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1067373', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1199, 'n_words': 175}