【发布时间】:2018-11-19 19:28:15
【问题描述】:
我对 RackUnit 的 check-eq? 为相等的字符串返回 false 感到有些困惑。
这是我正在尝试的代码:
#lang racket
(require rackunit)
(define (get-output proc)
(let ([out (open-output-string)])
(parameterize ([current-output-port out])
(proc)
(get-output-string out))))
(define output (get-output
(λ () (display "hello"))))
(check-eq? output "hello")
运行此测试会导致此错误:
--------------------
. FAILURE
name: check-eq?
location: unsaved-editor:14:0
actual: "hello"
expected: "hello"
--------------------
我以为我理解了eq? 的含义,但似乎我仍然缺少一些东西……为什么会失败?
我知道get-output-string 调用了bytes->string/utf8,它返回了通过string? 合约的东西,所以我认为这在与文字字符串比较时应该可以工作。
【问题讨论】: