From d1b87ade120f8d01d86ed6e5c9661f36f78751b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 11 Jul 2022 18:34:48 +0200 Subject: Fix most of expand##. --- tests/test/cpp/preprocessor2.scm | 83 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-) (limited to 'tests') 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 -- cgit v1.2.3