Esempio n. 1
0
        public void ReportInvalidNumber_GivenLongNumber()
        {
            var text = @"var a = [124654541321534154153151]";

            var expectedDiagnostic = "The number 124654541321534154153151 isn't valid <int>";

            Assert.That(text, Has.Diagnostics(expectedDiagnostic));
        }
Esempio n. 2
0
        public void Report_UnexpectedToken()
        {
            var text = @"1 [(] + 4";

            var expectedDiagnostic = "ERROR: Unexpected token <OpenParensToken>, expected <EofToken>";

            Assert.That(text, Has.Diagnostics(expectedDiagnostic));
        }
Esempio n. 3
0
        public void ReportUnexpectedToken_GivenEmptyExpression()
        {
            var text = @"[]";

            var expectedDiagnostic = "ERROR: Unexpected token <EofToken>, expected <IdentifierToken>";

            Assert.That(text, Has.Diagnostics(expectedDiagnostic));
        }
Esempio n. 4
0
        public void ReportUndefinedUnaryOperator_GivenUnaryExpression()
        {
            var text = @"[+]true";

            var expectedDiagnostic = "Unary operator '+' is not defined for type <bool>";

            Assert.That(text, Has.Diagnostics(expectedDiagnostic));
        }
Esempio n. 5
0
        public void ReportUndefinedBinaryOperator_GivenBinaryExpression()
        {
            var text = @"1 [&&] true";

            var expectedDiagnostic = "Binary operator '&&' is not defined for type <int> and <bool>";

            Assert.That(text, Has.Diagnostics(expectedDiagnostic));
        }
Esempio n. 6
0
        public void ReportUndefinedVariable_GivenUndefinedVariable()
        {
            var text = @"[a] + 10";

            var expectedDiagnostic = "Variable 'a' doesn't exist";

            Assert.That(text, Has.Diagnostics(expectedDiagnostic));
        }
Esempio n. 7
0
        public void ReportCannotConvert_GivenAssignmentExpressionWithIntVariableAndBoolValue()
        {
            var text = @"
            {
                var b = 10
                [b] = false
            }
            ";

            var expectedDiagnostic = "Cannot convert from <bool> to <int>";

            Assert.That(text, Has.Diagnostics(expectedDiagnostic));
        }
Esempio n. 8
0
        public void ReportCannotAssign_GivenAssignmentExpressionWithReadonlyVariable()
        {
            var text = @"
            {
                let y = 10
                y [=] 0
            }
            ";

            var expectedDiagnostic = "Variable 'y' is readonly and cannot be assigned to";

            Assert.That(text, Has.Diagnostics(expectedDiagnostic));
        }
Esempio n. 9
0
        public void NotEndUpInInfiniteLoop_GivenIncompleteStatement()
        {
            var text = @"
                {
                    [)][]
            ";

            var expectedDiagnostics = @"
                ERROR: Unexpected token <CloseParensToken>, expected <IdentifierToken>
                ERROR: Unexpected token <EofToken>, expected <CloseBraceToken>
            ";

            Assert.That(text, Has.Diagnostics(expectedDiagnostics));
        }
Esempio n. 10
0
        public void ReportCannotConvert_Given_IfStatement()
        {
            var text = @"
            {
                var x = 0
                if [10]
                    x = 10
            }
            ";

            var expectedDiagnostic = "Cannot convert from <int> to <bool>";

            Assert.That(text, Has.Diagnostics(expectedDiagnostic));
        }
Esempio n. 11
0
        public void ReportCannotConvert_ForUpperBound_GivenForStatement()
        {
            var text = @"
            {
                var x = 0
                var result = 0
                for x = 10 to [false]
                    result = result + x
            }
            ";

            var expectedDiagnostic = "Cannot convert from <bool> to <int>";

            Assert.That(text, Has.Diagnostics(expectedDiagnostic));
        }
Esempio n. 12
0
        public void ReportCannotConvert_Given_WhileStatement()
        {
            var text = @"
            {
                var x = 0
                var result = 0
                while [10]
                    result = result + x
            }
            ";

            var expectedDiagnostic = "Cannot convert from <int> to <bool>";

            Assert.That(text, Has.Diagnostics(expectedDiagnostic));
        }
Esempio n. 13
0
        public void ReportRedeclaration_Given_AssignmentExpression()
        {
            var text = @"
            {
                var x = 100
                var y = 10
                {
                    var x = 10
                }
                var [x] = 5
            }";

            var expectedDiagnostic = "Variable 'x' is already declared";

            Assert.That(text, Has.Diagnostics(expectedDiagnostic));
        }