Esempio n. 1
0
        public void NoneEndedCommentTest()
        {
            string        lInputData           = "Ientifier{\\\\\\\\\\\\\\\\";
            string        lExpectedTokenString = "{\\\\\\\\\\\\\\\\";
            DelphiScanner target = new DelphiScanner(new StringReader(lInputData));

            TokenInfo tokenInfo = new TokenInfo();

            int state          = 0; // TODO: Initialize to an appropriate value
            int state_expected = 1; // TODO: Initialize to an appropriate value

            bool expected = true;
            bool actual;

            actual = target.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state);
            actual = target.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state);

            Assert.AreEqual(state_expected, state, "state_ScanTokenAndProvideInfoAboutIt_expected was not set correctly.");
            Assert.AreEqual(expected, actual, "VisualStudio.Delphi.Language.DelphiScanner.ScanTokenAndProvideInfoAboutIt did not" +
                            " return the expected value.");

            Assert.AreEqual(TokenType.Comment, tokenInfo.Type, "TokenInfo.TokenType did not return expected value");
            Assert.AreEqual(lExpectedTokenString, lInputData.Substring(tokenInfo.StartIndex, tokenInfo.EndIndex - tokenInfo.StartIndex + 1),
                            "TokenInfo.StartIndex and TokenInfo.EndIndex did not return expected value");
        }
Esempio n. 2
0
        public void DelphiStringWithChrLiteralsTest()
        {
            string        lInputData           = "Identifier #$0A#10'This is a test string''ss wieth '''#13#10 AndWhiteSpace";
            string        lExpectedTokenString = "#$0A#10'This is a test string''ss wieth '''#13#10";
            DelphiScanner target = new DelphiScanner(new StringReader(lInputData));

            TokenInfo tokenInfo = new TokenInfo();

            int state          = 0; // TODO: Initialize to an appropriate value
            int state_expected = 0; // TODO: Initialize to an appropriate value

            bool expected = true;
            bool actual;

            actual = target.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state);
            actual = target.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state);
            actual = target.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state);

            Assert.AreEqual(state_expected, state, "state_ScanTokenAndProvideInfoAboutIt_expected was not set correctly.");
            Assert.AreEqual(expected, actual, "VisualStudio.Delphi.Language.DelphiScanner.ScanTokenAndProvideInfoAboutIt did not" +
                            " return the expected value.");

            Assert.AreEqual(TokenType.String, tokenInfo.Type, "TokenInfo.TokenType did not return expected value");
            Assert.AreEqual(lExpectedTokenString, lInputData.Substring(tokenInfo.StartIndex, tokenInfo.EndIndex - tokenInfo.StartIndex + 1),
                            "TokenInfo.StartIndex and TokenInfo.EndIndex did not return expected value");
        }
 public override IScanner GetScanner(IVsTextLines buffer)
 {
     if (FDelphiScanner == null)
     {
         FDelphiScanner = new DelphiScanner();
     }
     return(FDelphiScanner);
 }
Esempio n. 4
0
        public void SetSourceTest()
        {
            DelphiScanner target = TestDelphiScanner.VisualStudio_Delphi_Language_DelphiScannerAccessor.CreatePrivate();

            string source = "Test data";

            int offset = 0;

            target.SetSource(source, offset);
        }
Esempio n. 5
0
        // wrapper for yyparse
        public TranslationUnit Parse(TextReader tr, SourceFile file = null, ParserDebug dgb = null)
        {
            if (dgb != null)
            {
                this.debug = (ParserDebug)dgb;
                DebugLevel = 1;
            }

            if (file != null)
            {
                currentFile = file;
            }
            lexer = new DelphiScanner(tr);
            lexer.yyLexDebugLevel = DebugLevel;

            Object parserRet;

            try
            {
                parserRet = yyparse(lexer);
            }
            catch (MultiDelphiException yye)
            {
                yyerror(yye.Message);
                return(null);
            }
            catch (Exception e)
            {
                ErrorOutput.WriteLine(e.Message + " in line " + lexer.yylineno());
                ErrorOutput.WriteLine(e.StackTrace);
                return(null);
            }
            finally {
                lexer = null;
            }

            if (!(parserRet is TranslationUnit))
            {
                throw new ParserException("Non-final node derived from parsing:" + parserRet.GetType());
            }

            return((TranslationUnit)parserRet);
        }
Esempio n. 6
0
        public void ScanTokenAndProvideInfoAboutItTest()
        {
            DelphiScanner target = new DelphiScanner(new StringReader("Identifier  AndWhiteSpace"));

            TokenInfo tokenInfo = new TokenInfo();

            int state          = 0; // TODO: Initialize to an appropriate value
            int state_expected = 0; // TODO: Initialize to an appropriate value

            bool expected = true;
            bool actual;

            actual = target.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state);

            Assert.AreEqual(state_expected, state, "state_ScanTokenAndProvideInfoAboutIt_expected was not set correctly.");
            Assert.AreEqual(expected, actual, "VisualStudio.Delphi.Language.DelphiScanner.ScanTokenAndProvideInfoAboutIt did not" +
                            " return the expected value.");

            Assert.AreEqual(TokenType.Identifier, tokenInfo.Type, "TokenInfo.TokenType did not return expected value");
            Assert.AreEqual(0, tokenInfo.StartIndex, "TokenInfo.StartIndex did not return expected value");
            Assert.AreEqual(9, tokenInfo.EndIndex, "TokenInfo.EndIndex did not return expected value");

            actual = target.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state);

            Assert.AreEqual(state_expected, state, "state_ScanTokenAndProvideInfoAboutIt_expected was not set correctly.");
            Assert.AreEqual(expected, actual, "VisualStudio.Delphi.Language.DelphiScanner.ScanTokenAndProvideInfoAboutIt did not" +
                            " return the expected value.");

            Assert.AreEqual(TokenType.WhiteSpace, tokenInfo.Type, "TokenInfo.TokenType did not return expected value");
            Assert.AreEqual(10, tokenInfo.StartIndex, "TokenInfo.StartIndex did not return expected value");
            Assert.AreEqual(11, tokenInfo.EndIndex, "TokenInfo.EndIndex did not return expected value");

            actual = target.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state);

            Assert.AreEqual(state_expected, state, "state_ScanTokenAndProvideInfoAboutIt_expected was not set correctly.");
            Assert.AreEqual(expected, actual, "VisualStudio.Delphi.Language.DelphiScanner.ScanTokenAndProvideInfoAboutIt did not" +
                            " return the expected value.");

            Assert.AreEqual(TokenType.Identifier, tokenInfo.Type, "TokenInfo.TokenType did not return expected value");
            Assert.AreEqual(12, tokenInfo.StartIndex, "TokenInfo.StartIndex did not return expected value");
            Assert.AreEqual(24, tokenInfo.EndIndex, "TokenInfo.EndIndex did not return expected value");
        }
