public void returns_CommentReport()
        {
            //Arrange
            var bytes = Encoding.ASCII.GetBytes("//Hello");

            //Act
            var msg = _sut.Parse(bytes);

            Assert.IsAssignableFrom <CommentReport>(msg);
        }
Ejemplo n.º 2
0
        private void TestError(string[] text)
        {
            string textString = string.Join(Environment.NewLine, text);
            var    parser     = new CommentParser("//", "/*", "*/", "#region", "#endregion");

            Assert.Throws <ParseException> (() => parser.Parse(textString));
        }
        private void AssertCorrectlyParsed(string input, string expectedHeader)
        {
            var parser          = new CommentParser("//", "/*", "*/", "#region", "#endregion");
            var extractedHeader = parser.Parse(input);

            Assert.That(extractedHeader, Is.EqualTo(expectedHeader));
        }
Ejemplo n.º 4
0
        public static PgDatabase LoadDatabaseSchema(TextReader reader, string charsetName, bool outputIgnoredStatements, bool ignoreSlonyTriggers)
        {
            var database = new PgDatabase();

            var statement = GetWholeStatement(reader);

            while (statement != null)
            {
                if (PatternCreateSchema.IsMatch(statement))
                {
                    CreateSchemaParser.Parse(database, statement);
                }
                else if (PatternDefaultSchema.IsMatch(statement))
                {
                    database.SetDefaultSchema(PatternDefaultSchema.Matches(statement)[0].Groups[1].Value);
                }
                else if (PatternCreateTable.IsMatch(statement))
                {
                    CreateTableParser.Parse(database, statement);
                }
                else if (PatternAlterTable.IsMatch(statement))
                {
                    AlterTableParser.Parse(database, statement, outputIgnoredStatements);
                }
                else if (PatternCreateSequence.IsMatch(statement))
                {
                    CreateSequenceParser.Parse(database, statement);
                }
                else if (PatternAlterSequence.IsMatch(statement))
                {
                    AlterSequenceParser.Parse(database, statement, outputIgnoredStatements);
                }
                else if (PatternCreateIndex.IsMatch(statement))
                {
                    CreateIndexParser.Parse(database, statement);
                }
                else if (PatternCreateView.IsMatch(statement))
                {
                    CreateViewParser.Parse(database, statement);
                }
                else if (PatternAlterView.IsMatch(statement))
                {
                    AlterViewParser.Parse(database, statement, outputIgnoredStatements);
                }
                else if (PatternCreateTrigger.IsMatch(statement))
                {
                    CreateTriggerParser.Parse(database, statement, ignoreSlonyTriggers);
                }
                else if (PatternCreateFunction.IsMatch(statement))
                {
                    CreateFunctionParser.Parse(database, statement);
                }
                else if (PatternComment.IsMatch(statement))
                {
                    CommentParser.Parse(database, statement, outputIgnoredStatements);
                }
                else if (PatternSelect.IsMatch(statement) ||
                         PatternInsertInto.IsMatch(statement) ||
                         PatternUpdate.IsMatch(statement) ||
                         PatternDeleteFrom.IsMatch(statement)) /* we just ignore these statements*/ } {
Ejemplo n.º 5
0
 public override void DoCommand(IBinaryFile output, IList <IBinaryFile> inputs, LinkerScriptState state)
 {
     if (state.cur_section.HasData)
     {
         byte[] darr = state.data[state.cur_section].ToArray();
         var    dstr = Encoding.ASCII.GetString(darr);
         cp.Parse(dstr, output, inputs, state);
     }
 }
Ejemplo n.º 6
0
            public void Should_Return_Null_If_Node_Cannot_Be_Parsed()
            {
                // Given
                var parser = new CommentParser();
                var node   = @"<test>Hello World</test>".CreateXmlNode();

                // When
                var result = parser.Parse(node);

                // Then
                Assert.Null(result);
            }
Ejemplo n.º 7
0
            public void Can_Parse_InlineCode_Comment()
            {
                // Given
                var parser = new CommentParser();
                var node   = @"<c>Hello World</c>".CreateXmlNode();

                // When
                var result = parser.Parse(node);

                // Then
                Assert.NotNull(result);
                Assert.Equal(@"<c>Hello World</c>", XmlCommentRenderer.Render(result));
            }
Ejemplo n.º 8
0
            public void Can_Parse_Exception_Comment()
            {
                // Given
                var parser = new CommentParser();
                var node   = @"<exception cref=""SparrowException"">Hello World</exception>".CreateXmlNode();

                // When
                var result = parser.Parse(node);

                // Then
                Assert.NotNull(result);
                Assert.Equal(@"<exception cref=""SparrowException"">Hello World</exception>", XmlCommentRenderer.Render(result));
            }
Ejemplo n.º 9
0
            public void Can_Parse_TypeParamRef_Comment()
            {
                // Given
                var parser = new CommentParser();
                var node   = @"<typeparamref name=""test"" />".CreateXmlNode();

                // When
                var result = parser.Parse(node);

                // Then
                Assert.NotNull(result);
                Assert.Equal(@"<typeparamref name=""test"" />", XmlCommentRenderer.Render(result));
            }
Ejemplo n.º 10
0
            public void Can_Parse_TypeParam_Comment()
            {
                // Given
                var parser = new CommentParser();
                var node   = @"<typeparam name=""T"">Hello World</typeparam>".CreateXmlNode();

                // When
                var result = parser.Parse(node);

                // Then
                Assert.NotNull(result);
                Assert.Equal(@"<typeparam name=""T"">Hello World</typeparam>", XmlCommentRenderer.Render(result));
            }
Ejemplo n.º 11
0
            public void Can_Parse_See_Comment()
            {
                // Given
                var parser = new CommentParser();
                var node   = @"<see cref=""System.String"" />".CreateXmlNode();

                // When
                var result = parser.Parse(node);

                // Then
                Assert.NotNull(result);
                Assert.Equal(@"<see cref=""System.String"" />", XmlCommentRenderer.Render(result));
            }
Ejemplo n.º 12
0
            public void Can_Parse_Permission_Comment()
            {
                // Given
                var parser = new CommentParser();
                var node   = @"<permission cref=""System.Security.PermissionSet"">Hello World</permission>".CreateXmlNode();

                // When
                var result = parser.Parse(node);

                // Then
                Assert.NotNull(result);
                Assert.Equal(@"<permission cref=""System.Security.PermissionSet"">Hello World</permission>", XmlCommentRenderer.Render(result));
            }
        private void AssertThrowsException(
            string text,
            string commentStart      = "//",
            string blockCommentStart = "/*",
            string blockCommentEnd   = "*/",
            string regionStart       = "#region",
            string regionEnd         = "#endregion")
        {
            var textString = string.Join(Environment.NewLine, text);
            var parser     = new CommentParser(commentStart, blockCommentStart, blockCommentEnd, regionStart, regionEnd);

            Assert.That(() => parser.Parse(textString), Throws.InstanceOf <ParseException>());
        }
Ejemplo n.º 14
0
            public void Should_Preserve_Whitespace()
            {
                // Given
                var parser = new CommentParser();
                var node   = @"<value> <see cref=""System.String"" />\t<c>true</c></value>".CreateXmlNode();

                // When
                var result = parser.Parse(node);

                // Then
                Assert.NotNull(result);
                Assert.Equal(@"<value> <see cref=""System.String"" />\t<c>true</c></value>", XmlCommentRenderer.Render(result));
            }
Ejemplo n.º 15
0
        private void Test(string[] header, string[] text)
        {
            string headerString = string.Join(Environment.NewLine, header);
            string textString   = string.Join(Environment.NewLine, text);

            if (header.Length > 0 && text.Length > 0)
            {
                headerString += Environment.NewLine;
            }

            var parser = new CommentParser("//", "/*", "*/", "#region", "#endregion");

            Assert.AreEqual(headerString, parser.Parse(headerString + textString));
        }
        public void TestCommentParser()
        {
            var data2   = new ParsableData("//LineComment\n\n   ");
            var p2      = new CommentParser(data2);
            var result2 = p2.Parse();

            Console.WriteLine($"Result2: {result2}");

            var data3   = new ParsableData("/*\n * ein einfacher Block Comment\n *\n*/\n   ");
            var p3      = new CommentParser(data3);
            var result3 = p3.Parse();

            Console.WriteLine($"Result3: {result3}");
        }
Ejemplo n.º 17
0
        public void TestEndRegionWithSpace()
        {
            var header = new[]
            {
                "#Region ",
                "//This is a comment.",
                "#End Region"
            };

            string headerString = string.Join(Environment.NewLine, header);

            headerString += Environment.NewLine;

            var parser = new CommentParser("//", "/*", "*/", "#Region", "#End Region");

            Assert.AreEqual(headerString, parser.Parse(headerString));
        }
Ejemplo n.º 18
0
        public void Handle(RevisionAssignableCreatedMessage message)
        {
            var commentParser     = new CommentParser();
            var actions           = commentParser.Parse(Data.RevisionDto, Data.EntityId);
            var actionParamFiller = new ActionParameterFillerVisitor(Data.RevisionDto, Data.EntityId);

            var actionsToExecute = actions.ToArray();

            if (!actionsToExecute.Any())
            {
                MarkAsComplete();
                return;
            }

            _logger.InfoFormat("Processing comment. Revision ID: {0}", Data.RevisionDto.SourceControlID);

            foreach (var action in actionsToExecute)
            {
                action.Execute(actionParamFiller, command => Send(command), _logger);
            }

            MarkAsComplete();
        }
        /// <summary>
        /// Loads database schema from dump file.
        /// </summary>
        /// <param name="file">The path to the file which is loaded.</param>
        /// <param name="database">The database.</param>
        /// <param name="encodingName">Charset that should be used to read the file.</param>
        /// <param name="outputIgnoredStatements">Whether ignored statements should be included in the output.</param>
        /// <param name="ignoreSlonyTriggers">Indicates if slony triggers are ignored.</param>
        /// <returns>Database schema from dump file.</returns>
        public static PgDatabase LoadDatabaseSchema(string file, Database database, bool outputIgnoredStatements, bool ignoreSlonyTriggers, string encodingName = DefaultEncoding)
        {
            var          encoding   = Encoding.GetEncoding(encodingName);
            var          pgDatabase = new PgDatabase(database.Name, database.IgnoredSchemas.ToList());
            StreamReader reader     = null;

            using (reader = new StreamReader(file, encoding))
            {
                var statement = GetWholeStatement(reader);

                while (statement != null)
                {
                    if (PatternCreateSchema.Matches(statement).Count != 0)
                    {
                        CreateSchemaParser.Parse(pgDatabase, statement);
                    }
                    else if (PatternCreateRule.Matches(statement).Count != 0)
                    {
                        CreateRuleParser.Parse(pgDatabase, statement);
                    }
                    else if (PatternDefaultSchema.Matches(statement).Count != 0)
                    {
                        PatternDefaultSchema.Matches(statement);
                        pgDatabase.SetDefaultSchema(PatternDefaultSchema.Matches(statement)[0].Groups[1].ToString());
                    }
                    else if (PatternCreateTable.Matches(statement).Count != 0)
                    {
                        CreateTableParser.Parse(pgDatabase, statement);
                    }
                    else if (PatternAlterTable.Matches(statement).Count != 0)
                    {
                        AlterTableParser.Parse(pgDatabase, statement, outputIgnoredStatements);
                    }
                    else if (PatternCreateSequence.Matches(statement).Count != 0)
                    {
                        CreateSequenceParser.Parse(pgDatabase, statement);
                    }
                    else if (PatternAlterSequence.Matches(statement).Count != 0)
                    {
                        AlterSequenceParser.Parse(pgDatabase, statement);
                    }
                    else if (PatternCreateIndex.Matches(statement).Count != 0)
                    {
                        CreateIndexParser.Parse(pgDatabase, statement);
                    }
                    else if (PatternCreateView.Matches(statement).Count != 0)
                    {
                        CreateViewParser.Parse(pgDatabase, statement);
                    }
                    else if (PatternAlterView.Matches(statement).Count != 0)
                    {
                        AlterViewParser.Parse(pgDatabase, statement, outputIgnoredStatements);
                    }
                    else if (PatternCreateTrigger.Matches(statement).Count != 0)
                    {
                        CreateTriggerParser.Parse(pgDatabase, statement, ignoreSlonyTriggers);
                    }
                    else if (PatternCreateFunction.Matches(statement).Count != 0)
                    {
                        CreateFunctionParser.Parse(pgDatabase, statement);
                    }
                    else if (PatternPrivilegeGrant.Matches(statement).Count != 0)
                    {
                        PrivilegeParser.Parse(pgDatabase, statement, PgPrivilegeCommand.Grant);
                    }
                    else if (PatternPrivilegeRevoke.Matches(statement).Count != 0)
                    {
                        PrivilegeParser.Parse(pgDatabase, statement, PgPrivilegeCommand.Revoke);
                    }
                    else if (PatternCreateAggregate.Matches(statement).Count != 0)
                    {
                        CreateAggregateParser.Parse(pgDatabase, statement);
                    }
                    else if (PatternComment.Matches(statement).Count != 0)
                    {
                        CommentParser.Parse(pgDatabase, statement, outputIgnoredStatements);
                    }
                    else if (PatternCreateType.Matches(statement).Count != 0)
                    {
                        CreateTypeParser.Parse(pgDatabase, statement);
                    }
                    else if (PatternSelect.Matches(statement).Count != 0 ||
                             PatternInsertInto.Matches(statement).Count != 0 ||
                             PatternUpdate.Matches(statement).Count != 0 ||
                             PatternDeleteFrom.Matches(statement).Count != 0)
                    {
                        // these statements are ignored
                    }
                    else if (outputIgnoredStatements)
                    {
                        pgDatabase.AddIgnoredStatement(statement);
                    }
                    else
                    {
                        // these statements are ignored if outputIgnoredStatements is false
                    }

                    statement = GetWholeStatement(reader);
                }
            }

            return(pgDatabase);
        }