Ejemplo n.º 1
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.º 2
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.º 3
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.º 5
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.º 6
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.º 7
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);
                    }
        private void UpdateNode(ref ModelNodeTransformation node)
        {
            // Compute LocalMatrix
            if ((node.Flags & ModelNodeFlags.EnableTransform) == ModelNodeFlags.EnableTransform)
            {
                TransformationComponent.CreateMatrixTRS(ref node.Transform.Translation, ref node.Transform.Rotation, ref node.Transform.Scaling, out node.LocalMatrix);
            }

            var nodeTransformationsLocal = this.nodeTransformations;

            var parentIndex = node.ParentIndex;

            // Update Enabled
            bool renderingEnabledRecursive = (node.Flags & ModelNodeFlags.EnableRender) == ModelNodeFlags.EnableRender;

            if (parentIndex != -1)
            {
                renderingEnabledRecursive &= nodeTransformationsLocal[parentIndex].RenderingEnabledRecursive;
            }

            node.RenderingEnabledRecursive = renderingEnabledRecursive;

            if (renderingEnabledRecursive)
            {
                // Compute WorldMatrix
                if (parentIndex != -1)
                {
                    Matrix.Multiply(ref node.LocalMatrix, ref nodeTransformationsLocal[parentIndex].WorldMatrix, out node.WorldMatrix);
                }
                else
                {
                    node.WorldMatrix = node.LocalMatrix;
                }
            }
        }
Ejemplo n.º 9
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));
                        }
                    }
                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");
                }
            public void TransformNoTargetLanguage()
            {
                //arrange
                string text = "Some text";

                AllRules allRules = new AllRules();

                allRules.AddBaseRules(new System.Collections.Generic.Dictionary <string, Rule>());

                string sourceLang = "a";

                string targetLang = "b";

                allRules.AddLanguageRules(sourceLang, new System.Collections.Generic.Dictionary <string, Rule>());


                TransformationComponent transformationComponent = new TransformationComponent();

                //act
                try
                {
                    transformationComponent.Transform(text, allRules, sourceLang, targetLang);
                }
                catch (TransformComponentException tr)
                {
                    Assert.IsInstanceOfType(tr, typeof(ModelParseException));
                    Assert.IsInstanceOfType(tr.InnerException, typeof(NoLanguageRulesFound));
                }
            }
Ejemplo n.º 12
0
        /// <summary>
        /// Create a new <see cref="Entity"/> instance having the provided name and initial position.
        /// </summary>
        /// <param name="position">The initial position of the entity</param>
        /// <param name="name">The name to give to the entity</param>
        public Entity(Vector3 position, string name = null)
            : base(name)
        {
            Tags.PropertyUpdated += EntityPropertyUpdated;

            Transformation             = new TransformationComponent();
            transformation.Translation = position;
        }
                    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 PascalCSharp()
            {
                //arrange
                string text = TransformationComponentUnitTest.Resource1.CSharpPascalRules;

                var component = new TransformationComponent();

                //act
                var actual = component.TransformToRules(text);
            }
Ejemplo n.º 15
0
            public void PascalToCSharp()
            {
                //arrange
                var rules     = TransformationComponentUnitTest.Resource1.CSharpPascalRules;
                var source    = TransformationComponentUnitTest.Resource1.PascalSource;
                var component = new TransformationComponent();

                //act
                var actual = component.Transform(source, rules, "Pascal", "CSharp");

                System.Diagnostics.Debug.WriteLine(actual);
            }
                    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 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);
                }
Ejemplo n.º 19
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
                        });
                    }
Ejemplo n.º 20
0
        /// <summary>
        /// Updades the graphics transformation from the given physics transformation
        /// </summary>
        /// <param name="physicsTransform"></param>
        internal void UpdateTransformationComponent(Matrix physicsTransform)
        {
            var entity = (Entity)Collider.EntityObject;

            if (Shape.Shape.LocalOffset != Vector3.Zero || Shape.Shape.LocalRotation != Quaternion.Identity)
            {
                physicsTransform = Matrix.Multiply(Shape.Shape.NegativeCenterMatrix, physicsTransform);
            }

            var rotation    = Quaternion.RotationMatrix(physicsTransform);
            var translation = physicsTransform.TranslationVector;

            //Invert up axis in the case of a Sprite
            if (Sprite)
            {
                translation.Y = -translation.Y;
            }

            if (entity.Transformation.UseTRS)
            {
                entity.Transformation.Translation = translation;
                entity.Transformation.Rotation    = rotation;
            }
            else
            {
                var worldMatrix = entity.Transformation.WorldMatrix;

                Vector3 scale;
                scale.X = (float)Math.Sqrt((worldMatrix.M11 * worldMatrix.M11) + (worldMatrix.M12 * worldMatrix.M12) + (worldMatrix.M13 * worldMatrix.M13));
                scale.Y = (float)Math.Sqrt((worldMatrix.M21 * worldMatrix.M21) + (worldMatrix.M22 * worldMatrix.M22) + (worldMatrix.M23 * worldMatrix.M23));
                scale.Z = (float)Math.Sqrt((worldMatrix.M31 * worldMatrix.M31) + (worldMatrix.M32 * worldMatrix.M32) + (worldMatrix.M33 * worldMatrix.M33));

                TransformationComponent.CreateMatrixTRS(ref translation, ref rotation, ref scale, out entity.Transformation.WorldMatrix);
                if (entity.Transformation.Parent == null)
                {
                    entity.Transformation.LocalMatrix = entity.Transformation.WorldMatrix;
                }
                else
                {
                    //We are not root so we need to derive the local matrix as well
                    var inverseParent = entity.Transformation.Parent.WorldMatrix;
                    inverseParent.Invert();
                    entity.Transformation.LocalMatrix = Matrix.Multiply(entity.Transformation.WorldMatrix, inverseParent);
                }
            }
        }
                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);
                }
                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 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 SimpleTransform()
            {
                //arrange
                var      text       = "a";
                var      sourceLang = "a";
                var      targetLang = "b";
                AllRules allRules   = new AllRules();

                allRules.AddBaseRules(
                    new System.Collections.Generic.Dictionary <string, Rule>
                {
                    ["Program"] = new BNFRule("Program")
                }
                    );
                allRules.AddLanguageRules(sourceLang, new System.Collections.Generic.Dictionary <string, Rule>
                {
                    ["Program"] = new BNFRule("Program")
                    {
                        new BasicBNFRule {
                            new BNFString("a")
                        }
                    }
                });
                allRules.AddLanguageRules(targetLang, new System.Collections.Generic.Dictionary <string, Rule>
                {
                    ["Program"] = new BNFRule("Program")
                    {
                        new BasicBNFRule {
                            new BNFString("b")
                        }
                    }
                });
                var transformationComponent = new TransformationComponent();
                var expected = "b";


                //act
                var actual = transformationComponent.Transform(text, allRules, sourceLang, targetLang);

                //assert
                Assert.AreEqual(expected, actual);
            }
Ejemplo n.º 26
0
        public void AddComponent <T>(T component) where T : GameObjectComponent
        {
            component.GameObject = this;
            if (this.GetComponent <T>() != null)
            {
                this.RemoveComponent <T>();
            }

            _components.Add(component.GetType(), component);
            if (component.GetType() == typeof(TransformationComponent))
            {
                this.Transform = component as TransformationComponent;
            }

            if (_isLoaded)
            {
                // We are already loaded to load this component
                component.Loaded();
            }
        }
                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
                        });
                    }
Ejemplo n.º 30
0
            public void HasTwoLang_BNF()
            {
                //arrange
                var rules = "/start\n" +
                            "Program\n" +
                            "/language_start a\n" +
                            "Program ::= a\n" +
                            "/language_end\n" +
                            "/language_start b\n" +
                            "Program ::= b\n" +
                            "/language_end\n" +
                            "/end";
                var text      = "a";
                var component = new TransformationComponent();
                var expected  = "b";

                //act
                var actual = component.Transform(text, rules, "a", "b");

                //assert
                Assert.IsNotNull(actual);
                Assert.AreEqual(expected, actual);
            }