-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: Handle UXML root tag without namespace (#23)
* added tests and different serialization option * changelog update * example update * remove comment
- Loading branch information
Showing
26 changed files
with
243 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
// ----------------------- | ||
// script auto-generated | ||
// any changes to this file will be lost on next code generation | ||
// com.quickeye.ui-toolkit-plus ver: 2.0.0 | ||
// com.quickeye.ui-toolkit-plus ver: 3.0.3 | ||
// ----------------------- | ||
using UnityEngine.UIElements; | ||
|
||
namespace SampleAsmDefName | ||
{ | ||
partial class CodeGenExample | ||
{ | ||
private Label _title; | ||
private VisualElement _menu; | ||
private Button _confirmButton; | ||
private QuickEye.UIToolkit.Tab _normalTab; | ||
private QuickEye.UIToolkit.TabGroup _dropTab; | ||
private Label title; | ||
private VisualElement menu; | ||
private Button confirmButton; | ||
private QuickEye.UIToolkit.Tab normalTab; | ||
private QuickEye.UIToolkit.TabGroup dropTab; | ||
|
||
protected void AssignQueryResults(VisualElement root) | ||
{ | ||
_title = root.Q<Label>("title"); | ||
_menu = root.Q<VisualElement>("menu"); | ||
_confirmButton = root.Q<Button>("confirm-button"); | ||
_normalTab = root.Q<QuickEye.UIToolkit.Tab>("normal-tab"); | ||
_dropTab = root.Q<QuickEye.UIToolkit.TabGroup>("drop--tab"); | ||
title = root.Q<Label>("title"); | ||
menu = root.Q<VisualElement>("menu"); | ||
confirmButton = root.Q<Button>("confirm-button"); | ||
normalTab = root.Q<QuickEye.UIToolkit.Tab>("normal-tab"); | ||
dropTab = root.Q<QuickEye.UIToolkit.TabGroup>("drop--tab"); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Packages/com.quickeye.ui-toolkit-plus/Editor/QuickEye.UxmlBridgeGen/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly:InternalsVisibleTo("QuickEye.UIToolkit.Editor.Tests")] |
3 changes: 3 additions & 0 deletions
3
Packages/com.quickeye.ui-toolkit-plus/Editor/QuickEye.UxmlBridgeGen/AssemblyInfo.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
Packages/com.quickeye.ui-toolkit-plus/Tests/Editor/InlineSettingsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Xml.Linq; | ||
using NUnit.Framework; | ||
using QuickEye.UxmlBridgeGen; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.UIElements; | ||
|
||
namespace QuickEye.UIToolkit.Tests | ||
{ | ||
public class InlineSettingsTests | ||
{ | ||
const string ResourcesDir = "uxml-bridge-tests/"; | ||
|
||
static readonly Dictionary<UxmlFileType, string> UxmlContents = new Dictionary<UxmlFileType, string>() | ||
{ | ||
{ UxmlFileType.Default, LoadUxml("Default") }, | ||
{ UxmlFileType.NoRootNamespace, LoadUxml("NoRootNamespace") }, | ||
{ UxmlFileType.WithCustomSettings, LoadUxml("WithCustomSettings") } | ||
}; | ||
|
||
static readonly InlineSettings CustomSettings = new InlineSettings() | ||
{ | ||
CsNamespace = "test.test", | ||
GenCsGuid = "guid", | ||
PrivateFieldPrefix = "pf-prefix", | ||
PrivateFieldSuffix = "pf-suffix", | ||
PrivateFieldStyle = CaseStyle.LowerCamelCase.ToString(), | ||
ClassPrefix = "c-prefix", | ||
ClassSuffix = "c-suffix", | ||
ClassStyle = CaseStyle.UpperCamelCase.ToString(), | ||
}; | ||
|
||
[TestCase(UxmlFileType.Default, false)] | ||
[TestCase(UxmlFileType.NoRootNamespace, false)] | ||
[TestCase(UxmlFileType.WithCustomSettings, true)] | ||
public void Deserialize_Settings(UxmlFileType fileType, bool hasCustomSettings) | ||
{ | ||
var uxml = UxmlContents[fileType]; | ||
|
||
var settings = InlineSettings.FromXml(uxml); | ||
|
||
Assert.IsNotNull(settings); | ||
if (hasCustomSettings) | ||
{ | ||
AssertAreSettingsEqual(CustomSettings, settings); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Serialize_Settings() | ||
{ | ||
var uxml = UxmlContents[UxmlFileType.Default]; | ||
var root = XDocument.Parse(uxml).Root; | ||
var settings = InlineSettings.FromXml(uxml); | ||
|
||
AssertAreSettingsEqual(new InlineSettings(), settings); | ||
CustomSettings.AddTo(root); | ||
settings = InlineSettings.FromXml(root.ToString()); | ||
AssertAreSettingsEqual(CustomSettings, settings); | ||
} | ||
|
||
private void AssertAreSettingsEqual(InlineSettings expected, InlineSettings actual) | ||
{ | ||
var json = JsonUtility.ToJson(actual); | ||
var expectedJson = JsonUtility.ToJson(expected); | ||
Assert.AreEqual(expectedJson, json); | ||
} | ||
|
||
private static string LoadUxml(string fileName) | ||
{ | ||
var asset = Resources.Load<VisualTreeAsset>(ResourcesDir + fileName); | ||
var path = AssetDatabase.GetAssetPath(asset); | ||
return File.ReadAllText(path); | ||
} | ||
|
||
public enum UxmlFileType | ||
{ | ||
Default, | ||
NoRootNamespace, | ||
WithCustomSettings | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Packages/com.quickeye.ui-toolkit-plus/Tests/Editor/InlineSettingsTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Packages/com.quickeye.ui-toolkit-plus/Tests/Editor/Resources.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.