public void TransformRulesTypeTypeTypeEx()
                    {
                        //arrange
                        var reg       = "r";
                        var pattern   = "[0-9]";
                        var typename  = "a";
                        var typep     = "<" + reg + ">";
                        var typebnf   = typep + "/child";
                        var exname    = "b";
                        var exname2   = "c";
                        var exbnf     = "b/child";
                        var exbnf2    = "<r>/child";
                        var rules_txt = "/start\n" +
                                        "/reg " + reg + " ::= " + pattern + "\n" +
                                        "/type " + typename + " ::= " + typebnf + "\n" +
                                        "/type= " + typename + " /type " + exname + " ::= " + exbnf + '\n' +
                                        "/type= " + exname + " /type " + exname2 + " ::= " + exbnf2 + '\n' +
                                        "/end";
                        var component = new TransformationComponent();

                        //act
                        var actual = component.TransformToRules(rules_txt);

                        //assert
                        Assert.AreEqual(0, actual.Languages.Count);

                        var resultRules = actual.GetBaseRules;

                        Assert.AreEqual(4, resultRules.Count);

                        CollectionAssert.Contains(resultRules.Keys, typename);
                        CollectionAssert.Contains(resultRules.Keys, exname);

                        var bnfrule = resultRules[exname] as BNFRule;

                        Assert.IsNotNull(bnfrule);

                        var basicBNFRule = new BasicBNFRule
                        {
                            new BNFReference("r"),
                            new BNFString("b"),
                            new BNFSystemRef(new Child())
                        };

                        TestUtil.AssertBNF(bnfrule, exname, basicBNFRule);

                        var expected = component.TransformToRules("/start\n" +
                                                                  "/reg r ::= [0-9]\n" +
                                                                  "/type b ::= <r>b/child\n" +
                                                                  "/end").GetBaseRules["b"] as TypeRule;

                        Assert.IsTrue(expected.Equals(resultRules["b"] as TypeRule));
                    }
                public void RequireReg()
                {
                    //Arrange
                    var rules = "/start\n" +
                                "/reg b ::= [0-9]\n" +
                                "a\n" +
                                "/language_start a\n" +
                                "a ::= abc\n" +
                                "/language_end\n" +
                                "/end\n";

                    var component = new TransformationComponent();

                    //Act
                    try
                    {
                        var result = component.TransformToRules(rules);
                    }
                    catch (RuleParseException ex)
                    {
                        Assert.IsInstanceOfType(ex.InnerException, typeof(LangRuleParseException));
                        Assert.IsInstanceOfType(ex.InnerException.InnerException, typeof(SyntaxErrorPlaced));
                        Assert.IsInstanceOfType(ex.InnerException.InnerException.InnerException, typeof(TranslateRuleRequired));
                        return;
                    }
                    //Assert
                    Assert.Fail("expected fail");
                }
Ejemplo n.º 3
0
                    public void ToRulesTypeStr()
                    {
                        //arrange
                        var name  = "a";
                        var bnf   = "a/child";
                        var rules = "Some strange comment-like text\n" +
                                    "with some new lines and //////star\n" +
                                    "but eventually /start\n" +
                                    "/type " + name + " ::= " + bnf + "\n" +
                                    "/end\n" +
                                    "Some more comments";
                        var component = new TransformationComponent();

                        //act
                        var actual = component.TransformToRules(rules);

                        //assert
                        Assert.AreEqual(actual.Languages.Count, 0);

                        var resultRules = actual.GetBaseRules;

                        Assert.AreEqual(1, resultRules.Count);

                        Assert.IsTrue(resultRules.ContainsKey(name));

                        var resultTypeRule = resultRules[name] as TypeRule;

                        var basicBNFRule = new BasicBNFRule
                        {
                            new BNFString("a"),
                            new BNFSystemRef(new Child())
                        };

                        TestUtil.AssertBNF(resultTypeRule, name, basicBNFRule);
                    }
