如何比较clojure中的数据结构并突出差异 [英] How to compare data structures in clojure and highlight differences

查看:32
本文介绍了如何比较clojure中的数据结构并突出差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种很好的方法可以打印出 clojure 数据结构中的差异?例如,在 Perl 中有 Test::Differences 这有助于很多.

Is there a nice way to print out differences in clojure data structures? In Perl for example there is Test::Differences which helps a lot.

推荐答案

我真正搜索的是 difform.使用 clojure.data/diff 很好,但在比较较大结构的单元测试中效果不佳.下面是一个例子,在我看来 data/diff 的表现不如 diff:

What I really searched for was difform. Using clojure.data/diff is nice but does not work well in a unit test where larger structures are compared. Here is an example where data/diff does not perform as well as difform in my opinion:

(defn example []
  (let [data [{:foo 1} {:value [{:bar 2}]}]]
    (diff data
          [{:value [{:bar 2}]}])

    (difform data
          [{:value [{:bar 2}]}])))

;; => diff output
;; => [[{:foo 1} {:value [{:bar 2}]}] [{:value [{:bar 2}]}] nil]

;; => difform output
   [{:
 - foo 1} {:
   value [{:bar 2}]}]
;; => nil

这篇关于如何比较clojure中的数据结构并突出差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