1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-01 15:00:38 +00:00

Add CONST tests

This commit is contained in:
Matthew Kilgore 2022-09-24 12:16:02 -04:00
parent 59dd8d3c51
commit a7cd7884a9
28 changed files with 350 additions and 0 deletions

View file

@ -0,0 +1,3 @@
' The ASDF operator doesn't exist
CONST foobar = 1 ASDF 2

View file

@ -0,0 +1,4 @@
Invalid CONST expression.9
Caused by (or after):
LINE 3:CONST FOOBAR = 1 ASDF 2

View file

@ -0,0 +1,3 @@
' The NOT is missing an argument
CONST foobar = 1 OR NOT

View file

@ -0,0 +1,4 @@
Invalid CONST expression.2
Caused by (or after):
LINE 3:CONST FOOBAR = 1 OR NOT

View file

@ -0,0 +1,3 @@
' The type postfix is used to avoid issue #192
CONST foobar = NOT 2! 2

View file

@ -0,0 +1,4 @@
Invalid CONST expression.4
Caused by (or after):
LINE 3:CONST FOOBAR = NOT 2E+0,2! 2

View file

@ -0,0 +1,3 @@
' Expression is a single invalid identifier
CONST foobar = OR

View file

@ -0,0 +1,4 @@
Invalid CONST expression.2
Caused by (or after):
LINE 3:CONST FOOBAR = OR

View file

@ -0,0 +1,80 @@
$CONSOLE:ONLY
CONST const__OR = 1 OR 2
CONST const__AND = 3 AND 1
CONST const__NOT = NOT 2
CONST const__XOR = 2 XOR 3
CONST const__EQV = 10 EQV 5
CONST const__IMP = 20 IMP 50
CONST const__mod = 20 MOD 3
CONST const__add = 2 + 3
CONST const__sub = 2 - 3
CONST const__div = 6 / 3
CONST const__idiv = 7 \ 3
CONST const__mult = 7 * 20
CONST const_pow = 3 ^ 10
CONST const__negate = -20
CONST const__eq = 2 = 2
CONST const__neq = 2 <> 3
CONST const__neq2 = 2 >< 3
CONST const__leq = 2 <= 3
CONST const__leq2 = 2 =< 3
CONST const__geq = 2 >= 3
CONST const__geq2 = 2 => 3
CONST const__gt = 2 > 3
CONST const__lt = 2 < 3
' The left side which has no parens to indicate order should still equal the
' right side which has parens to enforce order.
CONST const__oporder1 = (2 ^ 2 * 2) = ((2 ^ 2) * 2)
CONST const__oporder2 = (2 ^ 2 + 2) = ((2 ^ 2) + 2)
CONST const__oporder3 = (NOT 2 + 3) = (NOT (2 + 3))
CONST const__oporder4 = (-2 ^ 2) <> (-(2 ^ 2)) ' WRONG, should be equal, negation is applied incorrectly
CONST const__oporder5 = (NOT 2 ^ 3) = (NOT (2 ^ 3))
CONST const__oporder6 = (3 * 6 / 2) = ((3 * 6) / 2)
CONST const__oporder7 = (3 * 10 \ 3) = ((3 * 10) \ 3)
' Many levels of parens
CONST const__parens = (2 ^ (3 * (4 - (2 - (10 / (20 / 2))))))
PRINT const__OR
PRINT const__AND
PRINT const__NOT
PRINT const__XOR
PRINT const__EQV
PRINT const__IMP
PRINT const__mod
PRINT const__add
PRINT const__sub
PRINT const__div
PRINT const__idiv
PRINT const__mult
PRINT const_pow
PRINT const__negate
PRINT const__eq
PRINT const__neq
PRINT const__neq2
PRINT const__leq
PRINT const__leq2
PRINT const__geq
PRINT const__geq2
PRINT const__gt
PRINT const__lt
PRINT const__oporder1
PRINT const__oporder2
PRINT const__oporder3
PRINT const__oporder4
PRINT const__oporder5
PRINT const__oporder6
PRINT const__oporder7
PRINT const__parens
SYSTEM

View file

@ -0,0 +1,31 @@
3
1
-3
1
-16
-5
2
5
-1
2
2
140
59049
-20
-1
-1
-1
-1
-1
0
0
0
-1
-1
-1
-1
-1
-1
-1
-1
512

View file

@ -0,0 +1,107 @@
$CONSOLE:ONLY
_DEST _CONSOLE
' This list comprises all of the math functions usable in CONST
CONST const_PI = _PI
CONST const_ACOS = _ACOS(.2)
CONST const_ASIN = _ASIN(.2)
CONST const_ARCSEC = _ARCSEC(.2)
CONST const_ARCCOT = _ARCCOT(.2)
CONST const_ARCCSC = _ARCCSC(.2)
CONST const_SECH = _SECH(.2)
CONST const_CSCH = _CSCH(.2)
CONST const_COTH = _COTH(.2)
CONST const_COS = COS(.2)
CONST const_SIN = SIN(.2)
CONST const_TAN = TAN(.2)
CONST const_LOG = LOG(.2)
CONST const_EXP = EXP(.2)
CONST const_ATN = ATN(.2)
CONST const_D2R = _D2R(.2)
CONST const_D2G = _D2G(.2)
CONST const_R2D = _R2D(.2)
CONST const_R2G = _R2G(.2)
CONST const_G2D = _G2D(.2)
CONST const_G2R = _G2R(.2)
CONST const_ABS = ABS(2)
CONST const_SGN = SGN(-20)
CONST const_INT = INT(20.2)
CONST const_ROUND = _ROUND(20.2)
CONST const_CEIL = _CEIL(20.2)
CONST const_FIX = FIX(20.5)
CONST const_SEC = _SEC(2)
CONST const_CSC = _CSC(2)
CONST const_COT = _COT(2)
' CONST const_ASC = ASC("a") ' Bugged, not implemented
CONST const__RGB32 = _RGB32(2, 3, 4)
CONST const__RGBA32 = _RGBA32(2, 3, 4, 5)
CONST const__RGB32_1 = _RGB32(2)
CONST const__RGB32_2 = _RGB32(2, 3)
CONST const__RGB32_4 = _RGB32(2, 3, 4, 5)
CONST const__RGB = _RGB(2, 3, 4, 2)
CONST const__RGBA = _RGBA(2, 3, 4, 2, 2)
CONST const__RED32 = _RED32(22)
CONST const__GREEN32 = _GREEN32(22)
CONST const__BLUE32 = _BLUE32(22)
CONST const__ALPHA32 = _ALPHA32(22)
CONST const__RED = _RED(22, 0)
CONST const__GREEN = _GREEN(22, 0)
CONST const__BLUE = _BLUE(22, 0)
CONST const__ALPHA = _ALPHA(2222, 0)
CONST const_SQR = SQR(20)
CONST const_ROOT = 20 ROOT 3
' The answers have to be within the allowed range, to account for floating point
' differences.
PRINT "PI: "; 3.141592653589793 * .999999 < const_PI; 3.141592653589793 * 1.000001 > const_PI
PRINT "ACOS: "; 1.369438406004566 * .999999 < const_ACOS; 1.369438406004566 * 1.000001 > const_ACOS
PRINT "ASIN: "; .2013579207903308 * .999999 < const_ASIN; .2013579207903308 * 1.000001 > const_ASIN
PRINT "ARCSEC: "; .2013579207903308 * .999999 < const_ARCSEC; .2013579207903308 * 1.000001 > const_ARCSEC
PRINT "ARCCOT: "; 1.373400766945016 * .999999 < const_ARCCOT; 1.373400766945016 * 1.000001 > const_ARCCOT
PRINT "ARCCSC: "; .2013579207903308 * .999999 < const_ARCCSC; .2013579207903308 * 1.000001 > const_ARCCSC
PRINT "SECH: "; .9803279976447253 * .999999 < const_SECH; .9803279976447253 * 1.000001 > const_SECH
PRINT "CSCH: "; 4.966821568814516 * .999999 < const_CSCH; 4.966821568814516 * 1.000001 > const_CSCH
PRINT "COTH: "; 1.44280551632034 * .999999 < const_COTH; 1.44280551632034 * 1.000001 > const_COTH
PRINT "COS: "; .9800665778412416 * .999999 < const_COS; .9800665778412416 * 1.000001 > const_COS
PRINT "SIN: "; .1986693307950612 * .999999 < const_SIN; .1986693307950612 * 1.000001 > const_SIN
PRINT "TAN: "; .2027100355086725 * .999999 < const_TAN; .2027100355086725 * 1.000001 > const_TAN
PRINT "EXP: "; 1.22140275816017 * .999999 < const_EXP; 1.22140275816017 * 1.000001 > const_EXP
PRINT "ATN: "; .1973955598498808 * .999999 < const_ATN; .1973955598498808 * 1.000001 > const_ATN
PRINT "D2R: "; .0034906585 * .999999 < const_D2R; .0034906585 * 1.000001 > const_D2R
PRINT "D2G: "; .22222222222 * .999999 < const_D2G; .22222222222 * 1.000001 > const_D2G
PRINT "R2D: "; 11.4591559 * .999999 < const_R2D; 11.4591559 * 1.000001 > const_R2D
PRINT "R2G: "; .0031415926 * .999999 < const_R2G; .0031415926 * 1.000001 > const_R2G
PRINT "G2D: "; .18 * .999999 < const_G2D; .18 * 1.000001 > const_G2D
PRINT "G2R: "; 12.7323954474 * .999999 < const_G2R; 12.7323954474 * 1.000001 > const_G2R
PRINT "CSC: "; 1.099750170294616 * .999999 < const_CSC; 1.099750170294616 * 1.000001 > const_CSC
PRINT "SQR: "; 4.47213595499958 * .999999 < const_SQR; 4.47213595499958 * 1.000001 > const_SQR
PRINT "ROOT: "; 2.714417616594907 * .999999 < const_ROOT; 2.714417616594907 * 1.000001 > const_ROOT
PRINT "LOG: "; -1.6094379124341 * .999999 > const_LOG; -1.6094379124341 * 1.000001 < const_LOG
PRINT "SEC: "; -2.402997961722381 * .999999 > const_SEC; -2.402997961722381 * 1.000001 < const_SEC
PRINT "COT: "; -.4576575543602858 * .999999 > const_COT; -.4576575543602858 * 1.000001 < const_COT
PRINT "ABS: "; const_ABS
PRINT "SGN: "; const_SGN
PRINT "INT: "; const_INT
PRINT "ROUND: "; const_ROUND
PRINT "CEIL: "; const_CEIL
PRINT "FIX: "; const_FIX
PRINT "ASC: "; const_ASC
PRINT "RGB32: "; HEX$(const__RGB32)
PRINT "RGBA32: "; HEX$(const__RGBA32)
PRINT "1: "; HEX$(const__RGB32_1)
PRINT "2: "; HEX$(const__RGB32_2)
PRINT "4: "; HEX$(const__RGB32_4)
PRINT "RGB: "; HEX$(const__RGB)
PRINT "RGBA: "; HEX$(const__RGBA)
PRINT "RED32: "; HEX$(const__RED32)
PRINT "GREEN32: "; const__GREEN32
PRINT "BLUE32: "; const__BLUE32
PRINT "ALPHA32: "; const__ALPHA32
PRINT "RED: "; const__RED
PRINT "GREEN: "; const__GREEN
PRINT "BLUE: "; const__BLUE
PRINT "ALPHA: "; const__ALPHA
SYSTEM