Ejemplo n.º 4
0
                    public void ToRulesBNFFakeSys()
                    {
                        //arrange
                        var name     = "a";
                        var fakeName = "adkjlxfkbn";
                        var rules    = "Some strange comment-like text\n" +
                                       "with some new lines and //////star\n" +
                                       "but eventually /start\n" +
                                       name + " ::= /" + fakeName + "\n" +
                                       "/end\n" +
                                       "Some more comments";
                        var component = new TransformationComponent();

                        //act
                        try
                        {
                            var actual = component.TransformToRules(rules);
                        }//assert
                        catch (TransformComponentException tr)
                        {
                            Assert.IsInstanceOfType(tr, typeof(RuleParseException));
                            Assert.IsInstanceOfType(tr.InnerException, typeof(BaseRuleParseException));
                            Assert.IsInstanceOfType(tr.InnerException.InnerException, typeof(SyntaxErrorPlaced));
                        }
                    }
                public void RequireBNFRealisation()
                {
                    //Arrange
                    var rules = "/start\n" +
                                "a\n" +
                                "/language_start a\n" +
                                "/language_end\n" +
                                "/end\n";

                    var component = new TransformationComponent();

                    //Act
                    try
                    {
                        var result = component.TransformToRules(rules);
                    }
                    catch (RuleParseException ex)
                    {
                        Assert.IsInstanceOfType(ex.InnerException, typeof(LangRuleParseException));
                        Assert.IsInstanceOfType(ex.InnerException.InnerException, typeof(SyntaxErrorPlaced));
                        Assert.IsInstanceOfType(ex.InnerException.InnerException.InnerException, typeof(EOSException));
                        return;
                    }
                    //Assert
                    Assert.Fail();
                }
Ejemplo n.º 6
0
                    public void ToRulesTwoBNFSameName()
                    {
                        //arrange
                        var name  = "a";
                        var name2 = name;
                        var rules = "Some strange comment-like text\n" +
                                    "with some new lines and //////star\n" +
                                    "but eventually /start\n" +
                                    name + " ::= a\n" +
                                    name2 + " ::= b\n" +
                                    "/end\n" +
                                    "Some more comments";
                        var component = new TransformationComponent();

                        //act
                        try
                        {
                            var actual = component.TransformToRules(rules);
                        }
                        catch (System.Exception e)
                        {
                            //assert
                            Assert.IsInstanceOfType(e, typeof(RuleParseException));
                            Assert.IsInstanceOfType(e.InnerException, typeof(BaseRuleParseException));
                            Assert.IsInstanceOfType(e.InnerException.InnerException, typeof(SyntaxErrorPlaced));
                            Assert.IsInstanceOfType(e.InnerException.InnerException.InnerException, typeof(ConstructAlreadyDefined));
                        }
                    }
Ejemplo n.º 7
0
                    public void ToRulesBNF()
                    {
                        //arrange
                        var name  = "a";
                        var str   = "a";
                        var rules = "Some strange comment-like text\n" +
                                    "with some new lines and //////star\n" +
                                    "but eventually /start\n" +
                                    name + " ::= " + str + "\n" +
                                    "/end\n" +
                                    "Some more comments";
                        var component = new TransformationComponent();

                        //act
                        var actual = component.TransformToRules(rules);

                        //assert
                        Assert.AreEqual(actual.Languages.Count, 0);

                        var resultRules = actual.GetBaseRules;

                        Assert.AreEqual(1, resultRules.Count);

                        Assert.IsTrue(resultRules.ContainsKey(name));

                        var resultBNFRule = resultRules[name] as BNFRule;

                        var expBasicBNF = new BasicBNFRule();

                        expBasicBNF.Add(new BNFString(str));
                        TestUtil.AssertBNF(resultBNFRule, name, expBasicBNF);
                    }
Ejemplo n.º 8
0
                    public void SimpleRBnf()
                    {
                        //arrange
                        var name    = "r";
                        var pattern = "a|<r>";
                        var rules   = "/start\n" +
                                      name + " ::= " + pattern + "\n" +
                                      "/translate_rules_start\n" +
                                      name + " ::= a\n" +
                                      "/translate_rules_end\n" +
                                      "/end";

                        var component = new TransformationComponent();

                        //act
                        var result = component.TransformToRules(rules);

                        //assert
                        result.GetBaseRules.ContainsKey(name);
                        result.GetBaseRules.ContainsKey("T+" + name);

                        TestUtil.AssertBNF(result.GetBaseRules[name] as BNFRule, name,
                                           new BasicBNFRule {
                            new BNFString("a")
                        },
                                           new BasicBNFRule {
                            new BNFReference("r")
                        });
                        TestUtil.AssertBNF(result.GetBaseRules["T+" + name] as BNFRule, "T+" + name,
                                           new BasicBNFRule {
                            new BNFString("a")
                        });
                    }
