Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

Commit

Permalink
Include object under test in assert messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
rduplain committed Feb 14, 2020
1 parent 72d947f commit 38bda69
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions test/unit/test-hosts.janet
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,76 @@
(apply :update ipv4 "127.0.0.1" ["localhost" "localhost.local"])

(assert (deep= (:hosts ipv4 "127.0.0.1") @["localhost" "localhost.local"])
"Hosts lookup by IP.")
(string/format "Hosts lookup by IP: %q" ipv4))

(assert (= (:ip ipv4 "localhost") "127.0.0.1")
"IP lookup by host.")
(string/format "IP lookup by host: %q" ipv4))

(assert (= (:hosts ipv4 "0.0.0.0") nil)
"Lookup unknown IP.")
(string/format "Lookup unknown IP: %q" ipv4))

(assert (= (:ip ipv4 "unknown") nil)
"Lookup unknown host.")
(string/format "Lookup unknown host: %q" ipv4))

(:update ipv4 "192.168.1.100" "hostname")

(assert (deep= (:hosts ipv4 "192.168.1.100") @["hostname"])
"Hosts lookup by IP.")
(string/format "Hosts lookup by IP: %q" ipv4))

(assert (= (:ip ipv4 "hostname") "192.168.1.100")
"IP lookup by host.")
(string/format "IP lookup by host: %q" ipv4))

(assert (deep= (:hosts ipv4 "127.0.0.1") @["localhost" "localhost.local"])
"Hosts lookup by IP, after updating unrelated host.")
(string/format "Hosts lookup by IP, after unrelated host: %q" ipv4))

(assert (= (:ip ipv4 "localhost") "127.0.0.1")
"IP lookup by host, after updating unrelated host.")
(string/format "IP lookup by host, after unrelated host: %q" ipv4))

(apply :update ipv4 "127.0.1.1" ["hostname" "localhost.local"])

(assert (deep= (:hosts ipv4 "127.0.1.1")
@["hostname" "localhost" "localhost.local"])
"Hosts lookup by IP, after updating via alias.")
(string/format "Hosts lookup by IP, after alias update: %q" ipv4))

(assert (= (:ip ipv4 "localhost") "127.0.1.1")
"IP lookup by host, after updating via alias.")
(string/format "IP lookup by host, after alias update: %q" ipv4))

(assert (= (:hosts ipv4 "127.0.0.1") nil)
"Hosts lookup by original IP, after updating via alias."))
(string/format "Hosts lookup by old IP, after update: %q" ipv4)))

(let [int-tracker (tracker)]
(assert (= (:seen? int-tracker 7) false)
"Checking a not-yet-seen value.")
(string/format "Checking a not-yet-seen value: %q" int-tracker))

(:see int-tracker 7)

(assert (= (:seen? int-tracker 7) true)
"Checking a seen value.")
(string/format "Checking a seen value: %q" int-tracker))

(assert (= (:seen? int-tracker 42) false)
"Checking an unrelated value."))
(string/format "Checking an unrelated value: %q" int-tracker)))

(let [table-tracker (tracker hash)
a-table @{7 "seven"}]
(assert (= (:seen? table-tracker a-table) false)
"Checking a not-yet-seen value.")
(string/format "Checking a not-yet-seen value: %q" table-tracker))

(:see table-tracker a-table)

(assert (= (:seen? table-tracker a-table) true)
"Checking a seen value.")
(string/format "Checking a seen value: %q" table-tracker))

(assert (= (:seen? table-tracker @{42 "forty-two" 7 "seven"}) false)
"Checking an unrelated value."))
(string/format "Checking an unrelated value: %q" table-tracker)))

(let [custom-tracker (tracker (fn [xs] (string/join xs "|")))]
(assert (= (:seen? custom-tracker @["hello" "world"]) false)
"Checking a not-yet-seen value.")
(string/format "Checking a not-yet-seen value: %q" custom-tracker))

(:see custom-tracker @["hello" "world"])

(assert (= (:seen? custom-tracker @["hello" "world"]) true)
"Checking a seen value.")
(string/format "Checking a seen value: %q" custom-tracker))

(assert (= (:seen? custom-tracker @["hello"]) false)
"Checking an unrelated value."))
(string/format "Checking an unrelated value: %q" custom-tracker)))

0 comments on commit 38bda69

Please sign in to comment.