74 lines
2.6 KiB
TypeScript
74 lines
2.6 KiB
TypeScript
import assert from "node:assert/strict";
|
||
import { test } from "node:test";
|
||
|
||
import { createTextMatcher, normalizeSearchText } from "./text-search";
|
||
|
||
test("la comparación parcial pliega vocales, caja y representaciones Unicode equivalentes", () => {
|
||
for (const [query, value] of [
|
||
["portatil", "Mi portátil 24"],
|
||
[" APLICACION ", "Aplicación"],
|
||
["alvaro", "Álvaro"],
|
||
["administracion", "Administración"],
|
||
["Á", "A\u0301"],
|
||
["aguero", "Agüero"],
|
||
["AEIOU", "Àèìòù"],
|
||
["a", "a\u0301\u0308"],
|
||
["a\u0327", "a\u0327\u0301"],
|
||
]) {
|
||
assert.ok(query && value);
|
||
assert.equal(createTextMatcher(query)(value), true, `${query}: ${value}`);
|
||
assert.equal(normalizeSearchText(value), normalizeSearchText(value.normalize("NFD")));
|
||
}
|
||
});
|
||
|
||
test("ñ conserva identidad compuesta y descompuesta y otras escrituras no se transliteran", () => {
|
||
for (const [query, value] of [
|
||
["Pena", "Peña"],
|
||
["ano", "año"],
|
||
["canon", "cañón"],
|
||
["c", "ç"],
|
||
["a", "а"],
|
||
["か", "が"],
|
||
["α", "ά"],
|
||
]) {
|
||
assert.ok(query && value);
|
||
assert.equal(createTextMatcher(query)(value), false, `${query}: ${value}`);
|
||
}
|
||
assert.equal(createTextMatcher("PEN\u0303A")("Peña"), true);
|
||
assert.equal(createTextMatcher("cañon")("cañón"), true);
|
||
assert.equal(createTextMatcher("東京")("東京支社"), true);
|
||
assert.equal(normalizeSearchText("Ñ\u0301"), normalizeSearchText("N\u0303\u0301"));
|
||
});
|
||
|
||
test("puntuación técnica, números y espacios interiores siguen siendo significativos", () => {
|
||
for (const value of [
|
||
"192.168.5.201",
|
||
"AA:BB:01:02:03:04",
|
||
"AA-BB-01",
|
||
"\\\\srv\\Área",
|
||
"/srv/Área",
|
||
"PC-001",
|
||
"a b",
|
||
]) {
|
||
const matches = createTextMatcher(` ${value} `);
|
||
|
||
assert.equal(matches(value), true);
|
||
assert.equal(matches(value.replace(/[.:/\\ -]/gu, "")), false);
|
||
assert.equal(matches(value), true);
|
||
}
|
||
assert.equal(createTextMatcher("001")(1001), true);
|
||
assert.equal(createTextMatcher("false")(false), true);
|
||
assert.equal(createTextMatcher("0")(0), true);
|
||
});
|
||
|
||
test("vacíos y valores sin texto no serializan objetos arbitrarios", () => {
|
||
for (const value of ["", null, undefined, 0, false, { name: "portátil" }, ["portátil"]]) {
|
||
assert.equal(createTextMatcher(" ")(value), true);
|
||
}
|
||
for (const value of [null, undefined, { name: "portátil" }, ["portátil"], Symbol("portátil")]) {
|
||
assert.equal(createTextMatcher("portatil")(value), false);
|
||
}
|
||
assert.equal(normalizeSearchText(""), "");
|
||
assert.equal(normalizeSearchText(normalizeSearchText(" ÁÑÜ ")), "añu");
|
||
});
|