// What the phone says, swept as text: one spelling of a day, no path through a // Settings screen that is gone, no locale written in place. These once lived in // CottonUITests (DateWordsSweepTests.swift, NoSettingsPathInWordsTests.swift, // DictationLocaleGuardTests.swift) and only ever read Swift as text — ported to // vitest. The describe blocks keep the Swift suites' names. import { describe, expect, it } from "vitest"; import { matches, swiftSources, withoutComments } from "./helpers/swift-source-sweep"; // R7: one date-and-time formatter. The surfaces and the faces spell a day or a // clock only through `DateFormats` (Format/DateFormats.swift) — never a // formatter of their own, never the device's locale, never a word like "Today" // or "2 days ago" written in place. describe("DateWordsSweepTests", () => { // RULE: No date or time is formatted outside the shared formatter in Surfaces and Faces — no DateFormatter, FormatStyle or pattern of their own and no "Today", "Yesterday", "All day" or "ago" written in place — so every day and clock the person reads is DateFormats' one spelling. it("surfaces and faces spell days only through the shared formatter", () => { const patterns = [ String.raw`\bDateFormatter\(`, String.raw`\bDateComponentsFormatter\b`, String.raw`\bRelativeDateTimeFormatter\b`, String.raw`\bDate\.FormatStyle\b`, String.raw`\.formatted\(\s*(date:|\.dateTime|Date\.)`, String.raw`\bCottonDate\.(?:formatter|string)\(`, String.raw`\bdateFormat\s*=`, String.raw`"(Today|Tomorrow|Yesterday|All day)"`, String.raw`\b(days?|hours?|minutes?) ago"`, String.raw`"In \\\(`, String.raw`d ago"`, ]; const offenders: string[] = []; for (const { name, text } of swiftSources()) { if (!name.startsWith("CottonUI/Surfaces/") && !name.startsWith("CottonUI/Faces/")) continue; const code = withoutComments(text); for (const pattern of patterns) for (const hit of matches(pattern, code)) offenders.push(`${name}: ${hit}`); } expect(offenders, "a day or a clock spelled outside DateFormats").toEqual([]); }); }); // Spec 10 (a): there is no Settings screen on the phone, so no sentence the app // says may send a person to one. describe("NoSettingsPathInWordsTests", () => { // RULE: No string the app says names a path through Settings ("Settings → …"); a setting lives on the database, device or About page. it("no sentence names a path through Settings", () => { const offenders = swiftSources() .filter((file) => withoutComments(file.text).includes("Settings →")) .map((file) => file.name); expect(offenders, 'these say "Settings →" — point at the page instead').toEqual([]); }); }); describe("DictationLocaleGuardTests", () => { // RULE: no locale literal under Capture/ — dictation listens in the person's language (their setting) with the device's region, so a hard-coded locale (the old "en-IN") hears everyone else with the wrong model. it("no locale literal under Capture", () => { const sources = swiftSources().filter((file) => file.name.startsWith("CottonUI/Capture/")); expect(sources.length, "no sources under CottonUI/Capture — did the folder move?").toBeGreaterThan(0); const literal = String.raw`Locale\s*\(\s*identifier\s*:\s*"|Locale\s*\(\s*languageCode\s*:\s*"|"[a-z]{2,3}[-_][A-Z]{2}"`; const offenders = sources.filter(({ text }) => matches(literal, withoutComments(text)).length > 0).map(({ name }) => name); expect(offenders, "these name a locale in a literal; dictation's locale is DictationHints.locale").toEqual([]); }); });