feat: enable named literals, ref: NOISSUE
This commit is contained in:
@@ -20,6 +20,12 @@ public class TextParserTests
|
||||
cv strs(test) jh 4,3,2
|
||||
|
||||
34,54,2nums(2,8) strs(aa,ab,ba,bb)aa,bb";
|
||||
private const string testInput6 = @"adfdf1()324ddf3()svsdvs
|
||||
davnsldkvjs2()m23423()
|
||||
mcsodkcn owdjnfj 1() asdfnad 23234 2() sdvsdv";
|
||||
private const string testInput7 = @"adfdf1()324ddf3()()()svsdvs
|
||||
davnsldkvjs2()()m23423()()()
|
||||
mcsodkcn owdjnfj 1() asdfnad 23234 2()() sdvsdv";
|
||||
|
||||
[Fact]
|
||||
public void LineParser_TestSimpleRepetition()
|
||||
@@ -257,4 +263,56 @@ public class TextParserTests
|
||||
Assert.Equal(12, convertedData[2]);
|
||||
Assert.Equal(4, convertedData[3]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FragmentParser_LiteralTest()
|
||||
{
|
||||
var schemaBuilder = new FragmentSchemaBuilder();
|
||||
var schema = schemaBuilder
|
||||
.StartOptions()
|
||||
.Option()
|
||||
.Expect("1()", "option1")
|
||||
.Option()
|
||||
.Expect("2()", "option2")
|
||||
.Option()
|
||||
.Expect("3()", "option3")
|
||||
.EndOptions()
|
||||
.Build();
|
||||
|
||||
var parser = TextParser.Create(schema);
|
||||
var fragmentData = parser
|
||||
.SetInputText(testInput6)
|
||||
.Parse()
|
||||
.AsFragments();
|
||||
|
||||
var convertedData = fragmentData
|
||||
.ConvertAll((Fragment f) =>
|
||||
{
|
||||
bool saw1 = f.ContainsKey("option1") ? f["option1"].Count > 0 : false;
|
||||
bool saw2 = f.ContainsKey("option2") ? f["option2"].Count() > 0 : false;
|
||||
bool saw3 = f.ContainsKey("option3") ? f["option3"].Count() > 0 : false;
|
||||
int indicator = 0;
|
||||
if (saw1)
|
||||
{
|
||||
indicator += 1;
|
||||
}
|
||||
if (saw2)
|
||||
{
|
||||
indicator += 2;
|
||||
}
|
||||
if (saw3)
|
||||
{
|
||||
indicator += 4;
|
||||
}
|
||||
return indicator;
|
||||
});
|
||||
|
||||
Assert.Equal(6, convertedData.Count);
|
||||
Assert.Equal(1, convertedData[0]);
|
||||
Assert.Equal(4, convertedData[1]);
|
||||
Assert.Equal(2, convertedData[2]);
|
||||
Assert.Equal(4, convertedData[3]);
|
||||
Assert.Equal(1, convertedData[4]);
|
||||
Assert.Equal(2, convertedData[5]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user