aboutsummaryrefslogtreecommitdiff
path: root/tests/test/cpp
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-07-03 12:36:35 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-07-07 21:31:32 +0200
commitcba504b509cd59f376063f6e590362b197147a2c (patch)
tree954e90b0053ab4c0247ef242607654c862d02e48 /tests/test/cpp
parentMerge branch 'new-object-system' into c-parser (diff)
downloadcalp-cba504b509cd59f376063f6e590362b197147a2c.tar.gz
calp-cba504b509cd59f376063f6e590362b197147a2c.tar.xz
Major work.
Diffstat (limited to 'tests/test/cpp')
-rw-r--r--tests/test/cpp/lex2.scm64
-rw-r--r--tests/test/cpp/preprocessor2.scm29
2 files changed, 93 insertions, 0 deletions
diff --git a/tests/test/cpp/lex2.scm b/tests/test/cpp/lex2.scm
new file mode 100644
index 00000000..0342e25c
--- /dev/null
+++ b/tests/test/cpp/lex2.scm
@@ -0,0 +1,64 @@
+(define-module (test cpp lex2)
+ :use-module (srfi srfi-64)
+ :use-module (srfi srfi-88)
+ :use-module (ice-9 peg)
+ :use-module (c lex2))
+
+
+(test-equal "Integer literal"
+ '(preprocessing-token (pp-number "10"))
+ (lex "10"))
+
+(test-equal "String literal"
+ '(preprocessing-token (string-literal "Hello"))
+ (lex "\"Hello\""))
+
+
+(test-equal "Mulitple tokens, including whitespace"
+ '((whitespace " ")
+ (preprocessing-token (pp-number "10"))
+ (whitespace " "))
+ (lex " 10 "))
+
+(test-equal "Char literal"
+ '(preprocessing-token (character-constant "a"))
+ (lex "'a'"))
+
+
+
+(test-equal "Comment inside string"
+ '(preprocessing-token (string-literal "Hel/*lo"))
+ (lex "\"Hel/*lo\""))
+
+(test-equal "#define line"
+ '((preprocessing-token (punctuator "#"))
+ (preprocessing-token (identifier "define"))
+ (whitespace " ")
+ (preprocessing-token (identifier "f"))
+ (preprocessing-token (punctuator "("))
+ (preprocessing-token (identifier "x"))
+ (preprocessing-token (punctuator ")"))
+ (whitespace " ")
+ (preprocessing-token (pp-number "10")))
+ (lex "#define f(x) 10"))
+
+
+
+(test-equal "Nested parenthesis"
+ '((preprocessing-token (identifier "f"))
+ (preprocessing-token (punctuator "("))
+ (preprocessing-token (pp-number "1"))
+ (preprocessing-token (punctuator ","))
+ (whitespace " ")
+ (preprocessing-token (punctuator "("))
+ (preprocessing-token (pp-number "2"))
+ (preprocessing-token (punctuator ","))
+ (whitespace " ")
+ (preprocessing-token (pp-number "3"))
+ (preprocessing-token (punctuator ")"))
+ (preprocessing-token (punctuator ","))
+ (whitespace " ")
+ (preprocessing-token (pp-number "4"))
+ (preprocessing-token (punctuator ")")))
+ (lex "f(1, (2, 3), 4)"))
+
diff --git a/tests/test/cpp/preprocessor2.scm b/tests/test/cpp/preprocessor2.scm
new file mode 100644
index 00000000..117b7e49
--- /dev/null
+++ b/tests/test/cpp/preprocessor2.scm
@@ -0,0 +1,29 @@
+(define-module (test cpp preprocessor2)
+ :use-module (srfi srfi-64)
+ :use-module (srfi srfi-88))
+
+
+
+(test-group "Tokens until End Of Line"
+ (call-with-values
+ (lambda ()
+ (tokens-until-eol
+ '(before (whitespace "\n") after)))
+ (lambda (bef aft)
+ (test-equal '(before) bef)
+ (test-equal '((whitespace "\n") after) aft))))
+
+
+
+(test-equal "Squeeze whitespace"
+ '(bef (whitespace " ") aft)
+ (squeeze-whitespace
+ '(bef
+ (whitespace a)
+ (whitespace b)
+ aft)))
+
+
+
+(test-equal "("
+ (stringify-token '(preprocessor-token (operator "("))))