Exemplo n.º 1
0
        protected void AssertCompilerReturnsMessage(
            string input,
            CompilerMessageId messageId,
            CompilerMessageType messageType,
            string[] messageParameters)
        {
            // Arrange
            var compiler    = new ThriftCompiler();
            var parserInput = ParserInput.FromString(input);

            // Act
            var result = compiler.Compile(parserInput.GetStream());

            // Assert
            var message = result.Messages.FirstOrDefault(
                m => m.MessageType == messageType && m.MessageId == messageId);

            Assert.True(message != null, $"No {messageType.ToString().ToLower()} messages were returned from the compiler");

            if (parserInput.LineNumber != null)
            {
                Assert.Equal(parserInput.LineNumber, message.LineNumber);
                Assert.Equal(parserInput.StartPosition, message.StartPosition);
                Assert.Equal(parserInput.EndPosition, message.EndPosition);
            }

            if (messageParameters?.Length > 0)
            {
                var expectedMessage = string.Format(
                    CompilerMessages.Get(messageId), messageParameters);
                Assert.Equal(expectedMessage, message.Message);
            }
        }
Exemplo n.º 2
0
        public void Compile_SetsNamespace(string input, string expected)
        {
            // Arrange
            var compiler = new ThriftCompiler();

            // Act
            var result = compiler.Compile(input.ToStream());

            // Assert
            Assert.Equal(expected, result.Document.CSharpNamespace);
        }
Exemplo n.º 3
0
        protected void AssertCompilerDoesNotReturnAnyMessages(string input)
        {
            // Arrange
            var compiler    = new ThriftCompiler();
            var parserInput = ParserInput.FromString(input);

            // Act
            var result = compiler.Compile(parserInput.GetStream());

            // Assert
            Assert.Empty(result.Messages);
        }
Exemplo n.º 4
0
        public void Compile_RecognizedNamespaceScope_DoesNotReportError(string scope)
        {
            // Arrange
            var compiler = new ThriftCompiler();
            var input    = $"namespace {scope} MyNamespace";

            // Act
            var result = compiler.Compile(input.ToStream());

            // Assert
            Assert.Empty(result.Errors);
        }
Exemplo n.º 5
0
        public void Compile_MultipleNamespacesSpecified_IgnoresNonCSharpNamespaces()
        {
            // Arrange
            var    compiler = new ThriftCompiler();
            string input    =
                @"namespace csharp Thrift.Net.Examples
namespace delphi SomeOtherNamespace";

            // Act
            var result = compiler.Compile(input.ToStream());

            // Assert
            Assert.Equal("Thrift.Net.Examples", result.Document.CSharpNamespace);
        }
Exemplo n.º 6
0
        protected void AssertCompilerDoesNotReturnMessage(
            string input,
            CompilerMessageId messageId)
        {
            // Arrange
            var compiler    = new ThriftCompiler();
            var parserInput = ParserInput.FromString(input);

            // Act
            var result = compiler.Compile(parserInput.GetStream());

            // Assert
            var message = result.Messages.FirstOrDefault(m => m.MessageId == messageId);

            Assert.True(
                message == null,
                $"Message Id '{messageId}' should not have been reported");
        }
Exemplo n.º 7
0
        protected void AssertCompilerReturnsMessage(
            string input,
            CompilerMessageId messageId,
            CompilerMessageType messageType,
            string[] messageParameters)
        {
            // Arrange
            var compiler    = new ThriftCompiler();
            var parserInput = ParserInput.FromString(input);

            // Act
            var result = compiler.Compile(parserInput.GetStream());

            // Assert
            var message = result.Messages.FirstOrDefault(
                m => m.MessageType == messageType && m.MessageId == messageId);

            Assert.True(message != null, $"No {messageType.ToString().ToLower()} messages were returned from the compiler");

            // Although we know that message cannot be null because of the assert on
            // the previous line, check for null here because the lgtm check isn't
            // smart enough to realise that
            if (message != null)
            {
                if (parserInput.LineNumber != null)
                {
                    Assert.Equal(parserInput.LineNumber, message.LineNumber);
                    Assert.Equal(parserInput.StartPosition, message.StartPosition);
                    Assert.Equal(parserInput.EndPosition, message.EndPosition);
                }

                if (messageParameters?.Length > 0)
                {
                    var expectedMessage = string.Format(
                        CompilerMessages.Get(messageId), messageParameters);
                    Assert.Equal(expectedMessage, message.Message);
                }
            }
        }