Esempio n. 7
0
        public void ConstructorTest1()
        {
            TextReader @in = null;

            DelphiScanner target = new DelphiScanner(@in);
        }
Esempio n. 8
0
 public void ConstructorTest()
 {
     DelphiScanner target = new DelphiScanner();
 }
Esempio n. 9
0
        public void VSOneLineAtATimeCommentTest()
        {
            string        lInputData           = "Ientifier{\\\\\\\\\\\\\\\\";
            string        lExpectedTokenString = "{\\\\\\\\\\\\\\\\";
            DelphiScanner target = new DelphiScanner(new StringReader(lInputData));

            TokenInfo tokenInfo = new TokenInfo();

            int state          = 0; // TODO: Initialize to an appropriate value
            int state_expected = 1; // TODO: Initialize to an appropriate value

            bool expected = true;
            bool actual;

            actual = target.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state);
            actual = target.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state);

            Assert.AreEqual(state_expected, state, "state_ScanTokenAndProvideInfoAboutIt_expected was not set correctly.");
            Assert.AreEqual(expected, actual, "VisualStudio.Delphi.Language.DelphiScanner.ScanTokenAndProvideInfoAboutIt did not" +
                            " return the expected value.");

            Assert.AreEqual(TokenType.Comment, tokenInfo.Type, "TokenInfo.TokenType did not return expected value");
            Assert.AreEqual(lExpectedTokenString, lInputData.Substring(tokenInfo.StartIndex, tokenInfo.EndIndex - tokenInfo.StartIndex + 1),
                            "TokenInfo.StartIndex and TokenInfo.EndIndex did not return expected value");

            /*
             * This is the next line that may apear in a comment
             *
             */
            lInputData           = " this Should all be a comment ";
            lExpectedTokenString = " this Should all be a comment ";

            target.SetSource(lInputData, 0);
            actual = target.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state);

            Assert.AreEqual(state_expected, state, "state_ScanTokenAndProvideInfoAboutIt_expected was not set correctly.");
            Assert.AreEqual(expected, actual, "VisualStudio.Delphi.Language.DelphiScanner.ScanTokenAndProvideInfoAboutIt did not" +
                            " return the expected value.");

            Assert.AreEqual(TokenType.Comment, tokenInfo.Type, "TokenInfo.TokenType did not return expected value");
            Assert.AreEqual(lExpectedTokenString, lInputData.Substring(tokenInfo.StartIndex, tokenInfo.EndIndex - tokenInfo.StartIndex + 1),
                            "TokenInfo.StartIndex and TokenInfo.EndIndex did not return expected value");

            /*
             * Lets put some imbeaded comments in
             *
             */
            lInputData           = " (*imbead a comment*)  all is comments // even here";
            lExpectedTokenString = " (*imbead a comment*)  all is comments // even here";

            target.SetSource(lInputData, 0);
            actual = target.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state);

            Assert.AreEqual(state_expected, state, "state_ScanTokenAndProvideInfoAboutIt_expected was not set correctly.");
            Assert.AreEqual(expected, actual, "VisualStudio.Delphi.Language.DelphiScanner.ScanTokenAndProvideInfoAboutIt did not" +
                            " return the expected value.");

            Assert.AreEqual(TokenType.Comment, tokenInfo.Type, "TokenInfo.TokenType did not return expected value");
            Assert.AreEqual(lExpectedTokenString, lInputData.Substring(tokenInfo.StartIndex, tokenInfo.EndIndex - tokenInfo.StartIndex + 1),
                            "TokenInfo.StartIndex and TokenInfo.EndIndex did not return expected value");

            /*
             * End this comments now
             *
             */
            lInputData           = " End here }  nexttoken";
            lExpectedTokenString = " End here }";

            state_expected = 0;


            target.SetSource(lInputData, 0);
            actual = target.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state);

            Assert.AreEqual(state_expected, state, "state_ScanTokenAndProvideInfoAboutIt_expected was not set correctly.");
            Assert.AreEqual(expected, actual, "VisualStudio.Delphi.Language.DelphiScanner.ScanTokenAndProvideInfoAboutIt did not" +
                            " return the expected value.");

            Assert.AreEqual(TokenType.Comment, tokenInfo.Type, "TokenInfo.TokenType did not return expected value");
            Assert.AreEqual(lExpectedTokenString, lInputData.Substring(tokenInfo.StartIndex, tokenInfo.EndIndex - tokenInfo.StartIndex + 1),
                            "TokenInfo.StartIndex and TokenInfo.EndIndex did not return expected value");
        }