aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-07-11 18:34:48 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-07-11 18:34:48 +0200
commitd1b87ade120f8d01d86ed6e5c9661f36f78751b7 (patch)
treea84e69b087a7d823270aeba02f5cae74041b2ddf /tests
parentRewrite handel-preprocessing-tokens. (diff)
downloadcalp-d1b87ade120f8d01d86ed6e5c9661f36f78751b7.tar.gz
calp-d1b87ade120f8d01d86ed6e5c9661f36f78751b7.tar.xz
Fix most of expand##.
Diffstat (limited to 'tests')
-rw-r--r--tests/test/cpp/preprocessor2.scm83
1 files changed, 81 insertions, 2 deletions
diff --git a/tests/test/cpp/preprocessor2.scm b/tests/test/cpp/preprocessor2.scm
index cbc62edd..9349d290 100644
--- a/tests/test/cpp/preprocessor2.scm
+++ b/tests/test/cpp/preprocessor2.scm
@@ -14,6 +14,11 @@
:use-module (c lex2))
+(test-skip "Stringify __VA_ARGS__")
+(test-skip "__LINE__ through macro")
+(test-skip "__LINE__ standalone")
+
+
;; arbitrary tokens useful in tests for checking that values are returned correctly
(define before (car (lex "before")))
(define after (car (lex "after")))
@@ -214,7 +219,16 @@
'macro-expand-error
(expand#
m (build-parameter-map
- m (list (lex "x")))))))
+ m (list (lex "x"))))))
+
+ (let ((m (function-like-macro
+ identifier: "f"
+ identifier-list: '()
+ variadic?: #t
+ body: (lex "# __VA_ARGS__"))))
+ (test-equal "Stringify __VA_ARGS__"
+ (lex "\"10, 20\"")
+ (expand# m (build-parameter-map m (list (lex "10, 20")))))))
;; TODO expand-join
;; token ## token2
@@ -594,7 +608,7 @@ f(10)
#define x 1
x"))))
-(test-equal "__LINE__"
+(test-equal "__LINE__ through macro"
(lex "5")
(drop-whitespace-both
(remove-noexpand
@@ -606,6 +620,71 @@ x"))))
x // 5"))
)))
+(test-equal "__LINE__ standalone"
+ (lex "5")
+ (drop-whitespace-both
+ (remove-noexpand
+ (handle-preprocessing-tokens (make-environment)
+ (tokenize " // 1
+// 2
+// 3
+// 4
+__LINE__")))))
+
+
+
+(define expand## (@@ (c preprocessor2) expand##))
+
+(test-group "expand##"
+ (test-error 'cpp-error (expand## (lex "a ##")))
+ (test-error 'cpp-error (expand## (lex "## a")))
+ (test-error 'cpp-error (expand## (lex "##")))
+ (test-equal (lex "ab") (expand## (lex "a ## b")))
+ )
+
+(test-equal "Token concatenation in function like macro"
+ (lex "ab")
+ (remove-noexpand
+ (handle-preprocessing-tokens
+ (make-environment)
+ (tokenize "
+#define f() a ## b
+f()"))))
+
+(test-equal "token concatentanion in object like macro"
+ (lex "ab")
+ (remove-noexpand
+ (handle-preprocessing-tokens
+ (make-environment)
+ (tokenize "
+#define x a ## b
+x"))))
+
+(test-equal "Token concatenation with parameter"
+ (lex "ab")
+ (remove-noexpand
+ (handle-preprocessing-tokens
+ (make-environment)
+ (tokenize "
+#define f(x) x ## b
+f(a)"))))
+
+
+;; 6.10.3.3 p. 4
+(test-equal
+ (lex "\"x ## y\"")
+ (drop-whitespace-both
+ (remove-noexpand
+ (handle-preprocessing-tokens
+ (make-environment)
+ (tokenize "
+#define hash_hash # ## #
+#define mkstr(a) # a
+#define in_between(a) mkstr(a)
+#define join(c, d) in_between(c hash_hash d)
+
+join(x, y)")))))
+
;; __LINE__
;; #line
;; #undef