-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
228 additions
and
7 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
|
||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace DecTest | ||
{ | ||
[TestFixture] | ||
public class Path : Base | ||
{ | ||
private class PathTester : Dec.IRecordable | ||
{ | ||
public static int validations = 0; | ||
public string text; | ||
|
||
public void Record(Dec.Recorder recorder) | ||
{ | ||
recorder.RecordAsThis(ref text); | ||
|
||
Assert.AreEqual(text, recorder.Context.PathString()); | ||
++validations; | ||
} | ||
} | ||
|
||
private class PathDec : Dec.Dec | ||
{ | ||
public PathTester member; | ||
public PathTester[] array; | ||
public PathTester[,] arrayMulti; | ||
public List<PathTester> list; | ||
public Dictionary<PathTester, string> dictKey; | ||
public Dictionary<string, PathTester> dictValue; | ||
public HashSet<PathTester> set; | ||
} | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
UpdateTestParameters(new Dec.Config.UnitTestParameters { explicitTypes = new Type[] { typeof(PathDec) } }); | ||
PathTester.validations = 0; | ||
} | ||
|
||
[Test] | ||
public void MemberPath() | ||
{ | ||
var parser = new Dec.Parser(); | ||
parser.AddString(Dec.Parser.FileType.Xml, @" | ||
<Decs> | ||
<PathDec decName=""TestDec""> | ||
<member>PathDec.TestDec.member</member> | ||
</PathDec> | ||
</Decs>"); | ||
parser.Finish(); | ||
|
||
Assert.IsTrue(PathTester.validations == 1); | ||
} | ||
|
||
[Test] | ||
public void ArrayPath() | ||
{ | ||
var parser = new Dec.Parser(); | ||
parser.AddString(Dec.Parser.FileType.Xml, @" | ||
<Decs> | ||
<PathDec decName=""TestDec""> | ||
<array> | ||
<li>PathDec.TestDec.array[0]</li> | ||
<li>PathDec.TestDec.array[1]</li> | ||
</array> | ||
</PathDec> | ||
</Decs>"); | ||
parser.Finish(); | ||
|
||
Assert.IsTrue(PathTester.validations == 2); | ||
} | ||
|
||
[Test] | ||
public void MultiDimensionalArrayPath() | ||
{ | ||
var parser = new Dec.Parser(); | ||
parser.AddString(Dec.Parser.FileType.Xml, @" | ||
<Decs> | ||
<PathDec decName=""TestDec""> | ||
<arrayMulti> | ||
<li> | ||
<li>PathDec.TestDec.arrayMulti[0,0]</li> | ||
<li>PathDec.TestDec.arrayMulti[0,1]</li> | ||
</li> | ||
<li> | ||
<li>PathDec.TestDec.arrayMulti[1,0]</li> | ||
<li>PathDec.TestDec.arrayMulti[1,1]</li> | ||
</li> | ||
</arrayMulti> | ||
</PathDec> | ||
</Decs>"); | ||
parser.Finish(); | ||
|
||
Assert.IsTrue(PathTester.validations == 4); | ||
} | ||
|
||
[Test] | ||
public void ListPath() | ||
{ | ||
var parser = new Dec.Parser(); | ||
parser.AddString(Dec.Parser.FileType.Xml, @" | ||
<Decs> | ||
<PathDec decName=""TestDec""> | ||
<list> | ||
<li>PathDec.TestDec.list[0]</li> | ||
<li>PathDec.TestDec.list[1]</li> | ||
</list> | ||
</PathDec> | ||
</Decs>"); | ||
parser.Finish(); | ||
|
||
Assert.IsTrue(PathTester.validations == 2); | ||
} | ||
|
||
[Test] | ||
public void DictionaryKeyPath() | ||
{ | ||
var parser = new Dec.Parser(); | ||
parser.AddString(Dec.Parser.FileType.Xml, @" | ||
<Decs> | ||
<PathDec decName=""TestDec""> | ||
<dictKey> | ||
<li> | ||
<key>PathDec.TestDec.dictKey[KEY]</key> | ||
<value>sure</value> | ||
</li> | ||
</dictKey> | ||
</PathDec> | ||
</Decs>"); | ||
parser.Finish(); | ||
|
||
Assert.IsTrue(PathTester.validations == 1); | ||
} | ||
|
||
[Test] | ||
public void DictionaryValuePath() | ||
{ | ||
var parser = new Dec.Parser(); | ||
parser.AddString(Dec.Parser.FileType.Xml, @" | ||
<Decs> | ||
<PathDec decName=""TestDec""> | ||
<dictValue> | ||
<li> | ||
<key>first</key> | ||
<value>PathDec.TestDec.dictValue[nyi]</value> | ||
</li> | ||
</dictValue> | ||
</PathDec> | ||
</Decs>"); | ||
parser.Finish(); | ||
|
||
Assert.IsTrue(PathTester.validations == 1); | ||
} | ||
|
||
[Test] | ||
public void HashSetPath() | ||
{ | ||
var parser = new Dec.Parser(); | ||
parser.AddString(Dec.Parser.FileType.Xml, @" | ||
<Decs> | ||
<PathDec decName=""TestDec""> | ||
<set> | ||
<li>PathDec.TestDec.set[KEY]</li> | ||
</set> | ||
</PathDec> | ||
</Decs>"); | ||
parser.Finish(); | ||
|
||
Assert.IsTrue(PathTester.validations == 1); | ||
} | ||
|
||
// nyi due to needing a write step | ||
/* | ||
[Test] | ||
public void Record() | ||
{ | ||
var initialData = new PathTester { text = "RECORD" }; | ||
string serialized = Dec.Recorder.Write(initialData); | ||
var deserialized = Dec.Recorder.Read<PathTester>(serialized); | ||
Assert.IsNotNull(deserialized); | ||
Assert.AreEqual(2, PathTester.validations); // Once for write, once for read | ||
} | ||
[Test] | ||
public void RecordRef() | ||
{ | ||
var initialData = new PathTester { text = "RECORD" }; | ||
string serialized = Dec.Recorder.Write((initialData, initialData)); | ||
var deserialized = Dec.Recorder.Read<(PathTester, PathTester)>(serialized); | ||
Assert.IsNotNull(deserialized); | ||
Assert.AreEqual(2, PathTester.validations); // Once for write, once for read | ||
} | ||
[Test] | ||
public void Simple() | ||
{ | ||
var initialData = new PathTester { text = "SimplePath" }; | ||
string serialized = Dec.Recorder.WriteSimple(initialData, "SimplePath"); | ||
var deserialized = Dec.Recorder.ReadSimple<PathTester>(serialized, "SimplePath"); | ||
Assert.IsNotNull(deserialized); | ||
Assert.AreEqual(2, PathTester.validations); // Once for write, once for read | ||
}*/ | ||
} | ||
} |