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.º 2
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 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.º 4
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);
            }