An open API service indexing awesome lists of open source software.

https://github.com/steenhansen/clojure-text-diff

Colored text diffs for Clojure tests
https://github.com/steenhansen/clojure-text-diff

Last synced: about 1 year ago
JSON representation

Colored text diffs for Clojure tests

Awesome Lists containing this project

README

          


### Rational 

The Clojure function 'text-diff/are-vars-eq' helps to quickly show small differences during testing with large bodies of html, convoluted maps/sets/lists/vectors, and unordered maps/sets. When unequal actual and expected values are tested, a short description of the similarities and differences are printed in the REPL. First, leading identical sections are displayed, followed by differences, and then finally identical ending sections.

### How to use

```
;; clojure test file
(ns my-test-ns
(:require [clojure.test :refer [is]])
(:require [text-diff :refer [are-vars-eq]]))

(deftest test-html-values []
(let [actual-value "DIFFERENT"
expected-value "different"
[diff-actual diff-expected] (are-vars-eq actual-value expected-value)]
(is (= diff-actual diff-expected)))
)
```

```
;; repl output
|START|""
|DIFF1|"e>DIFFERENT"
|DIFF2|"e>different"
| END|""

expected (= diff-actual diff-expected)
actual (not (= "DIFFERENT" "different"))
false
```

###Examples

![Hard to see \n versus \r](images/a_r_vs_n.png)

---

![Hard to see 1 versus L](images/b_1_vs_l.png)

---

![Hard to see c versus X](images/c_out_order.png)

---

![Hard to see X versus Y](images/d_lots_x_y.png)

---

![Hard to see 1/3 versus 1/4](images/e_map_3_4.png)

---

![Hard to see ending \n](images/f_end_n.png)

---

![Hard to see 8 versus 7](images/g_numbers_7_8.png)

---
Odd string behavior that is to be expected from string differences inside maps/sets/lists/vectors. Quote delimiters cause extra blank spaces because variable types are not taken into account.

![Hard to see 8 versus 7](images/h_str_in_list.png)