;; nyacc/lang/c99/c99-02.test		-*- scheme -*-
;;
;; Copyright (C) 2016-2017 Matthew R. Wette
;; 
;; Copying and distribution of this file, with or without modification,
;; are permitted in any medium without royalty provided the copyright
;; notice and this notice are preserved.  This file is offered as-is,
;; without any warranty.

;; test C99 parser in code mode

(define-module (c99-02)
  #:use-module (nyacc lang c99 parser)
  #:use-module (test-suite lib))

(define incs '("exam.d"))

(define (parse-string str)
  (with-input-from-string str
    (lambda ()
      (parse-c99 #:inc-dirs incs #:mode 'code))))

(define (parse-file file)
  (with-input-from-file file
    (lambda ()
      (parse-c99 #:inc-dirs incs #:mode 'code))))

;; parser test
(with-test-prefix "nyacc/c99-02, code mode"

  ;; Get a simple statement to parse.
  (pass-if "simple"
    (let ((sx (parse-string "int x;")))
      (equal? sx
	      '(trans-unit
		(decl (decl-spec-list (type-spec (fixed-type "int")))
		      (init-declr-list (init-declr (ident "x"))))))))

  ;; parse with include file ;; needs work ?
  (pass-if "include, code mode"
    (let* ((sx (parse-file "exam.d/ex01.c")))
      (pair? sx)))

  ;; parse massive comments file
  (pass-if "comments, wanted and unwanted"
    (let* ((sx (parse-file "exam.d/ex02.c")))
      (pair? sx)))

  ;; try to get all C99 in one file
  (pass-if "most of C99 in one file"
    (let* ((sx (parse-file "exam.d/ex05.c")))
      (pair? sx)))

  ;; 

  )
(display "TODO: nyacc/c99-02: test typedef inside function scope\n")

;; --- last line ---
