From eb5f5dd3f3f408ccb9f62303f031efc8454fd5de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Wed, 13 Jul 2022 11:47:22 +0200 Subject: Resolve #ifdef, #ifndef, #else, #endif. --- tests/test/cpp/preprocessor2.scm | 76 ++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 14 deletions(-) (limited to 'tests/test/cpp') diff --git a/tests/test/cpp/preprocessor2.scm b/tests/test/cpp/preprocessor2.scm index 5e1bb736..b4825907 100644 --- a/tests/test/cpp/preprocessor2.scm +++ b/tests/test/cpp/preprocessor2.scm @@ -592,17 +592,11 @@ (lex "x")))))) +;; TODO ;; resolve-h-file ;; resolve-q-file -;; handle-pragma ;; include -;; if -;; else -;; ifdef -;; ifndef -;; elif - (call-with-values (lambda () @@ -803,13 +797,6 @@ LISTING(..\\listing.dir) " e)))))) )) -;; TODO -;; if -;; else -;; ifdef -;; ifndef -;; elif - (test-group "Next token matches?" (test-assert "Zero tokens never match" (not (next-token-matches? (const #t) '()))) @@ -990,3 +977,64 @@ debug(\"X = %d\\n\", x); showlist(The first, second, and third items.); report(x>y, \"x is %d but y is %d\", x, y); ")))) + + + +(test-group "Conditionals" + (test-group "ifdef" + (test-equal "#ifdef on non-defined" + (lex "") + (run " +#ifdef X +x +#endif")) + + (test-equal "#ifdef on defined" + (lex "x") + (run " +#define X +#ifdef X +x +#endif"))) + + (test-group "ifndef" + (test-equal "#ifndef on non-defined" + (lex "x") + (run " +#ifndef X +x +#endif")) + + (test-equal "#ifndef on defined" + (lex "") + (run " +#define X +#ifndef X +x +#endif +"))) + + (test-group "else" + (test-equal "else from active to inactive" + (lex "1") + (run " +#ifndef X +1 +#else +2 +#endif")) + + (test-equal "else from inactive to active" + (lex "2") + (run " +#ifdef X +1 +#else +2 +#endif"))) + +;; TODO +;; if +;; elif + + ) -- cgit v1.2.3