{"size": 1723, "ext": "rktl", "max_stars_repo_path": "pkgs/racket-test-core/tests/racket/shared-tests.rktl", "max_stars_repo_name": "lkh01/racket", "max_stars_repo_stars_event_min_datetime": "2018-07-05T21:18:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-04T14:48:37.000Z", "max_issues_repo_path": "pkgs/racket-test-core/tests/racket/shared-tests.rktl", "max_issues_repo_name": "lkh01/racket", "max_issues_repo_issues_event_min_datetime": "2017-05-10T07:33:20.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-19T15:49:46.000Z", "max_forks_repo_path": "pkgs/racket-test-core/tests/racket/shared-tests.rktl", "max_forks_repo_name": "lkh01/racket", "max_forks_repo_forks_event_min_datetime": "2016-04-25T11:47:57.000Z", "max_forks_repo_forks_event_max_datetime": "2017-05-09T14:52:48.000Z"}
{"max_stars_count": 4, "max_issues_count": 9, "max_forks_count": 3, "avg_line_length": 30.7678571429, "max_line_length": 67, "alphanum_fraction": 0.5130586187}
;; This file has to work for both "shared.rkt" and "advanced.rkt"

;; this writes values to strings and compares the strings
;; to implements an equal? predicate that works for cyclic
;; structures.

(define (gs v)
  (let ([p (open-output-string)])
    (begin
      (write v p)
      (get-output-string p))))
(define (x s)
  (read (open-input-string s)))
(define (stest expect expression)
  (test
   (gs expect)
   (let ([shared-tester (lambda (x) (gs (eval x)))]) shared-tester)
   expression))

(stest '(1 2) '(shared ([x (list 1 2)]) x))
(stest #(1 2) '(shared ([x (vector 1 2)]) x))
(stest (box 1) '(shared ([x (box 1)]) x))
(stest '(1) '(shared ([x (cons 1 null)]) x))
(stest (mcons 1 null) '(shared ([x (mcons 1 null)]) x))

(stest (x "#1=(#1# 1)") '(shared ([x (list x 1)]) x))
(stest (x "#2=#(#2# 1)") '(shared ([x (vector x 1)]) x))
(stest (x "#2=#(#2# 1)") '(shared ([x (vector-immutable x 1)]) x))
(stest (x "#3=#&#3#") '(shared ([x (box x)]) x))
(stest (x "#3=#&#3#") '(shared ([x (box-immutable x)]) x))
(stest (x "#4=(#4#)") '(shared ([x (cons x null)]) x))
(stest (x "#5=(1 . #5#)") '(shared ([x (cons 1 x)]) x))
(stest (let ([x (mcons 1 #f)]) 
         (begin (set-mcdr! x x) 
                x))
       '(shared ([x (mcons 1 x)]) x))

(stest (x "#11=(#11#)") '(shared ([x `(,x)]) x))

(stest 1 '(shared ([x (list 1 x p)]
                   [p (lambda () x)])
             (car ((caddr x)))))

(define-struct s (a b))
(shared ([x (make-s 17 x)])
  (begin
    (test #t s? x)
    (test 17 s-a x)
    (test #t eq? x (s-b x))))

(define-struct shared-test-ds-no-fields ())
(stest (make-shared-test-ds-no-fields)
       '(shared ((-4- 11) 
                 (-8- (make-shared-test-ds-no-fields)))
          -8-))
