endbasic 0.11.1

The EndBASIC programming language - CLI
' EndBASIC
' Copyright 2024 Julio Merino
'
' Licensed under the Apache License, Version 2.0 (the "License"); you may not
' use this file except in compliance with the License.  You may obtain a copy
' of the License at:
'
'     http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
' WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
' License for the specific language governing permissions and limitations
' under the License.

' Tests for expressions that result in compilation errors.
'
' This is separate from exprs.bas and must be run through the REPL (as opposed
' to running as a script) because these expressions trigger compilation errors
' and abort execution right away.  The REPL compiles each statement separately
' so it can print those errors.
'
' These used to be done in core/src/eval.rs when the expressions were fully
' evaluated within the AST.  However, since we moved to bytecode execution,
' the evaluation of expressions relies on the parser, the compiler, and the
' execution engine.  As a result, it is much simpler to validate these cases
' with an integration test.

PRINT ">>> Symbol references"
PRINT x: PRINT ERRMSG

PRINT ">>> Logical operations"
' These tests just make sure that the expression evaluator delegates to the
' Value operations for each expression operator to essentially avoid duplicating
' all those tests.  We do this by triggering errors and rely on the fact that
' their messages are different for every operation.
PRINT FALSE AND 0
PRINT FALSE OR 0
PRINT FALSE XOR 0
PRINT NOT 0.0

PRINT ">>> Relational operations"
' These tests just make sure that the expression evaluator delegates to the
' Value operations for each expression operator to essentially avoid duplicating
' all those tests.  We do this by triggering errors and rely on the fact that
' their messages are different for every operation.
PRINT FALSE = 0
PRINT FALSE <> 0
PRINT FALSE < 0
PRINT FALSE <= 0
PRINT FALSE > 0
PRINT FALSE >= 0

PRINT ">>> Arithmetic operations"
' These tests just make sure that the expression evaluator delegates to the
' Value operations for each expression operator to essentially avoid duplicating
' all those tests.  We do this by triggering errors and rely on the fact that
' their messages are different for every operation.
PRINT FALSE + 0
PRINT FALSE - 0
PRINT FALSE * 0
PRINT FALSE / 0
PRINT FALSE MOD 0
PRINT FALSE ^ 0
PRINT -FALSE

PRINT ">>> Operations and variables"
PRINT 3 = 7 + TRUE

PRINT ">>> Array accesses"
DIM x(2, 4) AS INTEGER
PRINT x#(1, 3)
PRINT y$(3, 4)
PRINT a(1)
CLEAR

PRINT ">>> Simple function calls"
PRINT MAX$(2, 5, 3)
PRINT UNKNOWN(2)
CLEAR

PRINT ">>> Calling of non-functions"
z = 0
PRINT z()
PRINT PRINT()