我正在使用'Token()‘方法丢弃前导和尾随空格,但它不会,此测试失败,并显示消息Expected string to be "token", but it has unexpected whitespace at the end.
我试着在调用方法Text()之前调用方法Token(),但是也没有用。Parse.AnyChar.Many().Token().Text()
如何正确使用Token()方法?
[Test]
public void Test()
{
Parser<string> parser = Parse.AnyChar.Many().Text().Token();
var actual = parser.Parse(" token ");
actual.Should().Be("token"); // without leading and trailing whitespaces
}发布于 2018-01-05 09:46:29
在Token修饰符生效之前,Parse.AnyChar会使用尾随空格。
要修复解析器,请像这样排除空格:
[Test]
public void Test()
{
var parser = Parse.AnyChar.Except(Parse.WhiteSpace).Many().Text().Token();
var actual = parser.Parse(" token ");
actual.Should().Be("token"); // without leading and trailing whitespaces
}https://stackoverflow.com/questions/47883869
复制相似问题