Skip to content

Commit

Permalink
ArrayType에서 text값이 빈값이라면 빈배열을 반환한다.
Browse files Browse the repository at this point in the history
  • Loading branch information
Newp committed Feb 4, 2024
1 parent c53bf7e commit 2b74850
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
42 changes: 31 additions & 11 deletions src/Npgg.Configuration.Tests/ArrayConvertTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,42 @@ public class ArrayConvertTests

string csv = @"Key ,Values ,Tag
1,""1,2,3,4,5"",tag ";
[Fact]
public void StringListTest()
{
[Fact]
public void StringListTest()
{

var list = loader.Load<ArraySample<string>>(csv);
var list = loader.Load<ArraySample<string>>(csv);

Assert.Single(list);
Assert.Single(list);

var item = list.Last();
var item = list.Last();

Assert.Equal(1, item.Key);
Assert.Equal(5, item.Values.Length);
Assert.Equal("tag", item.Tag);
}
Assert.Equal(1, item.Key);
Assert.Equal(5, item.Values.Length);
Assert.Equal("tag", item.Tag);
}

[Fact]

[Fact]
public void EmptyIntArrayTest()
{

string csv = @"Key ,Values ,Tag
1,"""",tag ";
var list = loader.Load<ArraySample<int>>(csv);

Assert.Single(list);

var item = list.Last();

Assert.Equal(1, item.Key);
Assert.Equal(0, item.Values.Length);

Check warning on line 48 in src/Npgg.Configuration.Tests/ArrayConvertTests.cs

View workflow job for this annotation

GitHub Actions / build

Do not use Assert.Equal() to check for collection size. (https://xunit.github.io/xunit.analyzers/rules/xUnit2013)

Check warning on line 48 in src/Npgg.Configuration.Tests/ArrayConvertTests.cs

View workflow job for this annotation

GitHub Actions / build

Do not use Assert.Equal() to check for collection size. (https://xunit.github.io/xunit.analyzers/rules/xUnit2013)
Assert.Equal("tag", item.Tag);
}



[Fact]
public void IntListTest()
{

Expand Down
9 changes: 8 additions & 1 deletion src/Npgg.Configuration/Converters/ArrayCustomConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ public ArrayCustomConverter(Type elementType)

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var splited = value.ToString().Trim('\"').Split(',');
var text = value.ToString();

if(string.IsNullOrWhiteSpace(text))
{
return Array.CreateInstance(this.itemType, 0);
}

var splited = text.Trim('\"').Split(',');

var array = Array.CreateInstance(this.itemType, splited.Length);

Expand Down
2 changes: 1 addition & 1 deletion src/Npgg.Configuration/Npgg.Configuration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Copyright></Copyright>
<Description>Csv,Tsv string to c# object deserializer</Description>
<PackageProjectUrl>https://github.com/Newp/Npgg.Configuration</PackageProjectUrl>
<Version>1.6.2</Version>
<Version>1.6.3</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<RepositoryUrl>https://github.com/Newp/Npgg.Configuration</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down

0 comments on commit 2b74850

Please sign in to comment.