(import semen types) (test-group "semen" ;;; Macro expansion (let ((sex-code '((defmacro (sum-var name a b c) `(var ,name ,(+ a b c))) (sum-var v 1 2 3)))) (test '((var v 6)) (semen-process sex-code))) (let ((sex-code-macro '((defmacro (x10 a) `(* 10 ,a)) (fn foo ((a int) (b int)) void (return (+ a (x10 b))))))) (test '((fn foo ((a int) (b int)) void (return (+ a (* 10 b))))) (semen-process sex-code-macro))) ;;; Docstrings are lifted out as comment forms sitting before the ;;; declaration. A string later in a body is left alone. (test '((comment "Greet NAME.") (fn greet ((name (* char))) void (printf "Hello %s!\n" name))) (semen-process '((fn greet ((name (* char))) void "Greet NAME." (printf "Hello %s!\n" name))))) (test '((comment "Public entry.") (pub fn main () int (return 0))) (semen-process '((pub fn main () int "Public entry." (return 0))))) ;; A prototype whose only "body" is a docstring stays a prototype (test '((comment "Forward.") (fn helper ((a int)) int)) (semen-process '((fn helper ((a int)) int "Forward.")))) (test '((fn f () void (g) "not a docstring")) (semen-process '((fn f () void (g) "not a docstring")))) ;; `;' comments before the string are skipped when looking for it, ;; and stay in the body (test '((comment "Kept.") (fn f () void (comment " note") (g))) (semen-process '((fn f () void (comment " note") "Kept." (g))))) (test '((comment "A 2D point.") (struct t-doc-pt ((x int) (y int)))) (semen-process '((struct t-doc-pt "A 2D point." ((x int) (y int)))))) (test '((x int) (y int)) (get-fields 't-doc-pt)) (test '((comment "RGB.") (enum t-doc-color (red green blue))) (semen-process '((enum t-doc-color "RGB." (red green blue))))) (test '((comment "Either.") (union t-doc-val ((i int) (f float)))) (semen-process '((union t-doc-val "Either." ((i int) (f float)))))) ;; Includes (test '((include stdio.h)) (semen-process '((include stdio.h)))) (test '((include stdio.h) (include stdlib.h)) (semen-process '((include stdio.h stdlib.h)))) (test '() (semen-process '((include)))) )