Пример #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 TestAdvanceAndReturnThrowsIfNextIsNotFunction()
        {
            string code = "class X { function BFunction() {}";

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

              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 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());
        }
Пример #5
0
        public void TestCanExtractNameOfFunctionWithTwoParams()
        {
            string code = "function Test(segmentA, segmentB) { }";

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

              Assert.AreEqual("Test(segmentA,segmentB)", parser.GetFunctionName());
              Assert.AreEqual("{", textParser.NextKeyword());
        }
Пример #6
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());
        }
Пример #7
0
        public void TestThrowsIfCallingConsumeInterfaceWhenNextIsNotInterface()
        {
            string code = "class MyClass { class MyClass2 { function foo() { } } }";

              LookAheadLangParser textParser = LookAheadLangParser.CreateJavascriptParser(TestUtil.GetTextStream(code));
              var parser = new JSParser(textParser);
              parser.ConsumeInterface();
        }
Пример #8
0
        public void TestNextFunctionIsWiredUpAndReturnsName()
        {
            string code = "function Test(segmentA, segmentB) { }";

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

              try
              {
            parser.AdvanceToNextFunction();

            Assert.Fail(); // should not get here
              }
              catch (CCCParserSuccessException function)
              {
            Assert.AreEqual("Test(segmentA,segmentB)", function.Function);
              }
        }
Пример #9
0
        public void TestNestedClassesWithFunctionFindFunction()
        {
            string code = "class MyClass { class MyClass2 { function foo() { } } }";

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

              try
              {
            parser.AdvanceToNextFunction();
            Assert.Fail();
              }
              catch (CCCParserSuccessException function)
              {
            Assert.AreEqual("MyClass::MyClass2::foo()", function.Function);
              }

              Assert.AreEqual("{", textParser.PeekNextKeyword());
        }
Пример #10
0
        public void TestFindFunctionInClass()
        {
            string code = "class MyClass { function foo() { } }";

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

              try
              {
            parser.AdvanceToNextFunction();
            Assert.Fail();
              }
              catch (CCCParserSuccessException function)
              {
            Assert.AreEqual("MyClass::foo()", function.Function);
              }
        }
Пример #11
0
        public void TestMemberFunctionNameIsRetrieved()
        {
            string code = "bind : function(ev, callback) { ... }";

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

              Assert.AreEqual("bind(ev,callback)", parser.GetFunctionName());
        }
Пример #12
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
        }
Пример #13
0
        public void TestGlobalAssignmentNotRecognizedAsFunction()
        {
            string code = "Backbone.Event = { };";

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

              Assert.IsFalse(parser.NextIsFunction());
        }
Пример #14
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());
        }
Пример #15
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());
        }
Пример #16
0
        public void TestFindsFunctionAfterInterfaceDefinition()
        {
            string code = "interface Thing { member: ();  foo() {} } boo() {}";

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

              try
              {
            parser.AdvanceToNextFunction();
            Assert.Fail();
              }
              catch (CCCParserSuccessException function)
              {
            Assert.AreEqual("boo()", function.Function);
              }

              Assert.AreEqual("{", textParser.NextKeyword());
        }
Пример #17
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());
        }
Пример #18
0
        public void TestModulesRecognizedAsContext()
        {
            string code = "module MyNamespace { export class X { grey() {} } }";

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

              try
              {
            parser.AdvanceToNextFunction();
            Assert.Fail();
              }
              catch (CCCParserSuccessException function)
              {
            Assert.AreEqual("MyNamespace::X::grey()", function.Function);
              }

              Assert.AreEqual("{", textParser.PeekNextKeyword());
        }
Пример #19
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());
        }
Пример #20
0
        public void TestConsumesTypeScriptInterfaces()
        {
            string code = "interface Thing { intersect: (ray: Ray); normal: (pos: Vector); } NEXT";

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

              Assert.IsTrue(parser.NextIsInterface());

              parser.ConsumeInterface();

              Assert.AreEqual("NEXT", textParser.NextKeyword());
        }