Exemplo n.º 1
0
        public void TestExpressionParserDbg(string query)
        {
            var context     = TokenzierContext.FromText(query);
            var expressions = ExpressionTokenizer.ParseExpressionOrString(query, context);

            Assert.That(expressions, Is.Not.Null);
            Assert.That(context.Errors, Is.Empty, () => context.Errors.GetErrorText());
        }
Exemplo n.º 2
0
        public void TestExpressionParser(string query)
        {
            var context     = TokenzierContext.FromText(query);
            var expressions = ExpressionTokenizer.ParseExpressionOrString(query, context);

            Assert.That(expressions, Is.Not.Null);

            var visitor = new ToParsableStringExpressionVisitor();

            expressions.Accept(visitor);

            Assert.That(visitor.StringBuilder.ToString(), Is.EqualTo(query));
            Assert.That(context.Errors, Is.Empty, () => context.Errors.GetErrorText());
        }
Exemplo n.º 3
0
        public async Task CanParseString()
        {
            var text   = "'test'";
            var result = ExpressionTokenizer.ParseExpressionOrString(text, out var context);

            Assert.That(context.Errors, Is.Empty, () => context.Errors.Select(f => f.GetException().ToString())
                        .Aggregate((e, f) => e + "\r\n-------------" + f));
            Assert.That(result, Is.TypeOf <MorestachioExpressionString>());
            var expressionString = (result as MorestachioExpressionString);

            Assert.That(expressionString.Location.ToFormatString(), Is.EqualTo("1:1"));
            Assert.That(expressionString.StringParts.Count, Is.EqualTo(1));
            Assert.That((await expressionString.GetValue(StringTestContext(), new ScopeData())).Value, Is.EqualTo("test"));
        }
Exemplo n.º 4
0
        public async Task CanParseStringWithEscaptedChars()
        {
            var text   = "\"a string, with a comma, and other {[]}{§$%& stuff. also a escaped \\\" and \\\\\" and so on\"";
            var result = ExpressionTokenizer.ParseExpressionOrString(text, out var context);

            Assert.That(context.Errors, Is.Empty, () => context.Errors.Select(f => f.GetException().ToString())
                        .Aggregate((e, f) => e + "\r\n-------------" + f));

            Assert.That(result, Is.TypeOf <MorestachioExpressionString>());
            var expressionString = (result as MorestachioExpressionString);

            Assert.That(expressionString.Location.ToFormatString(), Is.EqualTo("1:1"));
            Assert.That(expressionString.StringParts.Count, Is.EqualTo(1));
            Assert.That((await expressionString.GetValue(StringTestContext(), new ScopeData())).Value, Is.EqualTo("a string, with a comma, and other {[]}{§$%& stuff. also a escaped \" and \\\" and so on"));
        }