View file

@ -0,0 +1,48 @@
PI: -1 -1
ACOS: -1 -1
ASIN: -1 -1
ARCSEC: -1 -1
ARCCOT: -1 -1
ARCCSC: -1 -1
SECH: -1 -1
CSCH: -1 -1
COTH: -1 -1
COS: -1 -1
SIN: -1 -1
TAN: -1 -1
EXP: -1 -1
ATN: -1 -1
D2R: -1 -1
D2G: -1 -1
R2D: -1 -1
R2G: -1 -1
G2D: -1 -1
G2R: -1 -1
CSC: -1 -1
SQR: -1 -1
ROOT: -1 -1
LOG: -1 -1
SEC: -1 -1
COT: -1 -1
ABS: 2
SGN: -1
INT: 20
ROUND: 20
CEIL: 21
FIX: 20
ASC: 0
RGB32: FF020304
RGBA32: 5020304
1: FF020202
2: 3020202
4: 5020304
RGB: 0
RGBA: 0
RED32: 0
GREEN32: 0
BLUE32: 22
ALPHA32: 0
RED: 0
GREEN: 0
BLUE: 0
ALPHA: 255

View file

@ -0,0 +1,3 @@
' Can't use NOT with an invalid identifier
CONST foobar = NOT OR

View file

@ -0,0 +1,4 @@
Expected variable/value after 'OR'
Caused by (or after):
LINE 3:CONST FOOBAR = NOT OR

View file

@ -0,0 +1,3 @@
' NOT cannot be applied to a string
CONST foobar = NOT "string"

View file

@ -0,0 +1,4 @@
Invalid CONST expression.6
Caused by (or after):
LINE 3:CONST FOOBAR = NOT "string",6

View file

@ -0,0 +1,3 @@
' _OFFSET values can't be used in CONST expressions
CONST foobar = 234%&

View file

@ -0,0 +1,4 @@
Cannot use _OFFSET symbols after numbers
Caused by (or after):
LINE 3:

View file

@ -0,0 +1,3 @@
' The second OR is missing the last argument
CONST foobar = 1 OR 2 OR

View file

@ -0,0 +1,4 @@
Invalid CONST expression.8
Caused by (or after):
LINE 3:CONST FOOBAR = 1 OR 2 OR

View file

@ -0,0 +1,3 @@
' We can't add strings and integers together
CONST foobar = "asdf" + 20

View file

@ -0,0 +1,4 @@
Invalid CONST expression.11
Caused by (or after):
LINE 3:CONST FOOBAR = "asdf",4 + 20

View file

@ -0,0 +1,3 @@
' Strings cannot be subtracted
CONST foobar = "asdf" - "asdf2"

View file

@ -0,0 +1,4 @@
Invalid CONST expression.12
Caused by (or after):
LINE 3:CONST FOOBAR = "asdf",4 - "asdf2",5

View file

@ -0,0 +1,3 @@
' Because UNDEFINED does not exist this should produce an error
CONST foobar = 20 OR UNDEFINED

View file

@ -0,0 +1,4 @@
Invalid CONST expression.15
Caused by (or after):
LINE 3:CONST FOOBAR = 20 OR UNDEFINED

View file

@ -0,0 +1,3 @@
' Because UNDEFINED does not exist this should produce an error
CONST foobar = UNDEFINED OR 2

View file

@ -0,0 +1,4 @@
Invalid CONST expression.4
Caused by (or after):
LINE 3:CONST FOOBAR = UNDEFINED OR 2