Ejemplo n.º 9
0
                    public void ToRulesEmptyType()
                    {
                        //arrange
                        var name  = "a";
                        var rules = "Some strange comment-like text\n" +
                                    "with some new lines and //////star\n" +
                                    "but eventually /start\n" +
                                    "/type " + name + "\n" +
                                    "/end\n" +
                                    "Some more comments";
                        var component = new TransformationComponent();

                        //act
                        var actual = component.TransformToRules(rules);

                        //assert
                        Assert.AreEqual(actual.Languages.Count, 0);

                        var resultRules = actual.GetBaseRules;

                        Assert.AreEqual(1, resultRules.Count);

                        Assert.IsTrue(resultRules.ContainsKey(name));

                        var resultTypeRule = resultRules[name] as TypeRule;

                        TestUtil.AssertBNF(resultTypeRule, name);
                    }
Ejemplo n.º 10
0
                    public void ToRulesTwoReg()
                    {
                        //arrange
                        var pattern  = "[1-9][0-9]*|0";
                        var name     = "a";
                        var pattern2 = @"\w+";
                        var name2    = "b";
                        var rules    = "Some strange comment-like text\n" +
                                       "with some new lines and //////star\n" +
                                       "but eventually /start\n" +
                                       "/reg " + name + " ::= " + pattern + "\n" +
                                       "/reg " + name2 + " ::= " + pattern2 + "\n" +
                                       "/end\n" +
                                       "Some more comments";
                        var component = new TransformationComponent();

                        //act
                        var actual = component.TransformToRules(rules);

                        //assert
                        Assert.AreEqual(actual.Languages.Count, 0);

                        var resultRules = actual.GetBaseRules;

                        Assert.AreEqual(resultRules.Count, 2);

                        Assert.IsTrue(resultRules.ContainsKey(name));

                        var resultRegRule = resultRules[name] as RegexRule;

                        TestUtil.AssertReg(resultRegRule, name, pattern);

                        resultRegRule = resultRules[name2] as RegexRule;
                        TestUtil.AssertReg(resultRegRule, name2, pattern2);
                    }
                    public void ToRulesTypeOneParam()
                    {
                        //arrange
                        var n1         = "c";
                        var name       = "a";
                        var param_name = "b";
                        var param_body = "<" + n1 + ">";
                        var bnf        = "<" + param_name + ">/child";
                        var rules      = "Some strange comment-like text\n" +
                                         "with some new lines and //////star\n" +
                                         "but eventually /start\n" +
                                         n1 + "\n" +
                                         "/type " + name + " ::= " + bnf + "\n" +
                                         "/params_start\n" +
                                         param_name + " ::= " + param_body + "\n" +
                                         "/params_end\n" +
                                         "/end\n" +
                                         "Some more comments";
                        var component = new TransformationComponent();

                        //act
                        var actual = component.TransformToRules(rules);

                        //assert
                        Assert.AreEqual(actual.Languages.Count, 0);

                        var resultRules = actual.GetBaseRules;

                        Assert.AreEqual(3, resultRules.Count);

                        CollectionAssert.Contains(resultRules.Keys, n1);

                        TestUtil.AssertBNF((BNFRule)resultRules[n1], n1, new BasicBNFRule[0]);



                        Assert.IsTrue(resultRules.ContainsKey(name));

                        var resultTypeRule = resultRules[name] as TypeRule;

                        var basicBNFRule = new BasicBNFRule();

                        basicBNFRule.Add(new BNFReference("a.b"));
                        basicBNFRule.Add(new BNFSystemRef(new Child()));

                        TestUtil.AssertBNF(resultTypeRule, name,
                                           new BasicBNFRule[] { basicBNFRule });

                        var full_par_n    = name + "." + param_name;
                        var resultBNFRule = resultRules[full_par_n] as BNFRule;

                        basicBNFRule = new BasicBNFRule();
                        basicBNFRule.Add(new BNFReference(n1));

                        TestUtil.AssertBNF(resultBNFRule, full_par_n,
                                           new BasicBNFRule[] { basicBNFRule });
                    }
                    public void TransformRulesSimpleTypeEx()
                    {
                        //arrange
                        var typename  = "a";
                        var typep     = "a";
                        var typebnf   = typep + "/child";
                        var exname    = "b";
                        var exbnf     = "b";
                        var rules_txt = "/start\n" +
                                        "/type " + typename + " ::= " + typebnf + "\n" +
                                        "/type= " + typename + " " + exname + " ::= " + exbnf + '\n' +
                                        "/end";
                        var component = new TransformationComponent();

                        //act
                        var actual = component.TransformToRules(rules_txt);

                        //assert
                        Assert.AreEqual(0, actual.Languages.Count);

                        var resultRules = actual.GetBaseRules;

                        Assert.AreEqual(2, resultRules.Count);

                        CollectionAssert.Contains(resultRules.Keys, typename);
                        CollectionAssert.Contains(resultRules.Keys, exname);

                        var bnfrule = resultRules[exname] as BNFRule;

                        Assert.IsNotNull(bnfrule);

                        var basicBNFRule = new BasicBNFRule
                        {
                            new BNFString(typep + exbnf)
                        };

                        TestUtil.AssertBNF(bnfrule, exname, basicBNFRule);

                        var expected = component.TransformToRules("/start\n" +
                                                                  "b ::= ab\n" +
                                                                  "/end").GetBaseRules["b"] as BNFRule;

                        Assert.IsTrue(expected.Equals(resultRules["b"] as BNFRule));
                    }
            public void PascalCSharp()
            {
                //arrange
                string text = TransformationComponentUnitTest.Resource1.CSharpPascalRules;

                var component = new TransformationComponent();

                //act
                var actual = component.TransformToRules(text);
            }
                    public void TransformRulesTypeWithParamTypeEx()
                    {
                        //arrange
                        var reg       = "r";
                        var pattern   = "[0-9]";
                        var typename  = "a";
                        var typename2 = "b";
                        var paramname = "c";
                        var typep     = "<" + paramname + ">";
                        var typebnf   = "<" + paramname + ">" + "/child";
                        var typebnf2  = "a/child";
                        var param_txt = "<" + reg + ">";
                        var rules_txt = "/start\n" +
                                        "/reg " + reg + " ::= " + pattern + "\n" +
                                        "/type " + typename + " ::= " + typebnf + "\n" +
                                        "/params_start\n" +
                                        paramname + " ::= " + param_txt + "\n" +
                                        "/params_end\n" +
                                        "/type= " + typename + " /type " + typename2 + " ::= " + typebnf2 + "\n" +
                                        "/end";
                        var component = new TransformationComponent();

                        //act
                        var actual = component.TransformToRules(rules_txt);

                        //assert
                        Assert.AreEqual(0, actual.Languages.Count);

                        var resultRules = actual.GetBaseRules;

                        Assert.AreEqual(4, resultRules.Count);

                        CollectionAssert.Contains(resultRules.Keys, typename);
                        CollectionAssert.Contains(resultRules.Keys, reg);
                        CollectionAssert.Contains(resultRules.Keys, typename2);
                        CollectionAssert.Contains(resultRules.Keys, typename + "." + paramname);

                        var bnfrule = resultRules[typename2] as BNFRule;

                        Assert.IsNotNull(bnfrule);

                        var basicBNFRule = new BasicBNFRule
                        {
                            new BNFReference("a.c"),
                            new BNFString("a"),
                            new BNFSystemRef(new Child())
                        };

                        TestUtil.AssertBNF(bnfrule, typename2, basicBNFRule);
                    }
                public void ToRulesEmptyBodyClean()
                {
                    //arrange
                    var rules = "/start\n" +
                                "/end\n";
                    var component = new TransformationComponent();

                    //act
                    var actual = component.TransformToRules(rules);

                    //assert
                    Assert.AreEqual(actual.Languages.Count, 0);
                    Assert.AreEqual(actual.GetBaseRules.Count, 0);
                }
                public void ToRulesEmptyBody()
                {
                    //arrange
                    var rules = "Some strange comment-like text\n" +
                                "with some new lines and //////star\n" +
                                "but eventually /start\n" +
                                "/end\n" +
                                "Some more comments";
                    var component = new TransformationComponent();

                    //act
                    var actual = component.TransformToRules(rules);

                    //assert
                    Assert.AreEqual(actual.Languages.Count, 0);
                    Assert.AreEqual(actual.GetBaseRules.Count, 0);
                }
