voelin-gpui: the parity test notices a second brush or string in theme.slint

The test compared the brush and string declarations of theme.slint by name
only (one backdrop, one font-family and the mode string), so a second brush or
string token in the Slint file passed unseen while docs/ui.md said a token on
one side only fails the test. It now asserts the brush declarations are
exactly {backdrop} and the strings exactly {mode, font-family}, and a test
adds a brush and a string to a copy of the file (a mutant) and checks both are
named: red with the previous rule ("backdrop-soft goes unnoticed"), green
with this one.

A Rust-only second brush or string is still not seen (tokens.rs has one
gradient and one family that the test cannot enumerate); docs/ui.md says so
instead of promising it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-27 12:29:02 +03:00
1 parent 977b942cd0
commit 5c94b15820
2 files changed
+80 -18

No files matched your search

+74 -16
View File
@@ -2,8 +2,9 @@
//! read and every token in it is compared with the Rust value of the same
//! name, light and dark and at four text sizes; a token on one side only, a
//! value that differs, or a declaration of a kind this test does not know
//! fails it. While both front ends live, a token changed in one place and
//! not the other is caught here.
//! (or a second brush or string, of which it knows `backdrop`, `mode` and
//! `font-family`) fails it. While both front ends live, a token changed in
//! one place and not the other is caught here.
use std::collections::{BTreeMap, BTreeSet};
@@ -14,7 +15,13 @@ const SLINT: &str = include_str!("../../../voelin-ui/ui/theme.slint");
/// What `theme.slint` declares: the kind and the expression of each property
/// of the `Theme` global, in file order.
fn declarations() -> Vec<(String, String, String)> {
let without_comments: String = SLINT
declarations_of(SLINT)
}
/// The same for the text of a `.slint` file (the tests below also read
/// altered copies of `theme.slint`).
fn declarations_of(source: &str) -> Vec<(String, String, String)> {
let without_comments: String = source
.lines()
.map(|line| line.split("//").next().unwrap_or(""))
.collect::<Vec<_>>()
@@ -241,20 +248,71 @@ fn the_backdrop_and_the_font_are_the_same_in_both_files() {
assert_eq!(get("font-family"), format!("\"{FONT_FAMILY}\""));
}
/// What the declarations hold that no comparison above covers, one sentence
/// each; empty when there is none: a kind of declaration this test does not
/// know, a brush other than `backdrop` or a string other than `mode` and
/// `font-family` (the two comparisons of those go by name, so a second one
/// would pass unseen), a state name that is no longer declared.
fn unknown_to_this_test(declared: &[(String, String, String)]) -> Vec<String> {
let mut problems = Vec::new();
let kinds: BTreeSet<&str> = declared
.iter()
.filter(|(name, _, _)| !STATE.contains(&name.as_str()))
.map(|(_, kind, _)| kind.as_str())
.collect();
let known = BTreeSet::from(["color", "brush", "length", "int", "duration", "string"]);
if kinds != known {
problems.push(format!("kinds of declaration {kinds:?}, this test knows {known:?}"));
}
for (kind, expected) in [("brush", &["backdrop"][..]), ("string", &["mode", "font-family"])] {
let found: BTreeSet<&str> = declared
.iter()
.filter(|(_, declared_kind, _)| declared_kind == kind)
.map(|(name, _, _)| name.as_str())
.collect();
let expected: BTreeSet<&str> = expected.iter().copied().collect();
for name in found.symmetric_difference(&expected) {
problems.push(format!(
"{name}: the <{kind}> declarations are {found:?}, this test compares {expected:?}"
));
}
}
for name in STATE {
if !declared.iter().any(|(declared, _, _)| declared == name) {
problems.push(format!("{name} is not declared"));
}
}
problems
}
#[test]
fn the_file_declares_nothing_this_test_does_not_know() {
let kinds: BTreeSet<String> = declarations()
.into_iter()
.filter(|(name, _, _)| !STATE.contains(&name.as_str()))
.map(|(_, kind, _)| kind)
.collect();
let known: BTreeSet<String> = ["color", "brush", "length", "int", "duration", "string"]
.into_iter()
.map(String::from)
.collect();
assert_eq!(kinds, known);
let declared: BTreeSet<String> = declarations().into_iter().map(|(name, _, _)| name).collect();
for name in STATE {
assert!(declared.contains(name), "{name} is declared");
let problems = unknown_to_this_test(&declarations());
assert!(problems.is_empty(), "{problems:#?}");
}
/// `theme.slint` with one more declaration in its `Theme` global.
fn with_declaration(declaration: &str) -> String {
let opening = "export global Theme {";
assert!(SLINT.contains(opening));
SLINT.replacen(opening, &format!("{opening}\n {declaration}"), 1)
}
#[test]
fn a_second_brush_or_string_is_not_passed_unseen() {
// Mutants of the Slint file: a token on one side only.
for (declaration, name) in [
("out property <brush> backdrop-soft: #123456;", "backdrop-soft"),
("out property <string> font-mono: \"Mono\";", "font-mono"),
] {
let mutant = declarations_of(&with_declaration(declaration));
assert!(mutant.iter().any(|(declared, _, _)| declared == name), "the mutant has {name}");
let problems = unknown_to_this_test(&mutant);
assert!(
problems.iter().any(|problem| problem.contains(name)),
"{name} goes unnoticed: {problems:#?}"
);
}
// And the file as it is has neither.
assert_eq!(unknown_to_this_test(&declarations()), Vec::<String>::new());
}
+6 -2
View File
@@ -1094,8 +1094,12 @@ Two layers (docs/design/gpui-spikes.md, "The theme against Theme tokens"):
(the server rail, presence, meters) read it. `theme/slint_parity.rs` reads
`theme.slint` at test time and compares every declaration of its `Theme`
global with `theme/tokens.rs` by name, with the file's own arithmetic, at
four text sizes; a token on one side only, a changed value or a kind of
declaration it does not know fails the test.
four text sizes; a colour, length, weight or duration on one side only, a
changed value or a kind of declaration it does not know fails the test, and
so does a brush other than `backdrop` or a string other than `mode` and
`font-family` in the Slint file (those three it compares by name against
the one gradient and the one family of `tokens.rs`, which it cannot
enumerate: a second brush or string only on the Rust side is not seen).
2. **gpui-component's `ThemeColor`**, which its widgets read, written from the
first on every change (`theme/components.rs`): the registered theme of the
mode first, then the mapped colours over it, the font (Inter, `font-body`),