Files
inkwell/tests/test_grammar_fixture.py
T
bvandeusenandClaude Opus 5.5 4285026cfe The repeat rules are pinned by the shared fixture
daily/weekly/monthly/yearly was written out in the server (REMINDER_RECURRENCES),
the core (recur::RECURRENCES), the web editor's <option>s and Android's picker,
with nothing holding them together. grammar.json now has a recurrences list; the
server, core and web suites each check theirs against it, and the web's options
come from notes/recurrence.ts rather than the template. Android's picker pins the
list by hand with its localised labels, as it does the tint: its JVM tests do not
read the fixture.

DRY pass #2, batch 3 (#5372).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 14:28:22 -04:00

55 lines
2.0 KiB
Python

"""The server's half of the shared grammar fixture (core/testdata/grammar.json).
The same cases run against the core (derive.rs) and the web (markdown.ts). A case
that passes in one language and fails in another is a note that changes shape when
it syncs — a checklist that stops being one, or a tag that is a label on the phone
and plain text on the server.
"""
from __future__ import annotations
import json
from pathlib import Path
import pytest
from inkwell.notes.checklist import parse_items, render_item
from inkwell.notes.helpers import derive_display_title
from inkwell.notes.recurrence import REMINDER_RECURRENCES
from inkwell.notes.tags import parse_tags, split_body_tags
FIXTURE = json.loads(
(Path(__file__).resolve().parents[1] / "core" / "testdata" / "grammar.json").read_text(encoding="utf-8")
)
@pytest.mark.parametrize("case", FIXTURE["task_lines"], ids=lambda c: repr(c["line"]))
def test_task_lines(case):
got = [(i.text, i.checked) for i in parse_items(case["line"])]
want = [] if case["item"] is None else [(case["item"]["text"], case["item"]["checked"])]
assert got == want
@pytest.mark.parametrize("case", FIXTURE["rendered_items"], ids=lambda c: repr(c["line"]))
def test_rendered_items(case):
assert render_item(case["text"], case["checked"]) == case["line"]
@pytest.mark.parametrize("case", FIXTURE["tags"], ids=lambda c: repr(c["body"]))
def test_tags(case):
assert parse_tags(case["body"]) == case["tags"]
@pytest.mark.parametrize("case", FIXTURE["lifts"], ids=lambda c: repr(c["body"]))
def test_lifts(case):
standalone, inline, lifted = split_body_tags(case["body"])
assert (standalone, inline, lifted) == (case["standalone"], case["inline"], case["lifted"])
@pytest.mark.parametrize("case", FIXTURE["display_titles"], ids=lambda c: repr(c["body"][:40]))
def test_display_titles(case):
assert derive_display_title(case["body"]) == case["title"]
def test_recurrences():
assert REMINDER_RECURRENCES == set(FIXTURE["recurrences"])