Files
scrabble-game/ui/src/lib/alphabet.test.ts
T
Ilia Denisov 8881214213 R6(a): de-stage code, docs, READMEs; split stage6_test
Mechanical, behaviour-preserving removal of Stage N / TODO-N / phase (RN)
references from comments, doc-comments, service READMEs, the current-state docs
(ARCHITECTURE, FUNCTIONAL+_ru, TESTING, UI_DESIGN), config-file comments, and the
.fbs/.proto schema comments. PLAN.md / PRERELEASE.md / CLAUDE.md keep the stage
history.

- Rename the only stage-named identifiers: registerStage8 -> registerSocialOps,
  registerStage11 -> registerLinkOps (gateway transcode).
- Split stage6_test.go: TestEmailLoginFlow -> email_test.go,
  TestGuestAutoMatchLeavesNoStats (+ provisionGuest) -> account_test.go.
- Regenerated proto bindings (push.pb.go, telegram_grpc.pb.go) from the de-staged
  .proto comments; FB Go/TS bindings unchanged (flatc strips schema comments).

go build/vet/gofmt clean across modules; integration typecheck and pnpm check green.
2026-06-10 16:56:03 +02:00

49 lines
1.9 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
alphabetLetters,
BLANK_INDEX,
hasAlphabet,
indexForLetter,
letterForIndex,
setAlphabet,
valueForLetter,
} from './alphabet';
// The cache module is per-file-isolated by vitest, so only what these tests seed exists.
describe('alphabet cache', () => {
it('upper-cases letters for display and maps indices and values case-insensitively', () => {
setAlphabet('scrabble_en', [
{ index: 0, letter: 'a', value: 1 },
{ index: 16, letter: 'q', value: 10 },
]);
expect(hasAlphabet('scrabble_en')).toBe(true);
expect(letterForIndex('scrabble_en', 0)).toBe('A');
expect(letterForIndex('scrabble_en', 16)).toBe('Q');
expect(indexForLetter('scrabble_en', 'a')).toBe(0);
expect(indexForLetter('scrabble_en', 'Q')).toBe(16);
expect(valueForLetter('scrabble_en', 'a')).toBe(1);
expect(valueForLetter('scrabble_en', 'Q')).toBe(10);
});
it('handles the blank sentinel and unknown letters/indices', () => {
setAlphabet('scrabble_en', [{ index: 0, letter: 'a', value: 1 }]);
expect(letterForIndex('scrabble_en', BLANK_INDEX)).toBe('?');
expect(indexForLetter('scrabble_en', '?')).toBe(BLANK_INDEX);
expect(valueForLetter('scrabble_en', '?')).toBe(0);
expect(letterForIndex('scrabble_en', 99)).toBe(''); // out of range
expect(valueForLetter('scrabble_en', 'Z')).toBe(0); // not in this alphabet
expect(() => indexForLetter('scrabble_en', 'Z')).toThrow();
});
it('lists the alphabet for the blank chooser and is empty for an uncached variant', () => {
setAlphabet('scrabble_en', [
{ index: 0, letter: 'a', value: 1 },
{ index: 1, letter: 'b', value: 3 },
]);
expect(alphabetLetters('scrabble_en')).toEqual(['A', 'B']);
expect(hasAlphabet('erudit_ru')).toBe(false);
expect(alphabetLetters('erudit_ru')).toEqual([]);
expect(valueForLetter('erudit_ru', 'A')).toBe(0);
});
});