Ejemplo n.º 1
0
        public static void SetHaxeFeatures(this IASContext mock)
        {
            var currentModel = new FileModel {
                Context = mock, Version = 4, haXe = true
            };
            var context = new HaXeContext.Context(new HaXeContext.HaXeSettings());

            BuildClassPath(context);
            context.CurrentModel = currentModel;
            mock.Settings.LanguageId.Returns(context.Settings.LanguageId);
            mock.Features.Returns(context.Features);
            mock.CurrentModel.Returns(currentModel);
            var visibleExternalElements = context.GetVisibleExternalElements();

            mock.GetVisibleExternalElements().Returns(visibleExternalElements);
            mock.GetCodeModel(null).ReturnsForAnyArgs(x =>
            {
                var src = x[0] as string;
                return(string.IsNullOrEmpty(src) ? null : context.GetCodeModel(src));
            });
            mock.IsImported(null, Arg.Any <int>()).ReturnsForAnyArgs(it =>
            {
                var member = it.ArgAt <MemberModel>(0);
                return(member != null && context.IsImported(member, it.ArgAt <int>(1)));
            });
            mock.ResolveType(null, null).ReturnsForAnyArgs(x => context.ResolveType(x.ArgAt <string>(0), x.ArgAt <FileModel>(1)));
            mock.IsFileValid.Returns(context.IsFileValid);
        }
        public static void SetHaxeFeatures(this IASContext context)
        {
            var currentModel = new FileModel {
                Context = context, Version = 4, haXe = true
            };
            var haxeContext = new HaXeContext.Context(new HaXeContext.HaXeSettings());

            BuildClassPath(haxeContext);
            haxeContext.CurrentModel = currentModel;
            context.Features.Returns(haxeContext.Features);
            context.CurrentModel.Returns(currentModel);
            var visibleExternalElements = haxeContext.GetVisibleExternalElements();

            context.GetVisibleExternalElements().Returns(x => visibleExternalElements);
            context.GetCodeModel(null).ReturnsForAnyArgs(x =>
            {
                var src = x[0] as string;
                return(string.IsNullOrEmpty(src) ? null : haxeContext.GetCodeModel(src));
            });
            context.ResolveType(null, null).ReturnsForAnyArgs(x => haxeContext.ResolveType(x.ArgAt <string>(0), x.ArgAt <FileModel>(1)));
        }
