gpt4 book ai didi

unit-testing - Unicode Clojure 单元测试输出

转载 作者:行者123 更新时间:2023-12-04 14:34:52 25 4
gpt4 key购买 nike

当对一些将 ascii 序列转换为 unicode 字符的代码进行单元测试时,我发现 Clojure 测试的输出存在问题。

我已经测试过我的终端可以输出 unicode 字符(通过 cat-ing 测试文件)并且工作正常,所以问题似乎与 leiningen、Clojure 或 clojure.test 有某种关系。

这是一个示例测试(使用 unicode 的希腊语部分 - 我也将使用希腊语扩展,但我认为同样的问题将适用):

(deftest bc-string-w-comma
(is (= "αβγ, ΑΒΓ" (parse "abg,*a*b*g"))))

由于输入中缺少空格,它意味着失败。 lein test 的输出如下:
Testing parse_perseus.test.betacode
FAIL in (bc-string-w-comma) (betacode.clj:15)
expected: (= "???, ???" (parse "abg,*a*b*g"))
actual: (not (= "???, ???" "???,???"))
Testing parse_perseus.test.core
Testing parse_perseus.test.pluralise
Ran 10 tests containing 59 assertions.
1 failures, 0 errors.

我在这里做错了什么?这是终端仿真问题还是与 clojure 相关的问题?我在使用 Slime/swank/emacs 在 REPL 中运行代码时遇到了同样的问题。 emacs 中的 REPL 只输出 unicode 输出的问号(虽然 emacs 非常能够理解 unicode)。

我试过在终端和 iTerm (OS X) 中运行它,结果相同。

最佳答案

事实证明,您可以将选项传递给 java 以强制 *out* 的输出编码。这样 unicode 就可以工作了,就像这样:

java -Dfile.encoding=utf-8 -cp lib/clojure-1.2.0.jar:lib/clojure-contrib-1.2.0.jar clojure.main -i src/whatever.clj

当我使用 Leiningen 时,我将此属性添加到我的 project.clj 文件中:
(defproject project_name "1.0.0-SNAPSHOT"
:description "A Clojure Project"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]]
:dev-dependencies [[swank-clojure "1.2.0"]]
:jvm-opts ["-Dfile.encoding=utf-8"])

关于unit-testing - Unicode Clojure 单元测试输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4843976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com