I've been playing around with Racket and Rackunit. I'm in the process of porting my little static site generator to Racket and writing unit tests and ran into this weird problem.
#lang racket
(require (planet esilkensen/yaml:2:1))
(require rackunit)
(define some-yaml
(string->yaml " - name : ding"))
(check-equal? some-yaml '(#hash(("name" . "ding"))) )
Can someone explain to me why the test fails with the following output:
Welcome to DrRacket, version 5.3.3 [3m].
Language: racket; memory limit: 128 MB.
--------------------
FAILURE
name: check-equal?
location: (#<path:/home/ding/Documents/racket/blog-generator> 7 0 119 45)
expression: (check-equal? x '(#hash(("name" . "ding"))))
actual: (#hash(("name" . "ding")))
expected: (#hash(("name" . "ding")))
It has to do with mutable vs immutable hashes. The following test will pass:
(check-equal? some-yaml (list (make-hash '(("name" . "ding")))))
where make-hash is the mutable hash constructor.
As Eli mentioned, it's confusing that mutable and immutable hashes print the same way, so I've reported a bug.
'#hash(...) in your source code is read as an immutable hash, but it looks like the library produces a mutable one. (And it's unfortunate that they're both printed the same.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With