mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-15 01:12:05 +07:00
116 lines
3.3 KiB
C#
116 lines
3.3 KiB
C#
using UnityEngine;
|
|
using NUnit.Framework;
|
|
using System.Collections.Generic;
|
|
|
|
namespace IsoTools.Tiled.Internal {
|
|
public class TiledMapPropertiesTests {
|
|
|
|
[Test]
|
|
public void Test00() {
|
|
var props = new TiledMapProperties(null);
|
|
Assert.AreEqual(props.Count, 0);
|
|
Assert.False(props.Has(""));
|
|
Assert.False(props.Has(string.Empty));
|
|
Assert.False(props.Has("prop1"));
|
|
}
|
|
|
|
[Test]
|
|
public void Test01() {
|
|
var prop_list = new List<string>{
|
|
"prop1", "val1",
|
|
"prop2", "val2",
|
|
"prop3", "val3",
|
|
"fakep"
|
|
};
|
|
var props = new TiledMapProperties(prop_list);
|
|
Assert.AreEqual(props.Count, 3);
|
|
|
|
Assert.True(props.Has("prop1"));
|
|
Assert.True(props.Has("prop2"));
|
|
Assert.True(props.Has("prop3"));
|
|
|
|
Assert.False(props.Has(""));
|
|
Assert.False(props.Has("val2"));
|
|
Assert.False(props.Has("prop4"));
|
|
Assert.False(props.Has(string.Empty));
|
|
}
|
|
|
|
[Test]
|
|
public void Test02() {
|
|
var props = new TiledMapProperties(null);
|
|
Assert.Throws<UnityException>(() => { props.GetAsBool (""); });
|
|
Assert.Throws<UnityException>(() => { props.GetAsShort (""); });
|
|
Assert.Throws<UnityException>(() => { props.GetAsInt (""); });
|
|
Assert.Throws<UnityException>(() => { props.GetAsLong (""); });
|
|
Assert.Throws<UnityException>(() => { props.GetAsFloat (""); });
|
|
Assert.Throws<UnityException>(() => { props.GetAsDouble(""); });
|
|
Assert.Throws<UnityException>(() => { props.GetAsString(""); });
|
|
}
|
|
|
|
[Test]
|
|
public void Test03() {
|
|
var props = new TiledMapProperties(null);
|
|
bool v0;
|
|
short v1;
|
|
int v2;
|
|
long v3;
|
|
float v4;
|
|
double v5;
|
|
string v6;
|
|
Assert.False(props.TryGetAsBool ("", out v0));
|
|
Assert.False(props.TryGetAsShort ("", out v1));
|
|
Assert.False(props.TryGetAsInt ("", out v2));
|
|
Assert.False(props.TryGetAsLong ("", out v3));
|
|
Assert.False(props.TryGetAsFloat ("", out v4));
|
|
Assert.False(props.TryGetAsDouble("", out v5));
|
|
Assert.False(props.TryGetAsString("", out v6));
|
|
}
|
|
|
|
[Test]
|
|
public void Test04() {
|
|
var prop_list = new List<string>{
|
|
"bool" , "true",
|
|
"short" , "64",
|
|
"int" , "128",
|
|
"long" , "1024",
|
|
"float" , "1.2",
|
|
"double", "1.23",
|
|
"string", "hello"
|
|
};
|
|
var props = new TiledMapProperties(prop_list);
|
|
|
|
bool v0;
|
|
short v1;
|
|
int v2;
|
|
long v3;
|
|
float v4;
|
|
double v5;
|
|
string v6;
|
|
|
|
Assert.True(props.TryGetAsBool ("bool" , out v0));
|
|
Assert.True(props.TryGetAsShort ("short" , out v1));
|
|
Assert.True(props.TryGetAsInt ("int" , out v2));
|
|
Assert.True(props.TryGetAsLong ("long" , out v3));
|
|
Assert.True(props.TryGetAsFloat ("float" , out v4));
|
|
Assert.True(props.TryGetAsDouble("double", out v5));
|
|
Assert.True(props.TryGetAsString("string", out v6));
|
|
|
|
Assert.AreEqual(v0, true);
|
|
Assert.AreEqual(v1, 64);
|
|
Assert.AreEqual(v2, 128);
|
|
Assert.AreEqual(v3, 1024);
|
|
Assert.AreEqual(v4, 1.2f);
|
|
Assert.AreEqual(v5, 1.23);
|
|
Assert.AreEqual(v6, "hello");
|
|
|
|
Assert.AreEqual(props.GetAsBool ("bool" ), v0);
|
|
Assert.AreEqual(props.GetAsShort ("short" ), v1);
|
|
Assert.AreEqual(props.GetAsInt ("int" ), v2);
|
|
Assert.AreEqual(props.GetAsLong ("long" ), v3);
|
|
Assert.AreEqual(props.GetAsFloat ("float" ), v4);
|
|
Assert.AreEqual(props.GetAsDouble("double"), v5);
|
|
Assert.AreEqual(props.GetAsString("string"), v6);
|
|
}
|
|
}
|
|
} // namespace IsoTools.Tiled.Internal
|