aboutsummaryrefslogtreecommitdiff
path: root/tests/test/cpp.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-06-30 01:48:21 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-07-07 21:17:22 +0200
commit9a5cdde850ba5a6185d5524ebf8acc25dfd00762 (patch)
treef7b3ce6bbce8266cc3fd40f05ef0280990cc7cbe /tests/test/cpp.scm
parentChar parse tests, these were broken by strings. (diff)
downloadcalp-9a5cdde850ba5a6185d5524ebf8acc25dfd00762.tar.gz
calp-9a5cdde850ba5a6185d5524ebf8acc25dfd00762.tar.xz
C parser add basic float support.
Diffstat (limited to 'tests/test/cpp.scm')
-rw-r--r--tests/test/cpp.scm87
1 files changed, 77 insertions, 10 deletions
diff --git a/tests/test/cpp.scm b/tests/test/cpp.scm
index 2c51f616..32072932 100644
--- a/tests/test/cpp.scm
+++ b/tests/test/cpp.scm
@@ -15,13 +15,16 @@
;; __asm__ always has strings as arguments
(test-skip "__asm__")
-;; not implemented
-(test-skip "Token concatenation")
-;; not implemented
-(test-skip "Floating point numbers")
+
+;; Lexer produces garbage when attempted. Fixing this would also fix cast
+;; operations.
+(test-skip "Float in infix expression")
;; order of operation is wrong, leading to an incorrect result
(test-skip "Cast with operation")
+;; not implemented
+(test-skip "Token concatenation")
+
;; A string follewed by a macro (which expands to a string)
;; should be concatenated. This is however not yet implemented
(test-skip "Implicit concatenation of string and macro")
@@ -278,13 +281,77 @@
(test-equal '0 (run form))))
(test-group "Floating point numbers"
- (let ((form "4.9406564584124654e-324"))
- (test-equal '(float (base-10 "4") (base-10)) (lex form))
- (test-equal '0 (run form)))
- (let ((form "1.7976931348623157e+308"))
- (test-equal '() (lex form))
- (test-equal '0 (run form))))
+ (test-group "Diffent forms"
+ (test-group "No decimal point, exponent, no suffix"
+ (let ((form "10e10"))
+ (test-equal '(float (float-integer (base-10 "10"))
+ (exponent (base-10 "10")))
+ (lex form))
+ (test-equal 10e10 (run form))))
+
+ (test-group "No decimal point, negative exponent"
+ (let ((form "10e-10"))
+ (test-equal '(float (float-integer (base-10 "10"))
+ (exponent "-" (base-10 "10")))
+ (lex form))
+ (test-equal 10e-10 (run form))))
+
+ (test-group "No decimal point, exponent and suffix"
+ (let ((form "10e10L"))
+ (test-equal '(float (float-integer (base-10 "10"))
+ (exponent (base-10 "10"))
+ (float-suffix "L"))
+ (lex form))
+ (test-equal '(as-type (long double) 10e10)
+ (run form))))
+
+ (test-group "Leading period, no exponent or suffix"
+ (let ((form ".1"))
+ (test-equal '(float (float-decimal (base-10 "1"))) (lex form))
+ (test-equal 0.1 (run form))))
+
+ (test-group "Trailing period, no exponent or suffix"
+ (let ((form "1."))
+ (test-equal '(float (float-integer (base-10 "1"))) (lex form))
+ (test-equal 1.0 (run form)))))
+
+
+ (test-group "Negative float"
+ (let ((form "-1.0"))
+ (test-equal '(prefix (prefix-operator "-")
+ (float (float-integer (base-10 "1"))
+ (float-decimal (base-10 "0"))))
+ (lex form))
+ (test-equal '(- 1.0) (run form))))
+
+
+
+ (test-group "Real world examples"
+ (let ((form "4.9406564584124654e-324"))
+ (test-equal '(float (float-integer (base-10 "4"))
+ (float-decimal (base-10 "9406564584124654"))
+ (exponent "-" (base-10 "324")))
+ (lex form))
+ (test-equal 4.9406564584124654e-324 (run form)))
+
+ (let ((form "1.7976931348623157e+308"))
+ (test-equal '(float (float-integer (base-10 "1"))
+ (float-decimal (base-10 "7976931348623157"))
+ (exponent "+" (base-10 "308")))
+ (lex form))
+ (test-equal 1.7976931348623157e+308 (run form))))
+
+ (test-group "Float in infix expression"
+ (test-group "Simple case"
+ (let ((form "1. + .1"))
+ (test-equal '(infix (float (float-integer (base-10 "1")))
+ (operator "+")
+ (float (float-decimal (base-10 "1"))))
+ (lex form))
+ (test-equal '(+ 1.0 0.1) (run form))))
+ ;; (test-group "Complicated case")
+ ))
(test-group "Typecasts"