Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit ef15854

Browse files
committed
Add a few unit tests
1 parent c3dc5cb commit ef15854

18 files changed

+4090
-0
lines changed

Bindings/Assets/Tests.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
2+
<ui:VisualElement name="root">
3+
<ui:Label name="label" text="Hello, World!" />
4+
<ui:Button name="button" text="Click Me" />
5+
<ui:IntegerField name="integerField" />
6+
<ui:TextField name="textField" />
7+
</ui:VisualElement>
8+
</ui:UXML>

Bindings/Assets/Tests/TestUxmlUI.uxml.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Bindings/Assets/Tests/Tests.asmdef

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "Tests",
3+
"rootNamespace": "",
4+
"references": [
5+
"UnityEngine.TestRunner",
6+
"UnityEditor.TestRunner",
7+
"VirtualMaker.Bindings"
8+
],
9+
"includePlatforms": [
10+
"Editor"
11+
],
12+
"excludePlatforms": [],
13+
"allowUnsafeCode": false,
14+
"overrideReferences": true,
15+
"precompiledReferences": [
16+
"nunit.framework.dll"
17+
],
18+
"autoReferenced": false,
19+
"defineConstraints": [
20+
"UNITY_INCLUDE_TESTS"
21+
],
22+
"versionDefines": [],
23+
"noEngineReferences": false
24+
}

Bindings/Assets/Tests/Tests.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Bindings/Assets/Tests/UxmlTests.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using NUnit.Framework;
2+
using UnityEditor;
3+
using UnityEngine.UIElements;
4+
using VirtualMaker.Bindings;
5+
6+
public class UxmlTests
7+
{
8+
private Bindings _bindings;
9+
private Property<int> _intProperty = new();
10+
private Property<string> _stringProperty = new();
11+
private IntegerField _integerField;
12+
private TextField _textField;
13+
14+
[SetUp]
15+
public void SetUp()
16+
{
17+
var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Tests/TestUxmlUI.uxml");
18+
Assert.IsNotNull(visualTree, "VisualTreeAsset should not be null");
19+
20+
var root = new VisualElement();
21+
visualTree.CloneTree(root);
22+
23+
_integerField = root.Q<IntegerField>("integerField");
24+
_textField = root.Q<TextField>("textField");
25+
26+
_bindings = new(root);
27+
}
28+
29+
[TearDown]
30+
public void TearDown()
31+
{
32+
_bindings.Reset();
33+
}
34+
35+
[Test]
36+
public void IntegerFieldTests()
37+
{
38+
_intProperty.Value = 42;
39+
_bindings.BindIntegerField("integerField", _intProperty, true);
40+
Assert.AreEqual(42, _integerField.value);
41+
42+
_intProperty.Value = 100;
43+
Assert.AreEqual(100, _integerField.value);
44+
45+
// Unity bug? Assigning to value doesn't trigger changed event.
46+
// _integerField.value = 200;
47+
// Assert.AreEqual(200, _intProperty.Value);
48+
}
49+
50+
[Test]
51+
public void TextFieldTests()
52+
{
53+
_stringProperty.Value = "Hello";
54+
_bindings.BindTextField("textField", _stringProperty, true);
55+
Assert.AreEqual("Hello", _textField.value);
56+
57+
_stringProperty.Value = "World";
58+
Assert.AreEqual("World", _textField.value);
59+
60+
// Unity bug? Assigning to value doesn't trigger changed event.
61+
// _textField.value = "Hello";
62+
// Assert.AreEqual("Hello", _stringProperty.Value);
63+
}
64+
}