Ejemplo n.º 3
0
            public void ParseFile_FunctionTypesWithSubTypes()
            {
                using (
                    var resourceFile =
                        new TestFile("ASCompletion.Test_Files.parser.haxe.FunctionTypesWithSubTypesTest.hx"))
                {
                    var plugin = Substitute.For<PluginMain>();
                    plugin.MenuItems.Returns(new List<ToolStripItem>());
                    var context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    Context.ASContext.GlobalInit(plugin);
                    Context.ASContext.Context = context;
                    var model = context.GetCodeModel(File.ReadAllText(resourceFile.DestinationFile));

                    Assert.AreEqual(5, model.Members.Count);

                    var member = model.Members[0];
                    Assert.AreEqual("functionTypesWithSubTypes", member.Name);
                    Assert.AreEqual(FlagType.Function, member.Flags & FlagType.Function);
                    Assert.AreEqual(3, member.Parameters.Count);
                    Assert.AreEqual("((Dynamic->Dynamic)->Int)->Int", member.Type);
                    var arg = member.Parameters[0];
                    Assert.AreEqual("functionTypeArg", arg.Name);
                    Assert.AreEqual("(Dynamic->Dynamic)->Dynamic", arg.Type);
                    arg = member.Parameters[1];
                    Assert.AreEqual("functionTypeArg2", arg.Name);
                    Assert.AreEqual("(Dynamic->Dynamic)->(Int->Int)", arg.Type);
                    Assert.AreEqual("null", arg.Value);
                    arg = member.Parameters[2];
                    Assert.AreEqual("test2", arg.Name);
                    Assert.AreEqual("String", arg.Type);

                    member = model.Members[1];
                    Assert.AreEqual("functionType", member.Name);
                    Assert.AreEqual(2, member.LineFrom);
                    Assert.AreEqual(2, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual("(Dynamic->Dynamic)->Dynamic", member.Type);

                    member = model.Members[2];
                    Assert.AreEqual("functionType2", member.Name);
                    Assert.AreEqual(3, member.LineFrom);
                    Assert.AreEqual(3, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual("((Dynamic->Dynamic)->Int)->Int", member.Type);

                    member = model.Members[3];
                    Assert.AreEqual("functionType3", member.Name);
                    Assert.AreEqual(4, member.LineFrom);
                    Assert.AreEqual(4, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual("(Dynamic->Dynamic)->(Int->Int)", member.Type);

                    member = model.Members[4];
                    Assert.AreEqual("functionType4", member.Name);
                    Assert.AreEqual(5, member.LineFrom);
                    Assert.AreEqual(5, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual("Void->(Void->Array<Int>)", member.Type);
                }
            }
Ejemplo n.º 4
0
            public void ParseFile_FunctionTypes()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.FunctionTypesTest.hx"))
                {
                    var plugin = Substitute.For<PluginMain>();
                    plugin.MenuItems.Returns(new List<ToolStripItem>());
                    var context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    Context.ASContext.GlobalInit(plugin);
                    Context.ASContext.Context = context;
                    var model = context.GetCodeModel(File.ReadAllText(resourceFile.DestinationFile));

                    Assert.AreEqual(3, model.Members.Count);

                    var member = model.Members[1];
                    Assert.AreEqual("functionType", member.Name);
                    Assert.AreEqual(2, member.LineFrom);
                    Assert.AreEqual(2, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual("Dynamic->Dynamic", member.Type);

                    member = model.Members[2];
                    Assert.AreEqual("functionType2", member.Name);
                    Assert.AreEqual(3, member.LineFrom);
                    Assert.AreEqual(3, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual("Int->Int->Int", member.Type);
                }
            }
Ejemplo n.º 5
0
            public void ParseFile_RegExLiterals()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.RegExTest.hx"))
                {
                    var plugin = Substitute.For<PluginMain>();
                    plugin.MenuItems.Returns(new List<ToolStripItem>());
                    var context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    Context.ASContext.GlobalInit(plugin);
                    Context.ASContext.Context = context;
                    var model = context.GetCodeModel(File.ReadAllText(resourceFile.DestinationFile));

                    Assert.AreEqual(4, model.Members.Count); // First member = function itself

                    var regExMember = model.Members[1];
                    Assert.AreEqual("regExInArray", regExMember.Name);
                    Assert.AreEqual("Array<EReg>", regExMember.Type);
                    regExMember = model.Members[2];
                    Assert.AreEqual("regExInObject", regExMember.Name);
                    regExMember = model.Members[3];
                    Assert.AreEqual("regEx", regExMember.Name);
                    Assert.AreEqual("EReg", regExMember.Type);
                }
            }
Ejemplo n.º 6
0
            public void ParseFile_NotGeneric()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.NotGenericTest.hx"))
                {
                    var plugin = Substitute.For<PluginMain>();
                    plugin.MenuItems.Returns(new List<ToolStripItem>());
                    var context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    Context.ASContext.GlobalInit(plugin);
                    Context.ASContext.Context = context;
                    var model = context.GetCodeModel(File.ReadAllText(resourceFile.DestinationFile));

                    Assert.AreEqual(3, model.Members.Count); // First member = function itself

                    var funcMember = model.Members[0];
                    Assert.AreEqual("init", funcMember.Name);
                    Assert.AreEqual(FlagType.Function, funcMember.Flags & FlagType.Function);
                    var member1 = model.Members[1];
                    Assert.AreEqual("testA", member1.Name);
                    Assert.AreEqual("Int", member1.Type);
                    var member2 = model.Members[2];
                    Assert.AreEqual("i1", member2.Name);
                }
            }
Ejemplo n.º 7
0
            public void ParseFile_MultipleVarsAtOnce()
            {
                using (var resourceFile = new TestFile("ASCompletion.Test_Files.parser.haxe.MultipleVarsAtOnceTest.hx"))
                {
                    var plugin = Substitute.For<PluginMain>();
                    plugin.MenuItems.Returns(new List<ToolStripItem>());
                    var context = new HaXeContext.Context(new HaXeContext.HaXeSettings());
                    Context.ASContext.GlobalInit(plugin);
                    Context.ASContext.Context = context;
                    var model = context.GetCodeModel(File.ReadAllText(resourceFile.DestinationFile));

                    Assert.AreEqual(7, model.Members.Count);

                    var member = model.Members[1];
                    Assert.AreEqual("var1", member.Name);
                    Assert.AreEqual(2, member.LineFrom);
                    Assert.AreEqual(2, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual("Int", member.Type);

                    member = model.Members[2];
                    Assert.AreEqual("var2", member.Name);
                    Assert.AreEqual(2, member.LineFrom);
                    Assert.AreEqual(2, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual("(Dynamic->Dynamic)->(Int->Int)", member.Type);

                    member = model.Members[3];
                    Assert.AreEqual("var3", member.Name);
                    Assert.AreEqual(3, member.LineFrom);
                    Assert.AreEqual(3, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual("Float", member.Type);

                    member = model.Members[4];
                    Assert.AreEqual("var4", member.Name);
                    Assert.AreEqual(3, member.LineFrom);
                    Assert.AreEqual(3, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual("String", member.Type);

                    member = model.Members[5];
                    Assert.AreEqual("var5", member.Name);
                    Assert.AreEqual(4, member.LineFrom);
                    Assert.AreEqual(4, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual("Bool", member.Type);

                    member = model.Members[6];
                    Assert.AreEqual("var6", member.Name);
                    Assert.AreEqual(5, member.LineFrom);
                    Assert.AreEqual(5, member.LineTo);
                    Assert.AreEqual(FlagType.Variable, member.Flags & FlagType.Variable);
                    Assert.AreEqual("Dynamic", member.Type);
                }
            }