Files
NeitzelFXDesigner/designer-kit-ui/src/test/java/de/neitzel/fxdesigner/kit/FxmlDiagnosticsTest.java
T
konrad 8a4f456e38 Publish shared FXML diagnostics and integrate IntelliJ Problems
Navigate authoritative FXML locations, withdraw stale results and preserve host Undo/Redo. Include editor ownership in native problem identity so equal diagnostics from separate owners survive independent cleanup. Qualify both hosts automatically.
2026-11-13 16:52:50 +01:00

84 lines
3.4 KiB
Java

package de.neitzel.fxdesigner.kit;
import static org.junit.jupiter.api.Assertions.*;
import de.neitzel.fxdesigner.contracts.DocumentSnapshot;
import de.neitzel.fxdesigner.protocol.BindingMetadata.Problem;
import java.net.URI;
import java.util.List;
import org.junit.jupiter.api.Test;
class FxmlDiagnosticsTest {
private DocumentSnapshot source(String xml) {
return new DocumentSnapshot(URI.create("file:/View.fxml"), 3, xml, true, true);
}
private static final String XML =
"<?import de.neitzel.fx.view.*?><VBox xmlns:fx='http://javafx.com/fxml/1'>\n"
+ "<fx:define><BindingList><!-- untouched --><DirectBinding control='field'"
+ " property='text' path='missing' direction='view'/><Repeat pane='rows'"
+ " collection='items' component='app.Row'/></BindingList></fx:define>\n"
+ "<Label fx:id='field'/><VBox fx:id='rows'/><Table fx:id='table' collection='items'"
+ " row='app.Row'><columns><Column header='N'"
+ " attribute='name'/></columns></Table></VBox>";
@Test
void locatesBindingsRepeatAndTableWithoutProjectionIdentities() {
var d = source(XML);
var result =
FxmlDiagnostics.target(
d,
List.of(
new Problem("field", "text", "ERROR", "bad path"),
new Problem("rows", "children", "WARNING", "unknown"),
new Problem("table", "columns", "ERROR", "bad column")));
assertEquals(
List.of(XML.indexOf("<DirectBinding"), XML.indexOf("<Repeat"), XML.indexOf("<Table")),
result.stream().map(p -> p.location().orElseThrow().offset()).toList());
assertTrue(
result.stream().allMatch(p -> p.location().orElseThrow().document().equals(d.document())));
}
@Test
void ambiguousTargetsIdentifyEveryDeclarationAndDeduplicateEvidence() {
String xml =
XML.replace(
"<!-- untouched -->",
"<ComputedBinding control='field' property='text' method='#value'/>");
var p = new Problem("field", "text", "ERROR", "duplicate");
var result = FxmlDiagnostics.target(source(xml), List.of(p, p));
assertEquals(2, result.size());
assertEquals(
xml.indexOf("<ComputedBinding"), result.getFirst().location().orElseThrow().offset());
}
@Test
void unknownOriginsFallBackToRootAndNestedTargetsAreLocated() {
String xml =
XML.replace(
"control='field' property='text' path='missing' direction='view'/>",
"path='missing'"
+ " direction='view'><control>field</control><property>text</property></DirectBinding>");
var result =
FxmlDiagnostics.target(
source(xml),
List.of(
new Problem("field", "text", "ERROR", "bad"),
new Problem("", "", "WARNING", "context unavailable")));
assertEquals(
xml.indexOf("<DirectBinding"), result.getFirst().location().orElseThrow().offset());
assertEquals(xml.indexOf("<VBox"), result.getLast().location().orElseThrow().offset());
}
@Test
void structuralErrorsAndMalformedXmlRemainNavigable() {
assertFalse(
FxmlDiagnostics.local(source(XML.replace("direction='view'", "direction='wrong'")))
.isEmpty());
var malformed = FxmlDiagnostics.local(source("<VBox>\n<Label>\n</VBox>"));
assertEquals(1, malformed.size());
assertTrue(malformed.getFirst().location().orElseThrow().offset() > 0);
assertTrue(FxmlDiagnostics.local(source(XML)).isEmpty());
}
}