Skip to content

Commit

Permalink
Fixed the single-letter alias within a path bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sinairv committed Feb 9, 2014
1 parent 327e0fb commit 20b3085
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[2.13] February 10, 2014
* Fixed a bug and added unit tests related to serializing path like aliases with one
letter (e.g., './B'). Thanks go to CodeProject user B.O.B. for reporting this bug.


[2.12] February 19, 2013
* Added support for serialization of non-collection fields
in objects derived from collection types/interfaces
Expand Down
41 changes: 41 additions & 0 deletions YAXLib.2013.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YAXLibTests", "YAXLibTests\YAXLibTests.csproj", "{4F012F71-C259-481B-A112-EC24D3AF24AC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YAXLib", "YAXLib\YAXLib.csproj", "{F1C4D174-C948-4D18-A125-F6855EF55683}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoApplication", "DemoApplication\DemoApplication.csproj", "{40A6C570-2CC0-44BF-8A2A-FD41CE598C41}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{5E379F4E-63A0-49D7-B60E-22B4EC98E92A}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
.nuget\NuGet.exe = .nuget\NuGet.exe
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4F012F71-C259-481B-A112-EC24D3AF24AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F012F71-C259-481B-A112-EC24D3AF24AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F012F71-C259-481B-A112-EC24D3AF24AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F012F71-C259-481B-A112-EC24D3AF24AC}.Release|Any CPU.Build.0 = Release|Any CPU
{F1C4D174-C948-4D18-A125-F6855EF55683}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F1C4D174-C948-4D18-A125-F6855EF55683}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1C4D174-C948-4D18-A125-F6855EF55683}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1C4D174-C948-4D18-A125-F6855EF55683}.Release|Any CPU.Build.0 = Release|Any CPU
{40A6C570-2CC0-44BF-8A2A-FD41CE598C41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40A6C570-2CC0-44BF-8A2A-FD41CE598C41}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40A6C570-2CC0-44BF-8A2A-FD41CE598C41}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40A6C570-2CC0-44BF-8A2A-FD41CE598C41}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion YAXLib/StringUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public static IEnumerable<string> SplitPathNamespaceSafe(this string value)
else continue;
}

if (lastStart < temp.Length - 1)
if (lastStart <= temp.Length - 1)
yield return temp.Substring(lastStart);
}

Expand Down
9 changes: 8 additions & 1 deletion YAXLibTests/DeserializationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,20 @@ public void DeserializingADictionaryDerivedInstance()

string input = ser.Serialize(inst);

DictionarySample deserializedInstance = (DictionarySample)ser.Deserialize(input);
var deserializedInstance = (DictionarySample)ser.Deserialize(input);

Assert.That(deserializedInstance, Is.Not.Null);
Assert.IsTrue(deserializedInstance.Count == inst.Count,
"Expected Count: {0}. Actual Count: {1}",
inst.Count,
deserializedInstance.Count);
}

[Test]
public void DeserializingOneLetterAliases()
{
object obj = OneLetterAlias.GetSampleInstance();
PerformTest(obj);
}
}
}
32 changes: 32 additions & 0 deletions YAXLibTests/SampleClasses/OneLetterAlias.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YAXLib;

namespace YAXLibTests.SampleClasses
{
[ShowInDemoApplication(SortKey = "_")]
public class OneLetterAlias
{
[YAXValueFor("./T")]
public string Title { get; set; }

[YAXValueFor("./A")]
public string Author { get; set; }

public override string ToString()
{
return GeneralToStringProvider.GeneralToString(this);
}

public static OneLetterAlias GetSampleInstance()
{
return new OneLetterAlias
{
Title = "Inside C#",
Author = "Tom Archer & Andrew Whitechapel",
};
}
}
}
15 changes: 15 additions & 0 deletions YAXLibTests/SerializationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1768,5 +1768,20 @@ public void ListOfPolymorphicObjectsTest()
</samples>";
Assert.AreEqual(expectedResult, result);
}

[Test]
public void OneLetterPathTest()
{
var ser = new YAXSerializer(typeof (OneLetterAlias));
string result = ser.Serialize(OneLetterAlias.GetSampleInstance());

const string expectedResult =
@"<OneLetterAlias>
<T>Inside C#</T>
<A>Tom Archer &amp; Andrew Whitechapel</A>
</OneLetterAlias>";

Assert.AreEqual(expectedResult, result);
}
}
}
1 change: 1 addition & 0 deletions YAXLibTests/YAXLibTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="SampleClasses\DataSetAndDataTableKnownTypeSample.cs" />
<Compile Include="SampleClasses\DictionaryWithExtraPropertiesAttributedAsNotCollection.cs" />
<Compile Include="SampleClasses\DictionaryWithExtraProperties.cs" />
<Compile Include="SampleClasses\OneLetterAlias.cs" />
<Compile Include="SampleClasses\PolymorphicSampleList.cs" />
<Compile Include="SampleClasses\RectangleDynamicKnownTypeSample.cs" />
<Compile Include="SampleClasses\YAXLibMetadataOverriding.cs" />
Expand Down

0 comments on commit 20b3085

Please sign in to comment.