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 =
"\n"
+ "\n"
+ "";
@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(" p.location().orElseThrow().offset()).toList());
assertTrue(
result.stream().allMatch(p -> p.location().orElseThrow().document().equals(d.document())));
}
@Test
void ambiguousTargetsIdentifyEveryDeclarationAndDeduplicateEvidence() {
String xml =
XML.replace(
"",
"");
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("",
"path='missing'"
+ " direction='view'>fieldtext");
var result =
FxmlDiagnostics.target(
source(xml),
List.of(
new Problem("field", "text", "ERROR", "bad"),
new Problem("", "", "WARNING", "context unavailable")));
assertEquals(
xml.indexOf("\n