|
| 1 | +import { isValidAlphaAbbreviation } from "./alpha_abbreviation.js"; |
| 2 | + |
| 3 | +function test(word: string, abbr: string, expected: boolean) { |
| 4 | + const result = isValidAlphaAbbreviation(word, abbr); |
| 5 | + const status = result === expected ? "✅ PASS" : "❌ FAIL"; |
| 6 | + console.log( |
| 7 | + `${status} | Word: "${word}" | Abbr: "${abbr}" → Expected: ${expected}, Got: ${result}`, |
| 8 | + ); |
| 9 | +} |
| 10 | + |
| 11 | +// === Basic valid cases === |
| 12 | +test("internationalization", "i18n", true); |
| 13 | +test("substitution", "s10n", true); |
| 14 | +test("hello", "4o", true); // skip "e", "l", "l", "o" |
| 15 | +test("abcde", "4e", true); // skip "b", "c", "d", arrive at "e" |
| 16 | + |
| 17 | +// === Literal-only match === |
| 18 | +test("dog", "dog", true); |
| 19 | +test("cat", "cut", false); // mismatch at "a" vs "u" |
| 20 | + |
| 21 | +// === Skip everything === |
| 22 | +test("abcdef", "6", true); // skip entire word |
| 23 | +test("abcdef", "7", false); // skip past word length |
| 24 | +test("abcdef", "5g", true); // skip to last letter and match |
| 25 | + |
| 26 | +// === Mixed skip + literal === |
| 27 | +test("compression", "c9n", true); |
| 28 | +test("transformation", "t12n", true); |
| 29 | +test("transformation", "t13n", false); // too much skip |
| 30 | + |
| 31 | +// === Zero padding (invalid) === |
| 32 | +test("test", "01st", false); |
| 33 | +test("skiptest", "s00t", false); |
| 34 | + |
| 35 | +// === Leading and trailing skips === |
| 36 | +test("abcdef", "1bcdef", false); // can't skip and expect literal 'b' immediately |
| 37 | +test("abcdef", "a5", true); // literal 'a', skip 5 to end |
| 38 | +test("abcdef", "a6", false); // skip past end |
| 39 | + |
| 40 | +// === Multiple number segments === |
| 41 | +test("abcdefg", "1b1d1f1g", true); // skips then matches |
| 42 | +test("abcdefg", "1b2e1g", true); |
| 43 | +test("abcdefg", "1b3f1g", false); // overshoots |
| 44 | + |
| 45 | +// === Full numeric — skips entire word |
| 46 | +test("skipped", "7", true); |
| 47 | +test("skipped", "8", false); // overshoot |
| 48 | + |
| 49 | +// === Empty abbreviation or word === |
| 50 | +test("word", "", false); // must match full |
| 51 | +test("", "", true); // both empty is valid |
| 52 | +test("", "1", false); // can't skip into empty |
| 53 | +test("nonempty", "", false); // abbreviation is empty |
| 54 | + |
| 55 | +// === Misc edge junk === |
| 56 | +test("abc", "a01c", false); // invalid leading 0 |
| 57 | +test("abc", "a0b", false); // zero is illegal |
| 58 | +test("abc", "a1b", true); // skip one |
0 commit comments