namespace ExpressionTests; using BCG; using Bts.DataStreamExpressions; using Bts.ExpressionTests; using Spark.Core; public class DataStreamExpressionTests { static string simpleExpression => "literal(\"n\", \"2.0\")"; [SetUp] public void Setup() { } void validateExpression(string expressionStr, bool expectSuccess = true) { var env = new Dictionary(); if (expectSuccess) { var expression = DataStreamExpressionsInterpreter.Evaluate(expressionStr); Assert.NotNull(expression.getView(env)); } else { try { // var expression = DataStreamExpressionsInterpreter.TryEvaluate(expressionStr); // Assert.IsNull(expression); } catch { } } } void validateExpression(IEnumerable lines, bool expectSuccess = true) { validateExpression("\n".join(lines), expectSuccess); } [Test] public void TestLineComments() { var commentBodies = new[] { "comment", "comment w/ odd symbols $@!&*.;: (i.e., those!)" }; // Create 2 layers of permutations. // 1. with and without white space between '//' and comment body // 2. with and without leading white space // 3. with and without trailing white space var comments = commentBodies .SelectMany(c => new[] { c, $" {c}", $" {c} ", $"{c} " }) .SelectMany(c => new[] { $"//{c}", $"// {c}" }) .SelectMany(c => new[] { c, $" {c}", $"{c} ", $" {c} " }); foreach (var c in comments) { impl(c); } void impl(string comment) { // Test single line comment (evaluation should fail) var expLines = new List() { comment }; validateExpression(expLines, false); // Add valid expression after comment (evaluation should succeed) expLines.Add(simpleExpression); validateExpression(expLines); // Add comment after expression expLines.Add(comment); validateExpression(expLines); expLines.Add(string.Empty); validateExpression(expLines); } } [Test] public void Test() { var expressionLines = new List() { "// fake comment w/ odd symbols $@!&*.;: (i.e., those!)", "literal(\"n\", \"2.0\")", "// com" }; var expressionStr = "\n".join(expressionLines); var expression = DataStreamExpressionsInterpreter.Evaluate(expressionStr + "\n"); var env = new Dictionary(); foreach (var s in expression.Statements) { Console.WriteLine("Statement: " + s.ToString()); } Assert.NotNull(expression.getView(env)); } public void SimpleOperatorTest() { // Assert.IsTrue(BooleanExpression); } }