public void ReportInvalidNumber_GivenLongNumber() { var text = @"var a = [124654541321534154153151]"; var expectedDiagnostic = "The number 124654541321534154153151 isn't valid <int>"; Assert.That(text, Has.Diagnostics(expectedDiagnostic)); }
public void Report_UnexpectedToken() { var text = @"1 [(] + 4"; var expectedDiagnostic = "ERROR: Unexpected token <OpenParensToken>, expected <EofToken>"; Assert.That(text, Has.Diagnostics(expectedDiagnostic)); }
public void ReportUnexpectedToken_GivenEmptyExpression() { var text = @"[]"; var expectedDiagnostic = "ERROR: Unexpected token <EofToken>, expected <IdentifierToken>"; Assert.That(text, Has.Diagnostics(expectedDiagnostic)); }
public void ReportUndefinedUnaryOperator_GivenUnaryExpression() { var text = @"[+]true"; var expectedDiagnostic = "Unary operator '+' is not defined for type <bool>"; Assert.That(text, Has.Diagnostics(expectedDiagnostic)); }
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)); }
public void ReportUndefinedVariable_GivenUndefinedVariable() { var text = @"[a] + 10"; var expectedDiagnostic = "Variable 'a' doesn't exist"; Assert.That(text, Has.Diagnostics(expectedDiagnostic)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }