srfi-38-test.scm 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. (test-begin "srfi-38" 8)
  2. (define circ1 (list 1 2 3))
  3. (define circ2 (list 1 2 (list 'a 'b 'c) (vector "gsoc" "kawa") 3))
  4. (define circ3 (cons 'a 'b))
  5. (define a (cons 'a 'z))
  6. (define b (cons 'b a))
  7. (define c (cons 'c b))
  8. (define circ4 (list c b a))
  9. (define (long-line n) (if (= n 0) '() (cons 'a (long-line (- n 1)))))
  10. (define edge1 (long-line 500))
  11. (define *list* '(b c d e f g h i j k l m n o p q u r s t v w x y))
  12. (define (long-shared res n)
  13. (if (= n 24)
  14. res
  15. (list (long-shared (cons (list-ref *list* (- n 1)) res)
  16. (+ n 1))
  17. res)))
  18. (define circ5 (long-shared (cons 'a 'z) 10))
  19. (define (make-write-string form)
  20. (call-with-output-string
  21. (lambda (s) (write-shared form s))))
  22. (set-car! (cdr circ1) circ1)
  23. (test-equal "#0=(1 #0# 3)"
  24. (make-write-string circ1))
  25. (set-car! (cdr circ2) circ2)
  26. (test-equal "#0=(1 #0# (a b c) #(\"gsoc\" \"kawa\") 3)"
  27. (make-write-string circ2))
  28. (set-car! (cddr (caddr circ2)) (caddr circ2))
  29. (test-equal "#0=(1 #0# #1=(a b #1#) #(\"gsoc\" \"kawa\") 3)"
  30. (make-write-string circ2))
  31. (vector-set! (cadddr circ2) 1 (cadddr circ2))
  32. (test-equal "#0=(1 #0# #1=(a b #1#) #2=#(\"gsoc\" #2#) 3)"
  33. (make-write-string circ2))
  34. (set-car! (cdr circ2) 2)
  35. (test-equal "(1 2 #0=(a b #0#) #1=#(\"gsoc\" #1#) 3)"
  36. (make-write-string circ2))
  37. (set-cdr! circ3 circ3)
  38. (test-equal "#0=(a . #0#)"
  39. (make-write-string circ3))
  40. (test-equal "((c . #0=(b . #1=(a . z)) #0# #1#)"
  41. (make-write-string circ4))
  42. ;; Stress test.
  43. (make-write-string edge1)
  44. ;; Testing both position markers > 9 and the hash table.
  45. (test-equal
  46. "(((((((((((((((x . #0=(w . #1=(v . #2=(t . #3=(s . #4=(r . #5=(u . #6=(q . #7=(p . #8=(o . #9=(n . #10=(m . #11=(l . #12=(k . #13=(a . z)))))))))))))) #0#) #1#) #2#) #3#) #4#) #5#) #6#) #7#) #8#) #9#) #10#) #11#) #12#) #13#)"
  47. (make-write-string circ5))
  48. (test-end)