aboutsummaryrefslogtreecommitdiff
path: root/tests/test/cpp
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-07-11 19:03:05 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-07-11 19:03:05 +0200
commitd155b5c67893bc7607234b3240bef260d2f1b81c (patch)
treef9d8d21d77500060316ca0d06be0f38823d865f5 /tests/test/cpp
parentFix most of expand##. (diff)
downloadcalp-d155b5c67893bc7607234b3240bef260d2f1b81c.tar.gz
calp-d155b5c67893bc7607234b3240bef260d2f1b81c.tar.xz
Fix whitespace for rest args.
Diffstat (limited to 'tests/test/cpp')
-rw-r--r--tests/test/cpp/preprocessor2.scm86
1 files changed, 60 insertions, 26 deletions
diff --git a/tests/test/cpp/preprocessor2.scm b/tests/test/cpp/preprocessor2.scm
index 9349d290..9ad1a726 100644
--- a/tests/test/cpp/preprocessor2.scm
+++ b/tests/test/cpp/preprocessor2.scm
@@ -14,7 +14,6 @@
:use-module (c lex2))
-(test-skip "Stringify __VA_ARGS__")
(test-skip "__LINE__ through macro")
(test-skip "__LINE__ standalone")
@@ -120,7 +119,7 @@
(test-group "Two values in parameter list"
(let ((containing remaining nls (parse-parameter-list (lex "(x, y)"))))
(test-equal (list (lex "x")
- (lex "y"))
+ (lex " y"))
containing)
(test-equal '() remaining)
(test-equal 0 nls)))
@@ -128,8 +127,8 @@
(test-group "Three values in parameter list"
(let ((containing remaining nls (parse-parameter-list (lex "(x, y, z)"))))
(test-equal (list (lex "x")
- (lex "y")
- (lex "z"))
+ (lex " y")
+ (lex " z"))
containing)
(test-equal '() remaining)
(test-equal 0 nls)))
@@ -144,7 +143,7 @@
(test-group "Two values, one of which is a paretheseed pair"
(let ((containing remaining nls
(parse-parameter-list (lex "(x, (y, z))"))))
- (test-equal (list (lex "x") (lex "(y, z)"))
+ (test-equal (list (lex "x") (lex " (y, z)"))
containing)
(test-equal '() remaining)
(test-equal 0 nls))))
@@ -642,48 +641,83 @@ __LINE__")))))
(test-equal (lex "ab") (expand## (lex "a ## b")))
)
-(test-equal "Token concatenation in function like macro"
- (lex "ab")
+(define (run str)
(remove-noexpand
(handle-preprocessing-tokens
(make-environment)
- (tokenize "
+ (tokenize str))))
+
+
+(test-equal "Token concatenation in function like macro"
+ (lex "ab")
+ (run "
#define f() a ## b
-f()"))))
+f()"))
(test-equal "token concatentanion in object like macro"
(lex "ab")
- (remove-noexpand
- (handle-preprocessing-tokens
- (make-environment)
- (tokenize "
+ (run "
#define x a ## b
-x"))))
+x"))
(test-equal "Token concatenation with parameter"
(lex "ab")
- (remove-noexpand
- (handle-preprocessing-tokens
- (make-environment)
- (tokenize "
+ (run "
#define f(x) x ## b
-f(a)"))))
+f(a)"))
+
+
;; 6.10.3.3 p. 4
-(test-equal
+(test-equal "x ## y"
(lex "\"x ## y\"")
- (drop-whitespace-both
- (remove-noexpand
- (handle-preprocessing-tokens
- (make-environment)
- (tokenize "
+ (run "
#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)")))))
+join(x, y)"))
+
+(test-equal "__VA_ARGS__ split its arguments"
+ (lex "1")
+ (run "
+#define fst(x, y) x
+#define f(...) fst(__VA_ARGS__)
+f(1,2)
+"))
+
+(test-equal
+ "Stringify __VA_ARGS__"
+ (lex "\"1,2\"")
+ (run "
+#define g(...) #__VA_ARGS__
+g(1,2)
+"))
+
+(test-equal "__VA_ARGS__ keep whitespace"
+ (lex "x, y")
+ (run "
+#define args(...) __VA_ARGS__
+args(x, y)
+"))
+
+(test-equal "Concat with __VA_ARGS__"
+ (lex "fx,y")
+ (run "
+#define wf(...) f ## __VA_ARGS__
+wf(x,y)
+"))
+
+(test-equal
+ "Concat with __VA_ARGS__ (keeping whitespace)"
+ (lex "fx, y")
+ (run "
+#define wf(...) f ## __VA_ARGS__
+wf(x, y)
+"))
+
;; __LINE__
;; #line