fix: fix bugs with fragment parsing support, refs: NOISSUE
This commit is contained in:
@@ -15,6 +15,11 @@ public class TextParserTests
|
||||
private const string testInput4 = @"2 ab ba fd er sd
|
||||
8 cd dc
|
||||
7 uh 6 yp rt";
|
||||
private const string testInput5 = @"asdfnums(2,5,3)ght
|
||||
|
||||
cv strs(test) jh 4,3,2
|
||||
|
||||
34,54,2nums(2,8) strs(aa,ab,ba,bb)aa,bb";
|
||||
|
||||
[Fact]
|
||||
public void LineParser_TestSimpleRepetition()
|
||||
@@ -208,46 +213,48 @@ public class TextParserTests
|
||||
.StartOptions()
|
||||
.Option()
|
||||
.Expect("nums(")
|
||||
.Expect(InputType.Integer)
|
||||
.Expect(InputType.Integer, "num")
|
||||
.Repeat()
|
||||
.Expect(",")
|
||||
.Expect(InputType.Integer)
|
||||
.Expect(InputType.Integer, "num")
|
||||
.EndRepetition()
|
||||
.Expect(")")
|
||||
.Option()
|
||||
.Expect("strs(")
|
||||
.Expect(InputType.String)
|
||||
.Expect(InputType.String, "str")
|
||||
.Repeat()
|
||||
.Expect(",")
|
||||
.Expect(InputType.String)
|
||||
.Expect(InputType.String, "str")
|
||||
.EndRepetition()
|
||||
.Expect(")")
|
||||
.EndOptions()
|
||||
.Build();
|
||||
|
||||
var parser = new TextParser<FragmentSchemaContext>(schema);
|
||||
var rows = parser
|
||||
.SetInputText(testInput4)
|
||||
var fragmentData = parser
|
||||
.SetInputText(testInput5)
|
||||
.Parse()
|
||||
.AsFragments();
|
||||
|
||||
Assert.Equal(3, rows.Count);
|
||||
Assert.Equal(6, rows[0].Count);
|
||||
Assert.Equal(3, rows[1].Count);
|
||||
Assert.Equal(5, rows[2].Count);
|
||||
// Assert.Equal(InputType.Integer, rows[0][0].GetInputType());
|
||||
// Assert.Equal(InputType.String, rows[0][1].GetInputType());
|
||||
// Assert.Equal(InputType.String, rows[0][2].GetInputType());
|
||||
// Assert.Equal(InputType.String, rows[0][3].GetInputType());
|
||||
// Assert.Equal(InputType.String, rows[0][4].GetInputType());
|
||||
// Assert.Equal(InputType.String, rows[0][5].GetInputType());
|
||||
// Assert.Equal(InputType.Integer, rows[1][0].GetInputType());
|
||||
// Assert.Equal(InputType.String, rows[1][1].GetInputType());
|
||||
// Assert.Equal(InputType.String, rows[1][2].GetInputType());
|
||||
// Assert.Equal(InputType.Integer, rows[2][0].GetInputType());
|
||||
// Assert.Equal(InputType.String, rows[2][1].GetInputType());
|
||||
// Assert.Equal(InputType.Integer, rows[2][2].GetInputType());
|
||||
// Assert.Equal(InputType.String, rows[2][3].GetInputType());
|
||||
// Assert.Equal(InputType.String, rows[2][4].GetInputType());
|
||||
var convertedData = fragmentData
|
||||
.ConvertAll((Fragment f) =>
|
||||
{
|
||||
int numSum = 0;
|
||||
foreach (var numString in f["num"])
|
||||
{
|
||||
numSum += int.Parse(numString);
|
||||
}
|
||||
return f["num"].Count + f["str"].Count + numSum;
|
||||
});
|
||||
|
||||
Assert.Equal(4, fragmentData.Count);
|
||||
Assert.Equal(3, fragmentData[0]["num"].Count);
|
||||
Assert.Single(fragmentData[1]["str"]);
|
||||
Assert.Equal(2, fragmentData[2]["num"].Count);
|
||||
Assert.Equal(4, fragmentData[3]["str"].Count);
|
||||
Assert.Equal(13, convertedData[0]);
|
||||
Assert.Equal(1, convertedData[1]);
|
||||
Assert.Equal(12, convertedData[2]);
|
||||
Assert.Equal(4, convertedData[3]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user