{"size": 1551, "ext": "rktl", "max_stars_repo_path": "share/pkgs/mzcom/tests/test.rktl", "max_stars_repo_name": "takikawa/racket-ppa", "max_stars_repo_stars_event_min_datetime": "2018-07-29T04:13:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T16:11:17.000Z", "max_issues_repo_path": "share/pkgs/mzcom/tests/test.rktl", "max_issues_repo_name": "takikawa/racket-ppa", "max_issues_repo_issues_event_min_datetime": "2017-08-25T20:26:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T17:48:40.000Z", "max_forks_repo_path": "share/pkgs/mzcom/tests/test.rktl", "max_forks_repo_name": "takikawa/racket-ppa", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 10, "max_issues_count": 15, "max_forks_count": null, "avg_line_length": 25.85, "max_line_length": 77, "alphanum_fraction": 0.6557059961}
; test.rkt for MzCOM
; requires MysterX to be installed

(require mysterx)
(define mzcom (cci/progid "MzCOM.MzObj"))

(define num-errors 0)
(define (add-error!)
  (set! num-errors (add1 num-errors)))

(define (run . s)
  (apply com-invoke mzcom s))

(define (mzeval s)
  (run "Eval" s))

(print-struct #t)

; should show an About box
(printf "You should see the About box\n")
(run "About")

; tests whether Eval returns sensible result
(if (string=? (mzeval "(+ 20 22)")
		  "42")
    (printf "1st Eval test ok\n")
    (begin
      (add-error!)
      (fprintf (current-error-port) "1st Eval test failed\n")))

(mzeval "(define x 42)")
; tests whether preceding definition really holds
(if (string=? "42" (mzeval "x"))
    (printf "define test ok\n")
    (begin
      (add-error!)
      (fprintf (current-error-port) "define test failed\n")))

(printf "Resetting environment\n")
(run "Reset") ; removes binding for x

; tests for removal of binding
(with-handlers
 ([void (lambda (exn) (printf "2nd Eval test looks ok\nexn was: ~a\n" exn))])
 (mzeval "x") ; binding for x missing
 (add-error!)
 (fprintf (current-error-port) "2nd Eval test failed\n"))

; tests if a Scheme error results in a COM error
(with-handlers
 ([void (lambda (exn) (printf "3rd Eval test looks ok\nexn was: ~a\n" exn))])
 (mzeval "(+ 'foo 42)") ; should raise Scheme error
 (add-error!)
 (fprintf (current-error-port) "3rd Eval test failed\n"))

(when (> num-errors 0)
      (fprintf (current-error-port) "There were ~a errors.\n" num-errors))

(printf "End of MzCOM tests.\n")
