0.3.0: ricerca nel testo, caselle di spunta toccabili, tag
- Ricerca nel testo: la cartella viene percorsa ricorsivamente e le note .md scaricate una alla volta (il WebDAV non cerca nel contenuto), con avanzamento, possibilità di fermare e il passaggio che contiene la parola. La ricerca per titolo nella lista resta istantanea. - Caselle di spunta: "- [ ]" e "- [x]" diventano caselle toccabili nell'anteprima; il tocco riscrive quella sola riga e salva subito, e l'editor segue (senza, uscendo riscriverebbe la versione vecchia sul server). - Tag: front-matter (tags: [a, b], lista a trattini o separata da virgole) e #tag nel testo; pastiglie in cima all'anteprima, #tag toccabili, nuova schermata Tag con il conteggio per tag. Il blocco front-matter non viene più stampato come testo. - tests/qml_contract_check.py: confronta i nomi JS e le proprietà usati dalla QML con i sorgenti, le pagine raggiungibili e i parametri dei gestori dei segnali — la classe di errori che la compilazione non vede. - Catalogo italiano aggiornato (25 stringhe nuove); repo ripulito dai residui di build e .gitignore esteso.
This commit is contained in:
1 parent
aab29c76cb
commit
8259297a27
15 files changed
+1280
-64
No files matched your search
@@ -0,0 +1,142 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Controllo statico della QML prima della build.
|
||||
|
||||
Perche' esiste: un nome sbagliato in QML non fa fallire la compilazione. Si vede
|
||||
solo sul telefono, come un pulsante che non fa niente o una pagina che non si
|
||||
apre. Qui si confronta quello che la QML usa con quello che i sorgenti
|
||||
dichiarano, in pochi millisecondi:
|
||||
|
||||
1. ogni `Markdown.<nome>(...)` esiste in qml/components/Markdown.js;
|
||||
2. ogni `dav.<nome>(...)` / `appSettings.<nome>` esiste in DavClient/settings;
|
||||
3. ogni `Qt.resolvedUrl("X.qml")` punta a un file che esiste;
|
||||
4. ogni `on<Segnale>:` di un `Connections { target: dav }` corrisponde a un
|
||||
segnale dichiarato in DavClient.qml (un gestore scritto male non da' errore,
|
||||
semplicemente non viene mai chiamato);
|
||||
5. i parametri usati nei gestori dei segnali di scansione sono quelli
|
||||
dichiarati (parametro sbagliato = ReferenceError solo a runtime).
|
||||
|
||||
Uso: python3 tests/qml_contract_check.py
|
||||
Esce 1 se trova qualcosa, 0 se e' pulito.
|
||||
"""
|
||||
|
||||
import pathlib
|
||||
import re
|
||||
import sys
|
||||
|
||||
APP = pathlib.Path(__file__).resolve().parent.parent
|
||||
problemi = []
|
||||
|
||||
|
||||
def qml_files():
|
||||
return sorted(APP.glob("qml/**/*.qml"))
|
||||
|
||||
|
||||
def js_functions(path):
|
||||
"""Nomi delle funzioni top-level di un modulo JS esportato alla QML."""
|
||||
testo = path.read_text()
|
||||
return set(re.findall(r"^function\s+(\w+)\s*\(", testo, re.M))
|
||||
|
||||
|
||||
def qml_functions(path):
|
||||
return set(re.findall(r"^\s*function\s+(\w+)\s*\(", path.read_text(), re.M))
|
||||
|
||||
|
||||
def controlla_markdown():
|
||||
disponibili = js_functions(APP / "qml/components/Markdown.js")
|
||||
for f in qml_files():
|
||||
for nome in set(re.findall(r"\bMarkdown\.(\w+)\s*\(", f.read_text())):
|
||||
if nome not in disponibili:
|
||||
problemi.append(f"{f.name}: Markdown.{nome}() non esiste in Markdown.js")
|
||||
|
||||
|
||||
def controlla_dav():
|
||||
sorgente = APP / "qml/components/DavClient.qml"
|
||||
dichiarati = qml_functions(sorgente)
|
||||
# Un segnale si emette come una funzione: e' legittimo chiamarlo.
|
||||
dichiarati |= set(re.findall(r"signal\s+(\w+)", sorgente.read_text()))
|
||||
proprieta = set(re.findall(r"^\s*(?:readonly\s+)?property\s+\w+\s+(\w+)",
|
||||
sorgente.read_text(), re.M))
|
||||
for f in qml_files():
|
||||
if f == sorgente:
|
||||
continue # dentro il client le chiamate sono emissioni dei suoi segnali
|
||||
testo = f.read_text()
|
||||
for nome in set(re.findall(r"\bdav\.(\w+)\s*\(", testo)):
|
||||
if nome not in dichiarati:
|
||||
problemi.append(f"{f.name}: dav.{nome}() non esiste in DavClient.qml")
|
||||
for nome in set(re.findall(r"\bdav\.(\w+)\b(?!\s*\()", testo)):
|
||||
if nome not in proprieta and nome not in dichiarati and nome not in ("scanning",):
|
||||
problemi.append(f"{f.name}: dav.{nome} non e' una proprieta' di DavClient.qml")
|
||||
|
||||
|
||||
def controlla_settings():
|
||||
h = APP / "src/settings.h"
|
||||
if not h.exists():
|
||||
return
|
||||
nomi = set(re.findall(r"Q_PROPERTY\(\s*[\w:*<>]+\s+(\w+)", h.read_text()))
|
||||
for f in qml_files():
|
||||
for nome in set(re.findall(r"\bappSettings\.(\w+)", f.read_text())):
|
||||
if nome not in nomi:
|
||||
problemi.append(f"{f.name}: appSettings.{nome} non dichiarato in src/settings.h")
|
||||
|
||||
|
||||
def controlla_url():
|
||||
for f in qml_files():
|
||||
for url in re.findall(r'Qt\.resolvedUrl\("([^"]+)"\)', f.read_text()):
|
||||
if not (f.parent / url).resolve().exists():
|
||||
problemi.append(f"{f.name}: Qt.resolvedUrl(\"{url}\") non esiste")
|
||||
|
||||
|
||||
def controlla_segnali():
|
||||
dav = (APP / "qml/components/DavClient.qml").read_text()
|
||||
segnali = {}
|
||||
for nome, params in re.findall(r"signal\s+(\w+)\s*\(([^)]*)\)", dav):
|
||||
segnali[nome] = [p.strip().split()[-1] for p in params.split(",") if p.strip()]
|
||||
for f in qml_files():
|
||||
testo = f.read_text()
|
||||
for blocco in re.findall(r"Connections\s*\{(.*?)\n \}", testo, re.S):
|
||||
if "target: dav" not in blocco and "target: page.dav" not in blocco:
|
||||
continue
|
||||
for gestore in re.findall(r"\bon([A-Z]\w*)\s*:", blocco):
|
||||
nome = gestore[0].lower() + gestore[1:]
|
||||
if nome not in segnali:
|
||||
problemi.append(f"{f.name}: on{gestore} non corrisponde a un segnale di DavClient.qml")
|
||||
continue
|
||||
corpo = blocco.split("on" + gestore + ":", 1)[1]
|
||||
# Il corpo finisce al gestore successivo o alla chiusura.
|
||||
corpo = re.split(r"\n\s*on[A-Z]\w*\s*:", corpo)[0]
|
||||
for p in segnali[nome]:
|
||||
# Un parametro dichiarato ma mai usato va bene; quello che
|
||||
# conta e' che i nomi usati come variabili siano dichiarati.
|
||||
if re.search(r"\b" + re.escape(p) + r"\b", corpo):
|
||||
continue
|
||||
# Se il gestore usa `message`, `content`, `path` e simili
|
||||
# ma il segnale non li dichiara, e' un errore.
|
||||
usati = set(re.findall(r"\b(message|content|path|entries|count|done|errs|all)\b", corpo))
|
||||
falsi = usati - set(segnali[nome])
|
||||
for u in sorted(falsi):
|
||||
problemi.append(f"{f.name}: on{gestore} usa '{u}', che il segnale non dichiara "
|
||||
f"({', '.join(segnali[nome]) or 'nessun parametro'})")
|
||||
|
||||
|
||||
def main():
|
||||
if not qml_files():
|
||||
print("nessun file QML trovato", file=sys.stderr)
|
||||
return 1
|
||||
controlla_markdown()
|
||||
controlla_dav()
|
||||
controlla_settings()
|
||||
controlla_url()
|
||||
controlla_segnali()
|
||||
|
||||
print(f"file QML controllati: {len(qml_files())}")
|
||||
if problemi:
|
||||
for p in problemi:
|
||||
print("PROBLEMA:", p)
|
||||
print(f"ESITO: {len(problemi)} problemi")
|
||||
return 1
|
||||
print("ESITO: nessun problema di contratto fra QML, JS e C++")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -112,6 +112,128 @@ assert(img3.indexOf("<i>[image: x]</i>") >= 0, "default label 'image'");
|
||||
|
||||
console.log("Markdown tests: OK");
|
||||
|
||||
// ── front matter ─────────────────────────────────────────────────────────
|
||||
var fm1 = Markdown.frontMatterInfo("---\ntitle: Nota\ntags: [uno, due]\n---\n\n# Titolo\n");
|
||||
console.log("── front matter ── " + JSON.stringify(fm1));
|
||||
assert.strictEqual(fm1.present, true, "front matter detected");
|
||||
assert.strictEqual(fm1.bodyStart, 4, "body starts after the closing dashes");
|
||||
assert.deepStrictEqual(fm1.tags, ["uno", "due"], "inline list tags: " + fm1.tags);
|
||||
assert.strictEqual(fm1.fields.title, "Nota", "scalar field");
|
||||
|
||||
var fm2 = Markdown.frontMatterInfo("---\ntags:\n - alfa\n - beta\n---\ntesto");
|
||||
assert.deepStrictEqual(fm2.tags, ["alfa", "beta"], "block list tags: " + fm2.tags);
|
||||
|
||||
var fm3 = Markdown.frontMatterInfo("---\ntags: uno, due\n---\ntesto");
|
||||
assert.deepStrictEqual(fm3.tags, ["uno", "due"], "comma separated tags");
|
||||
|
||||
// unterminated block is NOT front matter: the dashes stay text
|
||||
var fm4 = Markdown.frontMatterInfo("---\ntitle: x\n\nTesto\n");
|
||||
assert.strictEqual(fm4.present, false, "unterminated block ignored");
|
||||
assert.strictEqual(fm4.bodyStart, 0, "body starts at 0");
|
||||
|
||||
// a document with no front matter at all
|
||||
var fm5 = Markdown.frontMatterInfo("# Solo titolo\n");
|
||||
assert.strictEqual(fm5.present, false, "no front matter");
|
||||
assert.deepStrictEqual(fm5.tags, [], "no tags");
|
||||
|
||||
// the block must not be rendered as body text
|
||||
var rfm = Markdown.render("---\ntitle: Nota\ntags: [x]\n---\n\n# Titolo\n");
|
||||
assert(rfm.indexOf("title:") < 0 && rfm.indexOf("tags:") < 0, "front matter not rendered: " + rfm);
|
||||
assert(rfm.indexOf("<h1>Titolo</h1>") >= 0, "body rendered after front matter");
|
||||
|
||||
// a leading horizontal rule is not front matter
|
||||
var rfhr = Markdown.render("---\n\nTesto\n");
|
||||
assert(rfhr.indexOf("<hr/>") >= 0 && rfhr.indexOf("<p>Testo</p>") >= 0, "hr still hr: " + rfhr);
|
||||
|
||||
// ── tags ─────────────────────────────────────────────────────────────────
|
||||
var td1 = Markdown.tagDetails("---\ntags: [progetto, idee]\n---\n\nTesto con #inline e #altro/tag\n");
|
||||
assert.deepStrictEqual(td1.frontMatter, ["progetto", "idee"], "front matter tags: " + td1.frontMatter);
|
||||
assert.deepStrictEqual(td1.inline, ["inline", "altro/tag"], "inline tags: " + td1.inline);
|
||||
|
||||
// duplicates (also with different case) collapse
|
||||
var td2 = Markdown.tagDetails("---\ntags: [Idee]\n---\n#idee e #Idee");
|
||||
assert.strictEqual(td2.frontMatter.length + td2.inline.length, 1, "tags deduplicated: " + JSON.stringify(td2));
|
||||
|
||||
// code fences are not scanned for tags; #12 is not a tag
|
||||
var td3 = Markdown.tagDetails("```\n# commento\n```\n#12 e #vero");
|
||||
assert.deepStrictEqual(td3.inline, ["vero"], "fence skipped, number skipped: " + td3.inline);
|
||||
|
||||
// hasTag is case-insensitive and works for both sources
|
||||
assert.strictEqual(Markdown.hasTag("---\ntags: [Progetto]\n---\nx", "progetto"), true, "hasTag front matter");
|
||||
assert.strictEqual(Markdown.hasTag("testo #progetto", "progetto"), true, "hasTag inline");
|
||||
assert.strictEqual(Markdown.hasTag("testo #altro", "progetto"), false, "hasTag miss");
|
||||
|
||||
// tag links in the preview
|
||||
var tg = Markdown.render("Vedi #progetto e #altro/tag");
|
||||
assert(tg.indexOf('<a href="quill-tag://progetto">#progetto</a>') >= 0, "tag link: " + tg);
|
||||
assert(tg.indexOf("quill-tag://altro%2Ftag") >= 0, "tag with slash encoded");
|
||||
// a tag inside a link label must not nest anchors
|
||||
var tg2 = Markdown.render("[testo #progetto](http://e.it)");
|
||||
assert.strictEqual((tg2.match(/<a /g) || []).length, 1, "no nested anchors: " + tg2);
|
||||
// heading markers are not tags
|
||||
var tg3 = Markdown.render("## Titolo");
|
||||
assert(tg3.indexOf("quill-tag") < 0, "heading is not a tag: " + tg3);
|
||||
|
||||
console.log("Front matter + tags tests: OK");
|
||||
|
||||
// ── task lists ───────────────────────────────────────────────────────────
|
||||
var TASKS = "# Lista\n\n- [ ] prima\n- [x] seconda\n- normale\n\n| a | b |\n|---|---|\n| 1 | 2 |";
|
||||
var rt = Markdown.render(TASKS, "", { checkOff: "#111111", checkOn: "#222222" });
|
||||
console.log("── task output ──\n" + rt);
|
||||
assert(rt.indexOf('<a href="quill-check://2"><font color="#111111">\u2610</font></a> prima') >= 0,
|
||||
"unchecked task with source line: " + rt);
|
||||
assert(rt.indexOf('<a href="quill-check://3"><font color="#222222">\u2611</font></a> seconda') >= 0,
|
||||
"checked task with source line");
|
||||
assert(rt.indexOf("<li>normale</li>") >= 0, "plain item untouched");
|
||||
assert(rt.indexOf("\u2610") >= 0 && rt.indexOf("\u2611") >= 0, "checkbox glyphs rendered");
|
||||
|
||||
// the line index survives a front matter block
|
||||
var rtf = Markdown.render("---\ntags: [x]\n---\n- [ ] dopo\n");
|
||||
assert(rtf.indexOf('quill-check://3') >= 0, "line index absolute after front matter: " + rtf);
|
||||
|
||||
// toggling
|
||||
var toggled = Markdown.toggleTask(TASKS, 2);
|
||||
assert(toggled.indexOf("- [x] prima") >= 0, "unchecked -> checked: " + toggled.split("\n")[2]);
|
||||
var toggledBack = Markdown.toggleTask(toggled, 2);
|
||||
assert(toggledBack === TASKS, "round trip gives the original source");
|
||||
var toggledOff = Markdown.toggleTask(TASKS, 3);
|
||||
assert(toggledOff.indexOf("- [ ] seconda") >= 0, "checked -> unchecked");
|
||||
assert.strictEqual(Markdown.toggleTask(TASKS, 4), null, "plain list item is not a task");
|
||||
assert.strictEqual(Markdown.toggleTask(TASKS, 99), null, "line out of range");
|
||||
assert.strictEqual(Markdown.toggleTask("# x", 0), null, "heading is not a task");
|
||||
|
||||
// CRLF files keep their line endings
|
||||
var crlf = "- [ ] a\r\n- [ ] b";
|
||||
var crlfOut = Markdown.toggleTask(crlf, 1);
|
||||
assert(crlfOut.indexOf("\r\n") >= 0 && crlfOut.indexOf("\n\n") < 0, "CRLF preserved: " + JSON.stringify(crlfOut));
|
||||
assert(crlfOut.indexOf("- [x] b") >= 0, "CRLF toggle works");
|
||||
|
||||
// nested indentation is preserved
|
||||
var nested = " - [ ] dentro";
|
||||
assert(Markdown.toggleTask(nested, 0) === " - [x] dentro", "indentation kept");
|
||||
|
||||
console.log("Task list tests: OK");
|
||||
|
||||
// ── text search ──────────────────────────────────────────────────────────
|
||||
var NOTE = "---\ntags: [x]\n---\n\n# Progetto Marte\n\nLa colonia ha bisogno di **acqua** e di un\nreattore. Vedi [[Base]] per i dettagli.\n";
|
||||
var s1 = Markdown.searchText(NOTE, "acquA");
|
||||
console.log("── snippet ── " + (s1 && s1.snippet));
|
||||
assert(s1 !== null, "case-insensitive hit");
|
||||
assert(s1.index > 0, "index reported");
|
||||
assert(s1.snippet.indexOf("acqua") >= 0, "snippet contains the term: " + s1.snippet);
|
||||
assert(s1.snippet.indexOf("\n") < 0, "snippet is one line");
|
||||
assert.strictEqual(Markdown.searchText(NOTE, "inesistente"), null, "miss returns null");
|
||||
assert.strictEqual(Markdown.searchText("", "x"), null, "empty content");
|
||||
assert.strictEqual(Markdown.searchText("abc", ""), null, "empty term");
|
||||
|
||||
// a hit far into the text is prefixed with an ellipsis
|
||||
var longNote = new Array(40).join("riempitivo ") + "AGO";
|
||||
var s2 = Markdown.searchText(longNote, "ago");
|
||||
assert(s2.snippet.indexOf("\u2026") === 0, "ellipsis before a distant hit: " + s2.snippet);
|
||||
assert(s2.snippet.indexOf("AGO") >= 0, "term kept with original case");
|
||||
|
||||
console.log("Search tests: OK");
|
||||
|
||||
// ── PropfindParser ────────────────────────────────────────────────────────
|
||||
var xml = '<?xml version="1.0"?>' +
|
||||
'<d:multistatus xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">' +
|
||||
|
||||
Reference in new issue
Block a user