Ejemplo n.º 1
0
        public void JsonSerialize_PatternWithVar_JsonEqualsToDsl()
        {
            var pwdVar = new PatternVarDef {
                Id = "pwd", Values = new List <Expression>()
                {
                    new PatternIdToken("password")
                }
            };
            var patternNode = new PatternNode
            {
                Vars = new List <PatternVarDef>()
                {
                    pwdVar
                },
                Node = new PatternStatements(
                    new ExpressionStatement
                {
                    Expression = new AssignmentExpression
                    {
                        Left  = new PatternVarRef(pwdVar),
                        Right = new PatternExpression()
                    }
                },
                    new PatternMultipleStatements(),
                    new ExpressionStatement
                {
                    Expression = new InvocationExpression
                    {
                        Target    = new PatternExpression(),
                        Arguments = new PatternExpressions(
                            new PatternMultipleExpressions(),
                            new PatternVarRef(pwdVar),
                            new PatternMultipleExpressions())
                    }
                }
                    )
            };

            var jsonSerializer = new JsonUstNodeSerializer(typeof(UstNode), typeof(PatternVarDef));

            jsonSerializer.Indented         = true;
            jsonSerializer.IncludeTextSpans = false;

            string  json         = jsonSerializer.Serialize(patternNode);
            UstNode nodeFromJson = jsonSerializer.Deserialize(json, LanguageExt.AllPatternLanguages);

            var dslSeializer = new DslProcessor()
            {
                PatternExpressionInsideStatement = false
            };
            var nodeFromDsl = dslSeializer.Deserialize("<[@pwd:password]> = #; ... #(#*, <[@pwd]>, #*);", LanguageExt.AllPatternLanguages);

            Assert.IsTrue(nodeFromJson.Equals(patternNode));
            Assert.IsTrue(nodeFromJson.Equals(nodeFromDsl));
        }
Ejemplo n.º 2
0
        public void Process_Dsl_EqualsToHardcoded(string fileName)
        {
            var data      = File.ReadAllText(Path.Combine(TestHelper.TestsDataPath, fileName));
            var logger    = new LoggerMessageCounter();
            var processor = new DslProcessor()
            {
                Logger = logger, PatternExpressionInsideStatement = false
            };
            UstNode result = processor.Deserialize(data, fileName == @"DebugInfo.aipm" ? LanguageFlags.Php : LanguageExt.AllPatternLanguages);

            Assert.AreEqual(0, logger.ErrorCount);

            string  patternName    = Path.GetFileNameWithoutExtension(fileName);
            Pattern defaultPattern = patterns.FirstOrDefault(p => p.DebugInfo.StartsWith(patternName));

            if (defaultPattern == null)
            {
                Assert.Inconclusive($"Pattern {patternName} does not exists in DefaultPatternRepository");
            }

            Assert.IsTrue(result.Equals(defaultPattern.Data));
        }