Several shapes made v1.0.x import a smaller tree than the file held, with no warning at all: - a loose bookmark before the wrapper list (no </DT>) swallowed the whole list; with an explicit </DT> the bookmark "consumed" the next list; - an unescaped <b> in one title re-opened around every later entry (dt > b > a, dl > b > dt) and hid them from a direct-children walk; - a root list wrapped in <div>/<table> was invisible; - PERSONAL_TOOLBAR_FOLDER="false" made a folder the bar. Every reader now classifies addresses before anything is written (core/ href.ts): blank -> MISSING_URL, unparseable -> INVALID_URL (chrome.bookmarks. create rejects those mid-write, after a Replace has already cleared the tree), Firefox place: -> PLACE_QUERIES_SKIPPED in browser-written formats (kept in BM JSON and CSV, our restore formats). A DT that still yields nothing is counted as UNREADABLE_ENTRIES instead of vanishing. Also: - empty titles stay empty (the URL fallback ruined favicon-only bars); - the HTML node cap is counted on the raw text before DOMParser builds a DOM; the depth cap no longer rejects an empty list one level past it; - root markers for Other and Mobile (UNFILED_/MOBILE_BOOKMARKS_FOLDER in HTML, "root" in BM JSON, version stays 1), and a 1.0.x full-tree backup is recognised by shape and marked on read; - BM JSON dates go through the shared normalizer; url "" (which Chrome makes a folder) is skipped; - CSV: an unclosed quote is CSV_UNCLOSED_QUOTE with its line instead of one cell eating the file; formula cells get one reversible guard quote; sep= lines and padding rows are skipped; folder lookup is a Map, not a scan; - Markdown escapes every CommonMark-active character and collapses line breaks in titles (raw HTML used to pass through); - shared WarningBag/NodeBudget/title rule, an iterative walkTree, an isBookmark type guard, a CSV dialect module, chromeTimeToSeconds and microsToSeconds for the JSON formats that follow; - locales split warnings/errors into <lang>-notices.ts to stay under the size limit; every warning and error code must have a message (test). Four new fixtures, golden serializer suites for HTML and BM JSON (docs/11 named one; neither existed), and docs/02, 04, 05, 07, 09, 11, 15 updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
24 lines
798 B
TypeScript
24 lines
798 B
TypeScript
import { expect } from 'vitest';
|
|
import { BmParseError, type BmParseErrorCode } from '@/lib/core/model';
|
|
|
|
/**
|
|
* Assert that `run` throws a `BmParseError` with exactly this code.
|
|
*
|
|
* Replaces the try/catch/`(err as BmParseError)` blocks the suites used to
|
|
* repeat — and makes checking the CODE the default, which a bare
|
|
* `toThrow(BmParseError)` silently skipped (docs/11 §3).
|
|
*/
|
|
export function expectBmError(run: () => unknown, code: BmParseErrorCode): BmParseError {
|
|
let caught: unknown;
|
|
try {
|
|
run();
|
|
} catch (err) {
|
|
caught = err;
|
|
}
|
|
expect(caught, `expected a BmParseError ${code}`).toBeInstanceOf(BmParseError);
|
|
// SAFETY: the assertion above has just established the type.
|
|
const error = caught as BmParseError;
|
|
expect(error.code).toBe(code);
|
|
return error;
|
|
}
|