-
-
Save shkmr/d2885e9e23ac4a2fbdf4651e755b72fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use gauche.test) | |
(use lang.c.parser) | |
(define (test-c-tokenize str expect) | |
(test* (string-append "\"" str "\"") expect (c-tokenize (string->list str)))) | |
(test-section "CARM 2.3 tokens") | |
(test-c-tokenize "forwhile;" '((ident forwhile) |;|)) | |
(test-c-tokenize "forx;" '((ident forx) |;|)) | |
(test-c-tokenize "foox;" '((ident foox) |;|)) | |
(test-c-tokenize "xfor;" '((ident xfor) |;|)) | |
(test-c-tokenize "foo;" '((ident foo) |;|)) | |
(test-c-tokenize "b>x;" '((ident b) > (ident x) |;|)) | |
(test-c-tokenize "b->x;" '((ident b) -> (ident x) |;|)) | |
(test-c-tokenize "b--x;" '((ident b) -- (ident x) |;|)) | |
(test-c-tokenize "b---x;" '((ident b) -- - (ident x) |;|)) | |
(test-section "integer constants") | |
(test-c-tokenize "0L;" '((literal long-int "0L") |;|)) | |
(test-c-tokenize "0l;" '((literal long-int "0l") |;|)) | |
(test-c-tokenize "0U;" '((literal unsigned-int "0U") |;|)) | |
(test-c-tokenize "0u;" '((literal unsigned-int "0u") |;|)) | |
(test-c-tokenize "1234;" '((literal int "1234") |;|)) | |
(test-c-tokenize "012;" '((literal int "012" ) |;|)) | |
(test-c-tokenize "0x12;" '((literal int "0x12") |;|)) | |
(test-section "character constants") | |
(test-c-tokenize "'a';" '((char (#\a)) |;|)) | |
(test-c-tokenize "'A';" '((char (#\A)) |;|)) | |
(test-c-tokenize "' ';" '((char (#\space)) |;|)) | |
(test-c-tokenize "'?';" '((char (#\?)) |;|)) | |
(test-c-tokenize "'\\r';" '((char (#\return)) |;|)) | |
(test-c-tokenize "'\\0';" '((char (#\null)) |;|)) | |
(test-c-tokenize "'\"';" '((char (#\")) |;|)) | |
(test-c-tokenize "'\\377';" '((char (#\xff)) |;|)) | |
(test-c-tokenize "'%';" '((char (#\%)) |;|)) | |
(test-c-tokenize "'\\23';" '((char (#\x13)) |;|)) | |
(test-c-tokenize "'8';" '((char (#\8)) |;|)) | |
(test-c-tokenize "'\\\\';" '((char (#\\)) |;|)) | |
(test-c-tokenize "'ABCD';" '((char (#\A #\B #\C #\D)) |;|)) | |
(test-section "floating point constants") | |
(test-c-tokenize "0.;" '((literal double "0." ) |;|)) | |
(test-c-tokenize "3e1;" '((literal double "3e1" ) |;|)) | |
(test-c-tokenize "3.14159;" '((literal double "3.14159") |;|)) | |
(test-c-tokenize ".0;" '((literal double ".0" ) |;|)) | |
(test-c-tokenize "1.0E-3;" '((literal double "1.0E-3" ) |;|)) | |
(test-c-tokenize "1e-3;" '((literal double "1e-3" ) |;|)) | |
(test-c-tokenize "1.0;" '((literal double "1.0" ) |;|)) | |
(test-c-tokenize "0.00034;" '((literal double "0.00034") |;|)) | |
(test-c-tokenize "2e+9;" '((literal double "2e+9" ) |;|)) | |
(test-c-tokenize "1.0f;" '((literal float "1.0f" ) |;|)) | |
(test-c-tokenize "1.0e67L;" '((literal long-double "1.0e67L") |;|)) | |
(test-c-tokenize "1.37E+6L;" '((literal long-double "1.37E+6L") |;|)) | |
(test-c-tokenize "0E1L;" '((literal long-double "0E1L" ) |;|)) | |
(test-c-tokenize "0x1.0p1;" '((literal double "0x1.0p1") |;|)) | |
(test-c-tokenize "0x1.0;" '((literal double "0x1.0") |;|)) | |
(test-section "string constants") | |
(test-c-tokenize "\"abra\"" '((string "abra"))) | |
(test-c-tokenize "\"\";" '((string "") |;|)) | |
(test-c-tokenize "\"\\\"\";" '((string "\"") |;|)) | |
(test-c-tokenize "\"Copyright 2000 \\\nTexas Instruments. \"" | |
'((string "\"Copyright 2000 \\\nTexas Instruments. \""))) | |
(test-section "other") | |
(test-c-tokenize "X++Y;" '((ident X) ++ (ident Y) |;|)) | |
(test-c-tokenize "-12ul;" '(- (literal unsigned-long-int "12ul") |;|)) | |
(test-c-tokenize "x**2;" '((ident x) * * (literal int "2") |;|)) | |
(test-c-tokenize "A*=B;" '((ident A) *= (ident B) |;|)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment