aboutsummaryrefslogtreecommitdiff
path: root/tests/test/cpp.scm
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test/cpp.scm')
-rw-r--r--tests/test/cpp.scm54
1 files changed, 48 insertions, 6 deletions
diff --git a/tests/test/cpp.scm b/tests/test/cpp.scm
index f7b11296..2cb4266d 100644
--- a/tests/test/cpp.scm
+++ b/tests/test/cpp.scm
@@ -118,6 +118,48 @@
(integer (base-10 "2")))) (lex form))
(test-equal '(+ 2 2 2) (run form)))
+(test-group "Unary minus"
+ (test-group "Without space"
+ (let ((form "-1"))
+ (test-equal '(prefix (prefix-operator "-")
+ (integer (base-10 "1")))
+ (lex form))
+ (test-equal '(- 1) (run form))))
+
+ (test-group "With space"
+ (let ((form "- 1"))
+ (test-equal '(prefix (prefix-operator "-")
+ (integer (base-10 "1")))
+ (lex form))
+ (test-equal '(- 1) (run form))))
+
+ (test-group "Before variable"
+ (let ((form "-x"))
+ (test-equal '(prefix (prefix-operator "-")
+ (variable "x"))
+ (lex form))
+ (test-equal '(- x) (run form))))
+
+ (test-group "Before infix"
+ (let ((form "-x+3"))
+ (test-equal '(infix (prefix (prefix-operator "-")
+ (variable "x"))
+ (operator "+")
+ (integer (base-10 "3")))
+ (lex form))
+ (test-equal '(+ (- x) 3)
+ (run form))))
+
+ (test-group "Inside infix expression"
+ (let ((form "x+-3"))
+ (test-equal '(infix (variable "x")
+ (operator "+")
+ (prefix (prefix-operator "-")
+ (integer (base-10 "3"))))
+ (lex form))
+ (test-equal '(+ x (- 3)) (run form))))
+ )
+
@@ -224,6 +266,12 @@
(test-equal '(funcall _IOR (#{,}# 116 19 (struct-type termios))) (run form)))
+;; TODO concatenation rules
+;; #define __CONCAT(x,y) __CONCAT1(x,y)
+;; #define __CONCAT1(x,y) x ## y
+;; #define __CONSTANT_CFSTRINGS__ 1
+;; #define __COPYRIGHT(s) __IDSTRING(__CONCAT(__copyright_,__LINE__),s)
+
(test-group "Token concatenation"
(let ((form "x ## y"))
(test-equal '() (lex form))
@@ -426,9 +474,3 @@
(test-equal '(funcall __attribute__
(funcall __aligned__ x))
(run form)))
-
-;; TODO concatenation rules
-;; #define __CONCAT(x,y) __CONCAT1(x,y)
-;; #define __CONCAT1(x,y) x ## y
-;; #define __CONSTANT_CFSTRINGS__ 1
-;; #define __COPYRIGHT(s) __IDSTRING(__CONCAT(__copyright_,__LINE__),s)