2013-04-29 40 views
2

我一直在玩Racket和Rackunit。我正在將我的小靜態站點生成器移植到Racket,編寫單元測試,並遇到這個奇怪的問題。球拍哈希平等

#lang racket 
(require (planet esilkensen/yaml:2:1)) 
(require rackunit) 

(define some-yaml 
    (string->yaml " - name : ding")) 

(check-equal? some-yaml '(#hash(("name" . "ding")))) 

測試爲何失敗,出現以下輸出誰能給我解釋一下:

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"))) 

回答

4

它與可變與不可變哈希值有關。以下測試將通過:

(check-equal? some-yaml (list (make-hash '(("name" . "ding"))))) 

其中make-hash是可變的哈希構造函數。

正如Eli所說,令人困惑的是可變和不可變哈希以相同的方式打印,所以我報告了一個bug。

4

在你的源代碼'#hash(...)被讀作一個不變的哈希值,但它看起來像庫中產生可變的一個。 (它是不幸的,他們都打印相同的。)

3

我的猜測是,string->yaml結果是可變哈希,這是從來沒有相同的不變哈希(見the docs)。