コード例 #1
0
ファイル: ContextRule.cs プロジェクト: tzf-key/SharpGenTools
        public void ContextRuleLimitsWhereMappingRuleExecutes()
        {
            var config = new ConfigFile
            {
                Id        = nameof(ContextRuleLimitsWhereMappingRuleExecutes),
                Namespace = nameof(ContextRuleLimitsWhereMappingRuleExecutes),
                Includes  =
                {
                    new IncludeRule
                    {
                        Attach    = true,
                        File      = "cppEnum.h",
                        Namespace = nameof(ContextRuleLimitsWhereMappingRuleExecutes)
                    },
                    new IncludeRule
                    {
                        Attach    = true,
                        File      = "secondFile.h",
                        Namespace = nameof(ContextRuleLimitsWhereMappingRuleExecutes)
                    }
                },
                Mappings =
                {
                    new Config.ContextRule("cppEnum"),
                    new MappingRule
                    {
                        Enum             = "AnotherEnum",
                        MappingNameFinal = "NewEnum"
                    },
                    new ClearContextRule()
                }
            };

            var cppModel = new CppModule("SharpGenTestModule");

            var cppInclude = new CppInclude("cppEnum");

            var cppEnum = new CppEnum("TestEnum");

            var secondInclude = new CppInclude("secondFile");

            var cppEnum2 = new CppEnum("AnotherEnum");

            cppEnum.AddEnumItem("Element1", "0");
            cppEnum.AddEnumItem("Element2", "1");
            cppInclude.Add(cppEnum);
            cppModel.Add(cppInclude);


            var(solution, _) = MapModel(cppModel, config);

            Assert.Empty(solution.EnumerateDescendants().OfType <CsEnum>().Where(csEnum => csEnum.Name == "AnotherEnum"));
        }
コード例 #2
0
ファイル: Enum.cs プロジェクト: xiaotie/SharpGenTools
        public void ExplicitValues()
        {
            var config = new Config.ConfigFile
            {
                Id        = nameof(ExplicitValues),
                Assembly  = nameof(ExplicitValues),
                Namespace = nameof(ExplicitValues),
                Includes  =
                {
                    new Config.IncludeRule
                    {
                        Attach    = true,
                        File      = "cppEnum.h",
                        Namespace = nameof(ExplicitValues)
                    }
                }
            };

            var cppModel = new CppModule();

            var cppInclude = new CppInclude
            {
                Name = "cppEnum"
            };

            var cppEnum = new CppEnum
            {
                Name = "TestEnum"
            };

            cppEnum.AddEnumItem("Element1", "10");
            cppEnum.AddEnumItem("Element2", "15");
            cppEnum.AddEnumItem("Element3", "10");
            cppInclude.Add(cppEnum);
            cppModel.Add(cppInclude);

            var(solution, _) = MapModel(cppModel, config);

            var members = solution.EnumerateDescendants();

            Assert.Single(members.OfType <CsEnum>());

            var csEnum = members.OfType <CsEnum>().First();

            Assert.Single(csEnum.EnumItems.Where(item => item.Name == "Element1" && item.Value == "10"));
            Assert.Single(csEnum.EnumItems.Where(item => item.Name == "Element2" && item.Value == "15"));
            Assert.Single(csEnum.EnumItems.Where(item => item.Name == "Element3" && item.Value == "10"));
            Assert.Equal(typeof(int), csEnum.UnderlyingType.Type);
        }
コード例 #3
0
ファイル: Enum.cs プロジェクト: JetBrains/SharpGenTools
        public void Basic()
        {
            var config = new ConfigFile
            {
                Id        = nameof(Basic),
                Namespace = nameof(Basic),
                Includes  =
                {
                    new IncludeRule
                    {
                        Attach    = true,
                        File      = "cppEnum.h",
                        Namespace = nameof(Basic)
                    }
                }
            };

            var cppModel = new CppModule("SharpGenTestModule");

            var cppInclude = new CppInclude("cppEnum");

            var cppEnum = new CppEnum("TestEnum");

            cppEnum.AddEnumItem("Element1", "0");
            cppEnum.AddEnumItem("Element2", "1");
            cppInclude.Add(cppEnum);
            cppModel.Add(cppInclude);

            var(solution, _) = MapModel(cppModel, config);

            var members = solution.EnumerateDescendants();

            Assert.Single(members.OfType <CsEnum>());

            var csEnum = members.OfType <CsEnum>().First();

            Assert.Single(csEnum.EnumItems.Where(item => item.Name == "Element1" && item.Value == "0"));
            Assert.Single(csEnum.EnumItems.Where(item => item.Name == "Element2" && item.Value == "1"));
            Assert.Equal(TypeRegistry.Int32, csEnum.UnderlyingType);
        }