Skip to content

Commit

Permalink
fix text qualifier bug. add test project.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancole committed May 25, 2017
1 parent 612419a commit ad42a3a
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 11 deletions.
74 changes: 74 additions & 0 deletions DelimitedFileTools.Test/DelimitedFileTools.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{01379FD4-322F-4ABD-A107-B965CDAC5CD3}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DelimitedFileTools.Test</RootNamespace>
<AssemblyName>DelimitedFileTools.Test</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Tests\DelimitedFileRowTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DelimitedFileTools\DelimitedFileTools.csproj">
<Project>{71343400-f293-438d-b77c-85a8abfae115}</Project>
<Name>DelimitedFileTools</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.targets')" />
</Project>
20 changes: 20 additions & 0 deletions DelimitedFileTools.Test/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("DelimitedFileTools.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DelimitedFileTools.Test")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]

[assembly: Guid("01379fd4-322f-4abd-a107-b965cdac5cd3")]

// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
25 changes: 25 additions & 0 deletions DelimitedFileTools.Test/Tests/DelimitedFileRowTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.IO;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DelimitedFileTools.Models;

namespace DelimitedFileTools.Test
{
[TestClass]
public class DelimitedFileRowTests
{
private readonly byte[] m_line = Encoding.UTF8.GetBytes("111,222,\"text\",\"more text\",333,\"last text\"");

[TestMethod]
public void ProperlyHandlesTextQualifiers()
{
using (var stream = new MemoryStream(m_line))
using (var reader = new StreamReader(stream))
{
var row = new DelimitedFileRow(reader, '\n', '\r', '"', ',');

Assert.IsTrue(row.Columns.Count == 6);
}
}
}
}
5 changes: 5 additions & 0 deletions DelimitedFileTools.Test/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MSTest.TestAdapter" version="1.1.11" targetFramework="net452" />
<package id="MSTest.TestFramework" version="1.1.11" targetFramework="net452" />
</packages>
14 changes: 14 additions & 0 deletions DelimitedFileTools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.26430.4
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DelimitedFileTools", "DelimitedFileTools\DelimitedFileTools.csproj", "{71343400-F293-438D-B77C-85A8ABFAE115}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DelimitedFileTools.Test", "DelimitedFileTools.Test\DelimitedFileTools.Test.csproj", "{01379FD4-322F-4ABD-A107-B965CDAC5CD3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -25,6 +27,18 @@ Global
{71343400-F293-438D-B77C-85A8ABFAE115}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{71343400-F293-438D-B77C-85A8ABFAE115}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{71343400-F293-438D-B77C-85A8ABFAE115}.Release|x86.ActiveCfg = Release|Any CPU
{01379FD4-322F-4ABD-A107-B965CDAC5CD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{01379FD4-322F-4ABD-A107-B965CDAC5CD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01379FD4-322F-4ABD-A107-B965CDAC5CD3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{01379FD4-322F-4ABD-A107-B965CDAC5CD3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{01379FD4-322F-4ABD-A107-B965CDAC5CD3}.Debug|x86.ActiveCfg = Debug|Any CPU
{01379FD4-322F-4ABD-A107-B965CDAC5CD3}.Debug|x86.Build.0 = Debug|Any CPU
{01379FD4-322F-4ABD-A107-B965CDAC5CD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01379FD4-322F-4ABD-A107-B965CDAC5CD3}.Release|Any CPU.Build.0 = Release|Any CPU
{01379FD4-322F-4ABD-A107-B965CDAC5CD3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{01379FD4-322F-4ABD-A107-B965CDAC5CD3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{01379FD4-322F-4ABD-A107-B965CDAC5CD3}.Release|x86.ActiveCfg = Release|Any CPU
{01379FD4-322F-4ABD-A107-B965CDAC5CD3}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
22 changes: 11 additions & 11 deletions DelimitedFileTools/Models/DelimitedFileRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@ public DelimitedFileRow(StreamReader p_reader, int p_newline, int p_carriage, in
continue;
}

// we're currently looking at a text qualifier, while being inside a text qualified column, and the next character
// appears to be the end of the file. so, lets add this column value.
else if (isInsideTextQualifiers == true && nextCharacter == -1)
{
m_columns.Add(columnPayload);
break;
}

// we're currently looking at a text qualifier value. if we are already inside of a text qualifier column, we may need
// to exit the text qualifier state. column values may also contain text qualifier characters inside of the actual
// column value, so we need to confirm that we're able to exit the text qualifier column by inspecting the next value.
else if (isInsideTextQualifiers == true && (nextCharacter == m_carriage || nextCharacter == m_newline || nextCharacter == -1))
else if (isInsideTextQualifiers == true && (nextCharacter == m_columnDelimiter || nextCharacter == m_carriage || nextCharacter == m_newline))
{
if (nextCharacter == -1)
{
m_columns.Add(columnPayload);
break;
}
else
{
isInsideTextQualifiers = false;
continue;
}
isInsideTextQualifiers = false;
continue;
}

// if we're looking at a text qualifier value, but we're also inside of a text qualifier column, and it does not appear
Expand Down

0 comments on commit ad42a3a

Please sign in to comment.