Langage
Examples and rules
Examples are executable specifications run by dsfc test and generated as target tests. Usage rules are checked assertions.
Examples
An example sets up a component, applies inputs and host updates step by step, and states
what must be true.
example "disabled-wins-over-simultaneous-states" {
component = component.Button
props = {
label = "OK"
disabled = true
}
variants = {
appearance = "primary"
}
states = {
hovered = true
pressed = true
focus_visible = true
}
expect {
node "root" {
background = token.color.disabled
foreground = token.color.on-disabled
}
}
}
example "disabled-cannot-activate" {
component = component.Button
props = {
label = "OK"
disabled = true
}
inputs = ["activation", "activation"]
expect {
events = []
}
}
| Field | Meaning |
|---|---|
props, variants, states |
The component’s inputs. Examples may set read-only states. |
context |
Context axes, for example { theme = "dark" }. Every axis can be set, preferences included. |
fill "<slot>" |
Slot content written by the example, as on an instance. |
inputs |
Abstract inputs applied in order. "confirm:activation" sends an input to the confirm instance. |
step "<id>" |
One input (input, node, and its data: key, modifiers, text, source) or one host update (props, context), with an optional expect checked after it. Use either inputs or steps. |
expect |
present and absent node paths, the events since the previous expect (events = [event.x] or event "x" { field = value } blocks), states, node "<path>" { … } values, accessibility ["<path>"] { … } members, focused and geometry assertions. |
example "escape-requests-dismiss-and-host-closes" {
component = component.Dialog
props = {
open = true
title = "Publish now?"
}
step "escape" {
input = "dismiss"
source = "escape"
expect {
present = ["surface"]
event "dismiss" {
reason = "escape"
}
}
}
step "host-closes" {
props = {
open = false
}
}
expect {
absent = ["surface"]
}
}
Instances keep their states from one step to the next while they are present. focused
checks the node that has keyboard focus (null for none): a key step of "Tab" moves it
(modifiers = ["shift"] backward), and key steps without node go to the focused node
(D-049). Keys reach the focused stop only: a keyboard step while nothing has focus fails the
example, so give focus with a focus step first (D-058). A node expectation reads a
present node: on an absent node it fails the example; expect absence with absent. A pointer drag is three steps: drag_start presses a node, drag_change moves with
a translation (dp since the press) or a position (a unit point in the receiving node), and
drag_end releases it, all at the node pressed; an action step performs a named
accessibility action (D-052). Time is frozen: an advance = ms(…) step moves the example’s virtual clock, and
transition "<name>" and presence "<path>" expectations read the phase and eased progress
of what is moving (D-051).
geometry lists Boolean assertions over the reference layout model, which lays the example
out in its available_width × available_height (D-055). layout.<node> has x, y,
width and height in dp, and a text also line_count and truncated; a path with / or
keys is written layout["row[home]/label"]. Text is measured with a documented
approximation, so prefer relations to exact text widths:
example "rtl-puts-the-icon-on-the-right" {
component = component.Status
context = {
direction = "rtl"
}
expect {
geometry = [
layout.icon.x > layout.message.x,
layout.message.line_count >= 1,
]
}
}
Model tests cannot measure layout. The Angular target also runs the examples against its
rendered components in Chromium, where it measures the browser’s layout (D-059); SwiftUI
reports such examples as untranslated (example.geometry), and dsfc test runs them.
Running them
dsfc test fixtures/scenarios/01-button-calculated
test action-bar-forwards-confirm ... ok
test activation-emits-activate ... ok
test disabled-cannot-activate ... ok
test disabled-wins-over-simultaneous-states ... ok
test fill-icon-keeps-its-size ... ok
test minimum-size-is-calculated ... ok
test primary-in-dark-theme ... ok
7 passed, 0 failed, 0 not run
dsfc test runs examples against the reference semantics. A failed expectation is
DSF-E001. An example that uses a construct the evaluator cannot run yet (a step with
modifiers) is reported as not run, never as passed.
Generators turn the same examples into target tests: Swift Testing for SwiftUI, Vitest for Angular (tests of the models, and of the rendered components in Chromium). An example therefore checks the specification and every generated implementation. The documentation target shows each example with its status and a static preview.
Usage rules
A rule is a typed assertion over a declared view tree. It never inspects application data.
rule "single-primary-action" {
scope = "view"
severity = "warning"
assert = count(descendants(component.Button, { appearance = "primary" })) <= 1
message = "Use at most one primary action per view."
}
A violated rule is reported as DSF-U001 with the rule’s severity and message.
Documentation blocks
docs { summary = "…" guidance "do" { text = "…" } guidance "dont" { text = "…" } }
records usage guidance next to the component. It is prose and never executed.