Bindings/Assets/Tests/UxmlTests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema xmlns:editor="UnityEditor.UIElements" xmlns:engine="UnityEngine.UIElements" xmlns="UnityEditor.Overlays" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<xs:import schemaLocation="UnityEngine.UIElements.xsd" namespace="UnityEngine.UIElements" />
4+
<xs:import schemaLocation="UnityEditor.UIElements.xsd" namespace="UnityEditor.UIElements" />
5+
<xs:import schemaLocation="UnityEditor.UIElements.Debugger.xsd" namespace="UnityEditor.UIElements.Debugger" />
6+
<xs:import schemaLocation="Unity.UI.Builder.xsd" namespace="Unity.UI.Builder" />
7+
<xs:import schemaLocation="UnityEditor.Search.xsd" namespace="UnityEditor.Search" />
8+
<xs:import schemaLocation="UnityEditor.Experimental.GraphView.xsd" namespace="UnityEditor.Experimental.GraphView" />
9+
<xs:import schemaLocation="UnityEditor.ShortcutManagement.xsd" namespace="UnityEditor.ShortcutManagement" />
10+
<xs:import schemaLocation="UnityEditor.PackageManager.UI.Internal.xsd" namespace="UnityEditor.PackageManager.UI.Internal" />
11+
<xs:import schemaLocation="Unity.Profiling.Editor.xsd" namespace="Unity.Profiling.Editor" />
12+
<xs:import schemaLocation="UnityEditor.Overlays.xsd" namespace="UnityEditor.Overlays" />
13+
</xs:schema>
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema xmlns:editor="UnityEditor.UIElements" xmlns:engine="UnityEngine.UIElements" xmlns="UnityEditor.Overlays" elementFormDefault="qualified" targetNamespace="Unity.Profiling.Editor" xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<xs:import schemaLocation="UnityEngine.UIElements.xsd" namespace="UnityEngine.UIElements" />
4+
<xs:simpleType name="SelectableLabel_keyboard-type_Type">
5+
<xs:restriction base="xs:string">
6+
<xs:enumeration value="Default" />
7+
<xs:enumeration value="ASCIICapable" />
8+
<xs:enumeration value="NumbersAndPunctuation" />
9+
<xs:enumeration value="URL" />
10+
<xs:enumeration value="NumberPad" />
11+
<xs:enumeration value="PhonePad" />
12+
<xs:enumeration value="NamePhonePad" />
13+
<xs:enumeration value="EmailAddress" />
14+
<xs:enumeration value="NintendoNetworkAccount" />
15+
<xs:enumeration value="Social" />
16+
<xs:enumeration value="Search" />
17+
<xs:enumeration value="DecimalPad" />
18+
<xs:enumeration value="OneTimeCode" />
19+
</xs:restriction>
20+
</xs:simpleType>
21+
<xs:complexType name="SelectableLabelType">
22+
<xs:complexContent mixed="false">
23+
<xs:restriction base="engine:VisualElementType">
24+
<xs:sequence minOccurs="0" maxOccurs="unbounded">
25+
<xs:element ref="engine:VisualElement" />
26+
</xs:sequence>
27+
<xs:attribute default="" name="name" type="xs:string" use="optional" />
28+
<xs:attribute default="" name="view-data-key" type="xs:string" use="optional" />
29+
<xs:attribute default="Position" name="picking-mode" type="engine:VisualElement_picking-mode_Type" use="optional" />
30+
<xs:attribute default="" name="tooltip" type="xs:string" use="optional" />
31+
<xs:attribute default="None" name="usage-hints" type="engine:VisualElement_usage-hints_Type" use="optional" />
32+
<xs:attribute default="0" name="tabindex" type="xs:int" use="optional" />
33+
<xs:attribute default="true" name="focusable" type="xs:boolean" use="optional" />
34+
<xs:attribute default="" name="class" type="xs:string" use="optional" />
35+
<xs:attribute default="" name="content-container" type="xs:string" use="optional" />
36+
<xs:attribute default="" name="style" type="xs:string" use="optional" />
37+
<xs:attribute default="" name="binding-path" type="xs:string" use="optional" />
38+
<xs:attribute default="" name="label" type="xs:string" use="optional" />
39+
<xs:attribute default="" name="value" type="xs:string" use="optional" />
40+
<xs:attribute default="-1" name="max-length" type="xs:int" use="optional" />
41+
<xs:attribute default="false" name="password" type="xs:boolean" use="optional" />
42+
<xs:attribute default="*" name="mask-character" type="xs:string" use="optional" />
43+
<xs:attribute default="false" name="readonly" type="xs:boolean" use="optional" />
44+
<xs:attribute default="false" name="is-delayed" type="xs:boolean" use="optional" />
45+
<xs:attribute default="false" name="hide-mobile-input" type="xs:boolean" use="optional" />
46+
<xs:attribute default="Default" name="keyboard-type" xmlns:q1="Unity.Profiling.Editor" type="q1:SelectableLabel_keyboard-type_Type" use="optional" />
47+
<xs:attribute default="false" name="auto-correction" type="xs:boolean" use="optional" />
48+
<xs:attribute default="false" name="multiline" type="xs:boolean" use="optional" />
49+
<xs:anyAttribute processContents="lax" />
50+
</xs:restriction>
51+
</xs:complexContent>
52+
</xs:complexType>
53+
<xs:element name="SelectableLabel" substitutionGroup="engine:VisualElement" xmlns:q2="Unity.Profiling.Editor" type="q2:SelectableLabelType" />
54+
<xs:complexType name="MemoryUsageBreakdownType">
55+
<xs:complexContent mixed="false">
56+
<xs:restriction base="engine:VisualElementType">
57+
<xs:sequence minOccurs="0" maxOccurs="unbounded">
58+
<xs:element xmlns:q3="Unity.Profiling.Editor" ref="q3:MemoryUsageBreakdownElement" />
59+
</xs:sequence>
60+
<xs:attribute default="" name="name" type="xs:string" use="optional" />
61+
<xs:attribute default="" name="view-data-key" type="xs:string" use="optional" />
62+
<xs:attribute default="Position" name="picking-mode" type="engine:VisualElement_picking-mode_Type" use="optional" />
63+
<xs:attribute default="" name="tooltip" type="xs:string" use="optional" />
64+
<xs:attribute default="None" name="usage-hints" type="engine:VisualElement_usage-hints_Type" use="optional" />
65+
<xs:attribute default="0" name="tabindex" type="xs:int" use="optional" />
66+
<xs:attribute default="false" name="focusable" type="xs:boolean" use="optional" />
67+
<xs:attribute default="" name="class" type="xs:string" use="optional" />
68+
<xs:attribute default="" name="content-container" type="xs:string" use="optional" />
69+
<xs:attribute default="" name="style" type="xs:string" use="optional" />
70+
<xs:attribute default="Memory Usage" name="header-text" type="xs:string" use="optional" />
71+
<xs:attribute default="1288490240" name="total-bytes" type="xs:int" use="optional" />
72+
<xs:attribute default="false" name="show-unknown" type="xs:boolean" use="optional" />
73+
<xs:attribute default="Unknown" name="unknown-name" type="xs:string" use="optional" />
74+
<xs:anyAttribute processContents="lax" />
75+
</xs:restriction>
76+
</xs:complexContent>
77+
</xs:complexType>
78+
<xs:element name="MemoryUsageBreakdown" substitutionGroup="engine:VisualElement" xmlns:q4="Unity.Profiling.Editor" type="q4:MemoryUsageBreakdownType" />
79+
<xs:complexType name="BackgroundPatternType">
80+
<xs:complexContent mixed="false">
81+
<xs:restriction base="engine:VisualElementType">
82+
<xs:attribute default="" name="name" type="xs:string" use="optional" />
83+
<xs:attribute default="" name="view-data-key" type="xs:string" use="optional" />
84+
<xs:attribute default="Position" name="picking-mode" type="engine:VisualElement_picking-mode_Type" use="optional" />
85+
<xs:attribute default="" name="tooltip" type="xs:string" use="optional" />
86+
<xs:attribute default="None" name="usage-hints" type="engine:VisualElement_usage-hints_Type" use="optional" />
87+
<xs:attribute default="0" name="tabindex" type="xs:int" use="optional" />
88+
<xs:attribute default="false" name="focusable" type="xs:boolean" use="optional" />
89+
<xs:attribute default="" name="class" type="xs:string" use="optional" />
90+
<xs:attribute default="" name="content-container" type="xs:string" use="optional" />
91+
<xs:attribute default="" name="style" type="xs:string" use="optional" />
92+
<xs:attribute default="1" name="scale" type="xs:float" use="optional" />
93+
<xs:anyAttribute processContents="lax" />
94+
</xs:restriction>
95+
</xs:complexContent>
96+
</xs:complexType>
97+
<xs:element name="BackgroundPattern" substitutionGroup="engine:VisualElement" xmlns:q5="Unity.Profiling.Editor" type="q5:BackgroundPatternType" />
98+
<xs:complexType name="MemoryUsageBreakdownElementType">
99+
<xs:complexContent mixed="false">
100+
<xs:restriction base="engine:VisualElementType">
101+
<xs:attribute default="" name="name" type="xs:string" use="optional" />
102+
<xs:attribute default="" name="view-data-key" type="xs:string" use="optional" />
103+
<xs:attribute default="Position" name="picking-mode" type="engine:VisualElement_picking-mode_Type" use="optional" />
104+
<xs:attribute default="" name="tooltip" type="xs:string" use="optional" />
105+
<xs:attribute default="None" name="usage-hints" type="engine:VisualElement_usage-hints_Type" use="optional" />
106+
<xs:attribute default="0" name="tabindex" type="xs:int" use="optional" />
107+
<xs:attribute default="false" name="focusable" type="xs:boolean" use="optional" />
108+
<xs:attribute default="" name="class" type="xs:string" use="optional" />
109+
<xs:attribute default="" name="content-container" type="xs:string" use="optional" />
110+
<xs:attribute default="" name="style" type="xs:string" use="optional" />
111+
<xs:attribute default="Other" name="text" type="xs:string" use="optional" />
112+
<xs:attribute default="" name="background-color-class" type="xs:string" use="optional" />
113+
<xs:attribute default="false" name="show-used" type="xs:boolean" use="optional" />
114+
<xs:attribute default="50" name="used-bytes" type="xs:long" use="optional" />
115+
<xs:attribute default="100" name="total-bytes" type="xs:long" use="optional" />
116+
<xs:attribute default="false" name="show-selected" type="xs:boolean" use="optional" />
117+
<xs:attribute default="0" name="selected-bytes" type="xs:long" use="optional" />
118+
<xs:anyAttribute processContents="lax" />
119+
</xs:restriction>
120+
</xs:complexContent>
121+
</xs:complexType>
122+
<xs:element name="MemoryUsageBreakdownElement" substitutionGroup="engine:VisualElement" xmlns:q6="Unity.Profiling.Editor" type="q6:MemoryUsageBreakdownElementType" />
123+
</xs:schema>

0 commit comments

Comments
 (0)