-
Notifications
You must be signed in to change notification settings - Fork 1
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
8 changed files
with
318 additions
and
6 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
137 changes: 137 additions & 0 deletions
137
src/Tests/YamlMap.Tests/Reader/ParseQuotatedTypeStringTests.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,137 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using NUnit.Framework; | ||
|
||
namespace YamlMap.Tests.Reader | ||
{ | ||
[TestFixture] | ||
public class ParseQuotatedTypeStringTests | ||
{ | ||
[Test] | ||
public void ParseQuotatedTypeString_DoubleQuotations() | ||
{ | ||
var lines = new[] | ||
{ | ||
"Value: \"[value] test\"" | ||
}; | ||
|
||
var reader = new YamlReader(); | ||
var parsed = reader.Read(typeof(PrimitiveValues), lines) as PrimitiveValues; | ||
|
||
Assert.AreEqual("[value] test", parsed.Value); | ||
} | ||
|
||
[Test] | ||
public void ParseQuotatedTypeString_SingleQuotations() | ||
{ | ||
var lines = new[] | ||
{ | ||
"Value: '[value] test'" | ||
}; | ||
|
||
var reader = new YamlReader(); | ||
var parsed = reader.Read(typeof(PrimitiveValues), lines) as PrimitiveValues; | ||
|
||
Assert.AreEqual("[value] test", parsed.Value); | ||
} | ||
|
||
[Test] | ||
public void ParseQuotatedTypeString_DoubleQuotations_InnerSingle() | ||
{ | ||
var lines = new[] | ||
{ | ||
"Value: \"[value] 'test\"" | ||
}; | ||
|
||
var reader = new YamlReader(); | ||
var parsed = reader.Read(typeof(PrimitiveValues), lines) as PrimitiveValues; | ||
|
||
Assert.AreEqual("[value] 'test", parsed.Value); | ||
} | ||
|
||
[Test] | ||
public void ParseQuotatedTypeString_SingleQuotations_InnerDouble() | ||
{ | ||
var lines = new[] | ||
{ | ||
"Value: '[value] \"test'" | ||
}; | ||
|
||
var reader = new YamlReader(); | ||
var parsed = reader.Read(typeof(PrimitiveValues), lines) as PrimitiveValues; | ||
|
||
Assert.AreEqual("[value] \"test", parsed.Value); | ||
} | ||
|
||
[Test] | ||
public void ParseQuotatedTypeString_DoubleQuotations_NoEnd() | ||
{ | ||
var lines = new[] | ||
{ | ||
"Value: \"[value] test" | ||
}; | ||
|
||
var reader = new YamlReader(); | ||
Assert.Throws<InvalidConfigurationException>(() => reader.Read(typeof(PrimitiveValues), lines)); | ||
} | ||
|
||
[Test] | ||
public void ParseQuotatedTypeString_SingleQuotations_NoEnd() | ||
{ | ||
var lines = new[] | ||
{ | ||
"Value: '[value] test" | ||
}; | ||
|
||
var reader = new YamlReader(); | ||
Assert.Throws<InvalidConfigurationException>(() => reader.Read(typeof(PrimitiveValues), lines)); | ||
} | ||
|
||
[Test] | ||
public void ParseQuotatedTypeString_DoubleQuotations_EndInString() | ||
{ | ||
var lines = new[] | ||
{ | ||
"Value: \"[value] t\"est" | ||
}; | ||
|
||
var reader = new YamlReader(); | ||
Assert.Throws<InvalidConfigurationException>(() => reader.Read(typeof(PrimitiveValues), lines)); | ||
} | ||
|
||
[Test] | ||
public void ParseQuotatedTypeString_SingleQuotations_EndInString() | ||
{ | ||
var lines = new[] | ||
{ | ||
"Value: '[value] t'est" | ||
}; | ||
|
||
var reader = new YamlReader(); | ||
Assert.Throws<InvalidConfigurationException>(() => reader.Read(typeof(PrimitiveValues), lines)); | ||
} | ||
|
||
|
||
[Test] | ||
public void ParseQuotatedTypeString_DoubleQuotations_Special() | ||
{ | ||
var lines = new[] | ||
{ | ||
"Value: \"c: is a drive\"" | ||
}; | ||
|
||
var reader = new YamlReader(); | ||
var parsed = reader.Read(typeof(PrimitiveValues), lines) as PrimitiveValues; | ||
|
||
Assert.AreEqual("c: is a drive", parsed.Value); | ||
} | ||
|
||
public class PrimitiveValues | ||
{ | ||
public string Value { get; set; } | ||
|
||
public List<string> ValueList { get; set; } | ||
} | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
src/Tests/YamlMap.Tests/Reader/YamlReaderDictionaryTypeTests.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,104 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using NUnit.Framework; | ||
|
||
namespace YamlMap.Tests.Reader | ||
{ | ||
[TestFixture] | ||
public class YamlReaderDictionaryTypeTests | ||
{ | ||
[Test] | ||
public void YamlReaderDictionaryType_Dictionary() | ||
{ | ||
var lines = new[] | ||
{ | ||
"Dictionary:", | ||
" Name: one", | ||
" Id: 1" | ||
}; | ||
|
||
var reader = new YamlReader(); | ||
var data = reader.Read(typeof(StringNode), lines) as StringNode; | ||
|
||
Assert.That(data.Dictionary.Count() == 2); | ||
Assert.That(data.Dictionary["Name"] == "one"); | ||
Assert.That(data.Dictionary["Id"] == "1"); | ||
} | ||
|
||
[Test] | ||
public void YamlReaderDictionaryType_Dictionary_Interface() | ||
{ | ||
var lines = new[] | ||
{ | ||
"IDictionary:", | ||
" Name: one", | ||
" Id: 1" | ||
}; | ||
|
||
var reader = new YamlReader(); | ||
var data = reader.Read(typeof(StringNode), lines) as StringNode; | ||
|
||
Assert.That(data.IDictionary.Count() == 2); | ||
Assert.That(data.IDictionary["Name"] == "one"); | ||
Assert.That(data.IDictionary["Id"] == "1"); | ||
} | ||
|
||
[Test] | ||
public void YamlReaderDictionaryType_Dictionary_List() | ||
{ | ||
// this is a list of object instead of a dictionary | ||
// to use dictionary remove the - | ||
var lines = new[] | ||
{ | ||
"Dictionary:", | ||
" - Name: one", | ||
" - Id: 1" | ||
}; | ||
|
||
var reader = new YamlReader(); | ||
Assert.Throws<InvalidConfigurationException>(() => reader.Read(typeof(StringNode), lines)); | ||
} | ||
|
||
[Test] | ||
public void YamlReaderDictionaryType_Dictionary_Objects() | ||
{ | ||
var lines = new[] | ||
{ | ||
"ObjectDictionary:", | ||
" one:", | ||
" Id: 1", | ||
" Name: test one", | ||
" two:", | ||
" Id: 2", | ||
" Name: test two" | ||
}; | ||
|
||
var reader = new YamlReader(); | ||
var data = reader.Read(typeof(StringNode), lines) as StringNode; | ||
|
||
Assert.That(data.ObjectDictionary.Count() == 2); | ||
Assert.That(data.ObjectDictionary["one"].Id == 1); | ||
Assert.That(data.ObjectDictionary["one"].Name == "test one"); | ||
Assert.That(data.ObjectDictionary["two"].Id == 2); | ||
Assert.That(data.ObjectDictionary["two"].Name == "test two"); | ||
} | ||
|
||
public class StringNode | ||
{ | ||
public Dictionary<string, string> Dictionary { get; set; } | ||
|
||
public IDictionary<string, string> IDictionary { get; set; } | ||
|
||
public Dictionary<string, DictObject> ObjectDictionary { get; set; } | ||
} | ||
|
||
public class DictObject | ||
{ | ||
public int Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
} | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
...p.Tests/Serialization/_Snapshots/DeserializerTests_Serializer_Deserialize_ByType.snapshot
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,19 @@ | ||
---data | ||
Child: | ||
ObjList: | ||
Child: | ||
ObjList: | ||
Simple: simple | ||
StringList: | ||
Child: | ||
Child: | ||
ObjList: | ||
Simple: child | ||
StringList: | ||
ObjList: | ||
Simple: null | ||
StringList: | ||
Simple: root | ||
StringList: | ||
one | ||
2 |
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