Ejemplo n.º 17
0
                    public void ToRulesBNFRefReg()
                    {
                        //arrange
                        var name    = "a";
                        var name2   = "b";
                        var pattern = "[0-9]+";
                        var rules   = "Some strange comment-like text\n" +
                                      "with some new lines and //////star\n" +
                                      "but eventually /start\n" +
                                      "/reg " + name + " ::= " + pattern + "\n" +
                                      name2 + " ::= <" + name + ">\n" +
                                      "/end\n" +
                                      "Some more comments";
                        var component = new TransformationComponent();

                        //act
                        var actual = component.TransformToRules(rules);

                        //assert
                        Assert.AreEqual(actual.Languages.Count, 0);

                        var resultRules = actual.GetBaseRules;

                        Assert.AreEqual(2, resultRules.Count);

                        Assert.IsTrue(resultRules.ContainsKey(name));

                        var resultRegRule = resultRules[name] as RegexRule;

                        TestUtil.AssertReg(resultRegRule, name, pattern);
                        Assert.IsTrue(resultRules.ContainsKey(name2));

                        var resultBNFRule = resultRules[name2] as BNFRule;



                        var expBasicBNF = new BasicBNFRule
                        {
                            new BNFReference(name)
                        };

                        TestUtil.AssertBNF(resultBNFRule, name2,
                                           new BasicBNFRule[1] {
                            expBasicBNF
                        });
                    }
                public void SimpleTenLanguages()
                {
                    //Arrange
                    var rules = "/start\n" +
                                "a\n" +
                                "/language_start a\n" +
                                "a ::= a\n" +
                                "/language_end\n" +
                                "/language_start b\n" +
                                "a ::= a\n" +
                                "/language_end\n" +
                                "/language_start c\n" +
                                "a ::= a\n" +
                                "/language_end\n" +
                                "/language_start d\n" +
                                "a ::= a\n" +
                                "/language_end\n" +
                                "/language_start e\n" +
                                "a ::= a\n" +
                                "/language_end\n" +
                                "/language_start f\n" +
                                "a ::= a\n" +
                                "/language_end\n" +
                                "/language_start g\n" +
                                "a ::= a\n" +
                                "/language_end\n" +
                                "/language_start h\n" +
                                "a ::= a\n" +
                                "/language_end\n" +
                                "/language_start i\n" +
                                "a ::= a\n" +
                                "/language_end\n" +
                                "/language_start j\n" +
                                "a ::= a\n" +
                                "/language_end\n" +
                                "/end\n";

                    var component = new TransformationComponent();

                    //Act
                    var result = component.TransformToRules(rules);

                    //Assert
                    Assert.AreEqual(10, result.Languages.Count);
                }
                public void SimpleOneLanguage()
                {
                    //Arrange
                    var rules = "/start\n" +
                                "a\n" +
                                "/language_start a\n" +
                                "a ::= a\n" +
                                "/language_end\n" +
                                "/end\n";

                    var component = new TransformationComponent();

                    //Act
                    var result = component.TransformToRules(rules);

                    //Assert
                    Assert.AreEqual(1, result.Languages.Count);
                }
                public void ToRulesEmpty()
                {
                    //arrange
                    var rules     = string.Empty;
                    var component = new TransformationComponent();

                    //act
                    try
                    {
                        var actual = component.TransformToRules(rules);
                    }
                    catch (System.Exception e)
                    {
                        //assert

                        Assert.IsInstanceOfType(e, typeof(RuleParseException));

                        Assert.IsInstanceOfType(e.InnerException, typeof(InputIsEmpty));
                    }
                }
                public void ToRulesNoStart()
                {
                    //arrange
                    var rules = "Some strange comment-like text\n" +
                                "with some new lines and //////star";
                    var component = new TransformationComponent();

                    //act
                    try
                    {
                        var actual = component.TransformToRules(rules);
                    }
                    catch (System.Exception e)
                    {
                        //assert

                        Assert.IsInstanceOfType(e, typeof(RuleParseException));

                        Assert.IsInstanceOfType(e.InnerException, typeof(NoStartDetected));
                    }
                }
                    public void ToRulesSysPresentation(System.Type type)
                    {
                        //arrange
                        var name  = "a";
                        var rule  = (SystemRule)System.Activator.CreateInstance(type);
                        var str   = rule.Literal;
                        var rules = "Some strange comment-like text\n" +
                                    "with some new lines and //////star\n" +
                                    "but eventually /start\n" +
                                    name + " ::= " + str + "\n" +
                                    "/end\n" +
                                    "Some more comments";
                        var component = new TransformationComponent();

                        //act
                        var actual = component.TransformToRules(rules);

                        //assert
                        Assert.AreEqual(actual.Languages.Count, 0);

                        var resultRules = actual.GetBaseRules;

                        Assert.AreEqual(1, resultRules.Count);

                        Assert.IsTrue(resultRules.ContainsKey(name));

                        var resultBNFRule = resultRules[name] as BNFRule;

                        var expBasicBNF = new BasicBNFRule
                        {
                            new BNFSystemRef(rule)
                        };

                        TestUtil.AssertBNF(resultBNFRule, name,
                                           new BasicBNFRule[1] {
                            expBasicBNF
                        });
                    }