示例#1
0
        public void TestAnonymousFunctionIsRecognizedAsFunction()
        {
            string code = "function () { }";
            LookAheadLangParser textParser = LookAheadLangParser.CreateJavascriptParser(TestUtil.GetTextStream(code));
            var parser = new JSParser(textParser);

            Assert.IsTrue(parser.NextIsFunction());
        }
示例#2
0
        public void TestFunctionAssignment()
        {
            string code = "Backbone.View = function(options) {}";
            LookAheadLangParser textParser = LookAheadLangParser.CreateJavascriptParser(TestUtil.GetTextStream(code));
            var parser = new JSParser(textParser);

            Assert.IsTrue(parser.NextIsFunction());
            Assert.AreEqual("Backbone.View(options)", parser.GetFunctionName());
        }
示例#3
0
        public void GlobalScopeCodeNotRecognizedAsFunction()
        {
            string code = "if (x) { ... }";

            LookAheadLangParser textParser = LookAheadLangParser.CreateJavascriptParser(TestUtil.GetTextStream(code));
            var parser = new JSParser(textParser);

            Assert.IsFalse(parser.NextIsFunction());
        }
示例#4
0
        public void TestGlobalAssignmentNotRecognizedAsFunction()
        {
            string code = "Backbone.Event = { };";

            LookAheadLangParser textParser = LookAheadLangParser.CreateJavascriptParser(TestUtil.GetTextStream(code));
            var parser = new JSParser(textParser);

            Assert.IsFalse(parser.NextIsFunction());
        }
示例#5
0
        public void TestMemberFunctionisRecognizedAsFunction()
        {
            string code = "bind : function(ev, callback) { ... }";

            LookAheadLangParser textParser = LookAheadLangParser.CreateJavascriptParser(TestUtil.GetTextStream(code));
            var parser = new JSParser(textParser);

            Assert.IsTrue(parser.NextIsFunction());
            Assert.AreEqual("bind", textParser.PeekNextKeyword()); // parser should not have consumed any of the tokens
        }
示例#6
0
        public void TestFunctionWithTwoArgumentsIsRecognizedAsFunction()
        {
            string code = "function Test(segmentA, segmentB) { }";

            LookAheadLangParser textParser = LookAheadLangParser.CreateJavascriptParser(TestUtil.GetTextStream(code));
            var parser = new JSParser(textParser);

            Assert.IsTrue(parser.NextIsFunction());
            Assert.AreEqual("function", textParser.PeekNextKeyword());
        }
示例#7
0
        public void TestAnonymousFunctionIsNameAnonymous()
        {
            string code = "function (par1,par2) { }";
            LookAheadLangParser textParser = LookAheadLangParser.CreateJavascriptParser(TestUtil.GetTextStream(code));
            var parser = new JSParser(textParser);

            Assert.IsTrue(parser.NextIsFunction());

            Assert.AreEqual("function(par1,par2)", parser.GetFunctionName());
        }
示例#8
0
        public void TestCanFindTypeScriptFunctionWithReturnType()
        {
            string code = "function greet(): int { }";

            LookAheadLangParser textParser = LookAheadLangParser.CreateJavascriptParser(TestUtil.GetTextStream(code));
            var parser = new JSParser(textParser);

            Assert.IsTrue(parser.NextIsFunction());
            Assert.AreEqual("greet()", parser.GetFunctionName());
            Assert.AreEqual("{", textParser.NextKeyword());
        }
示例#9
0
        public void TestAnonFunctionWithoutParametersRecognizedAsFunction()
        {
            string code = "greet() { }";

            LookAheadLangParser textParser = LookAheadLangParser.CreateJavascriptParser(TestUtil.GetTextStream(code));
            var parser = new JSParser(textParser);

            Assert.IsTrue(parser.NextIsFunction());
            Assert.AreEqual("greet()", parser.GetFunctionName());
            Assert.AreEqual("{", textParser.PeekNextKeyword());
        }
示例#10
0
        public void TestMethodNamesWithDoubleNamesAreRecognized()
        {
            string code = "AFunction: function BFunction() {}";

            LookAheadLangParser textParser = LookAheadLangParser.CreateJavascriptParser(TestUtil.GetTextStream(code));
            var parser = new JSParser(textParser);

            Assert.IsTrue(parser.NextIsFunction());
            Assert.AreEqual("BFunction()", parser.GetFunctionName());
            Assert.AreEqual("{", textParser.PeekNextKeyword());
        }