Finishes testing, cleanup, adds license
This commit is contained in:
@@ -202,8 +202,11 @@ public class DOMFXMLParser implements FXMLParser {
|
||||
final var objects = new ArrayList<ParsedObject>();
|
||||
final var children = node.getChildNodes();
|
||||
for (var i = 0; i < children.getLength(); i++) {
|
||||
if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
|
||||
objects.add(parseObject(children.item(i), imports));
|
||||
final var child = children.item(i);
|
||||
if (child.getNodeType() == Node.ELEMENT_NODE) {
|
||||
objects.add(parseObject(child, imports));
|
||||
} else if (child.getNodeType() == Node.TEXT_NODE && !child.getNodeValue().isBlank()) {
|
||||
objects.add(new ParsedTextImpl(child.getNodeValue().trim()));
|
||||
}
|
||||
}
|
||||
return new ComplexProperty(new ParsedPropertyImpl(sourceTypeName.name(), sourceTypeName.sourceType(), null), objects);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.github.gtache.fxml.compiler.parsing.xml;
|
||||
|
||||
import com.github.gtache.fxml.compiler.parsing.ParseException;
|
||||
import com.github.gtache.fxml.compiler.parsing.impl.*;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.event.EventHandler;
|
||||
@@ -12,14 +13,14 @@ import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SequencedMap;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class TestDOMFXMLParser {
|
||||
|
||||
@@ -74,7 +75,13 @@ class TestDOMFXMLParser {
|
||||
)),
|
||||
new ParsedFactoryImpl(FXCollections.class.getName(), Map.of("fx:id", new ParsedPropertyImpl("fx:id", null, "define6"), "fx:factory", new ParsedPropertyImpl("fx:factory", null, "emptyObservableMap")), List.of(), List.of())))))),
|
||||
new ParsedPropertyImpl("center", null, null),
|
||||
List.of(new ParsedObjectImpl(VBox.class.getName(), newLinkedHashMap("fx:id", new ParsedPropertyImpl("fx:id", null, "vbox")), newLinkedHashMap(), List.of()))
|
||||
List.of(new ParsedObjectImpl(VBox.class.getName(), newLinkedHashMap("fx:id", new ParsedPropertyImpl("fx:id", null, "vbox"), "alignment", new ParsedPropertyImpl("alignment", null, "TOP_RIGHT")),
|
||||
newLinkedHashMap(
|
||||
new ParsedPropertyImpl("accessibleText", null, null), List.of(
|
||||
new ParsedDefineImpl(List.of(
|
||||
new ParsedObjectImpl(String.class.getName(), Map.of("value",
|
||||
new ParsedPropertyImpl("value", null, "3")), newLinkedHashMap(), List.of())
|
||||
)), new ParsedTextImpl("text"))), List.of()))
|
||||
), List.of());
|
||||
try (final var in = getClass().getResourceAsStream("loadView.fxml")) {
|
||||
assertNotNull(in);
|
||||
@@ -84,6 +91,51 @@ class TestDOMFXMLParser {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInvalidDefine() throws IOException {
|
||||
try (final var in = getClass().getResourceAsStream("invalidDefine.fxml")) {
|
||||
assertNotNull(in);
|
||||
final var content = new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
assertThrows(ParseException.class, () -> parser.parse(content));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInvalidFactory() throws IOException {
|
||||
try (final var in = getClass().getResourceAsStream("invalidFactory.fxml")) {
|
||||
assertNotNull(in);
|
||||
final var content = new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
assertThrows(ParseException.class, () -> parser.parse(content));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLoadRoot() throws IOException {
|
||||
try (final var in = getClass().getResourceAsStream("loadRoot.fxml")) {
|
||||
assertNotNull(in);
|
||||
final var content = new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
assertThrows(ParseException.class, () -> parser.parse(content));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLoadScript() throws IOException {
|
||||
try (final var in = getClass().getResourceAsStream("loadScript.fxml")) {
|
||||
assertNotNull(in);
|
||||
final var content = new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
assertThrows(ParseException.class, () -> parser.parse(content));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUnknownClass() throws IOException {
|
||||
try (final var in = getClass().getResourceAsStream("unknownClass.fxml")) {
|
||||
assertNotNull(in);
|
||||
final var content = new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
assertThrows(ParseException.class, () -> parser.parse(content));
|
||||
}
|
||||
}
|
||||
|
||||
private static <K, V> SequencedMap<K, V> newLinkedHashMap() {
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
@@ -100,12 +152,4 @@ class TestDOMFXMLParser {
|
||||
map.put(k2, v2);
|
||||
return map;
|
||||
}
|
||||
|
||||
private static <K, V> SequencedMap<K, V> newLinkedHashMap(final K k1, final V v1, final K k2, final V v2, final K k3, final V v3) {
|
||||
final var map = new LinkedHashMap<K, V>();
|
||||
map.put(k1, v1);
|
||||
map.put(k2, v2);
|
||||
map.put(k3, v3);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<BorderPane xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="com.github.gtache.fxml.compiler.parsing.xml.LoadController">
|
||||
<bottom>
|
||||
<fx:define>
|
||||
<children></children>
|
||||
</fx:define>
|
||||
</bottom>
|
||||
</BorderPane>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.collections.FXCollections?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<BorderPane xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="com.github.gtache.fxml.compiler.parsing.xml.LoadController">
|
||||
<bottom>
|
||||
<fx:define>
|
||||
<FXCollections fx:id="define5" fx:factory="observableArrayList">
|
||||
<children></children>
|
||||
</FXCollections>
|
||||
</fx:define>
|
||||
</bottom>
|
||||
</BorderPane>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<fx:root type="javafx.scene.layout.BorderPane" xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="com.github.gtache.fxml.compiler.parsing.xml.LoadController">
|
||||
</fx:root>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<BorderPane xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="com.github.gtache.fxml.compiler.parsing.xml.LoadController">
|
||||
<fx:script></fx:script>
|
||||
</BorderPane>
|
||||
@@ -60,6 +60,13 @@
|
||||
</bottom>
|
||||
<center>
|
||||
<VBox fx:id="vbox">
|
||||
<alignment>TOP_RIGHT</alignment>
|
||||
<accessibleText>
|
||||
<fx:define>
|
||||
<String value="3"/>
|
||||
</fx:define>
|
||||
text
|
||||
</accessibleText>
|
||||
</VBox>
|
||||
</center>
|
||||
</BorderPane>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<BorderPane xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="com.github.gtache.fxml.compiler.parsing.xml.LoadController">
|
||||
<bottom>
|
||||
</bottom>
|
||||
</BorderPane>
|
||||
Reference in New Issue
Block a user