Much more work on duck-typing.
This commit is contained in:
parent
032dcb7536
commit
b2ff133e4a
3 changed files with 275 additions and 20 deletions
129
test/dog_and_duck/quack/quack_test.clj
Normal file
129
test/dog_and_duck/quack/quack_test.clj
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
(ns dog-and-duck.quack.quack-test
|
||||
(:require [clojure.test :refer [deftest is testing]]
|
||||
[dog-and-duck.quack.quack :refer [activitystreams-context-uri
|
||||
actor? actor-type? context?
|
||||
object? persistent-object?
|
||||
verb-type?]]
|
||||
[dog-and-duck.scratch.parser :refer [clean]]))
|
||||
|
||||
;;; Copyright (C) Simon Brooke, 2022
|
||||
|
||||
;;; This program is free software; you can redistribute it and/or
|
||||
;;; modify it under the terms of the GNU General Public License
|
||||
;;; as published by the Free Software Foundation; either version 2
|
||||
;;; of the License, or (at your option) any later version.
|
||||
|
||||
;;; This program is distributed in the hope that it will be useful,
|
||||
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;;; GNU General Public License for more details.
|
||||
|
||||
;;; You should have received a copy of the GNU General Public License
|
||||
;;; along with this program; if not, write to the Free Software
|
||||
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
(deftest object-test
|
||||
(testing "object recognition"
|
||||
(let [expected false
|
||||
actual (object? nil)]
|
||||
(is (= actual expected)))
|
||||
(let [expected true
|
||||
actual (object? {:type "Test"})]
|
||||
(is (= actual expected)))
|
||||
(let [expected false
|
||||
actual (object?
|
||||
(first
|
||||
(clean
|
||||
(slurp "resources/activitystreams-test-documents/empty.json"))))]
|
||||
(is (= actual expected)))
|
||||
(let [expected true
|
||||
actual (object?
|
||||
(first
|
||||
(clean
|
||||
(slurp "resources/activitystreams-test-documents/core-ex1-jsonld.json"))))]
|
||||
(is (= actual expected)))))
|
||||
|
||||
(deftest persistent-object-test
|
||||
(testing "persistent object recognition"
|
||||
(let [expected false
|
||||
actual (persistent-object? nil)]
|
||||
(is (= actual expected) "Not persistent: not an object."))
|
||||
(let [expected true
|
||||
actual (persistent-object? {:type "Test" :id "https://foo.bar/@ban"})]
|
||||
(is (= actual expected) "Is persistent: has both id and type."))
|
||||
(let [expected false
|
||||
actual (persistent-object?
|
||||
(first
|
||||
(clean
|
||||
(slurp "resources/activitystreams-test-documents/simple0001.json"))))]
|
||||
(is (= actual expected) "Not persistent: has no id."))
|
||||
(let [expected true
|
||||
actual (persistent-object?
|
||||
(first
|
||||
(clean
|
||||
(slurp "resources/activitystreams-test-documents/simple0008.json"))))]
|
||||
(is (= actual expected) "Is persistent: has both id and type."))))
|
||||
|
||||
(deftest actor-type-test
|
||||
(testing "identification of actor types"
|
||||
(let [expected false
|
||||
actual (actor-type? nil)]
|
||||
(is (= actual expected) "nil is not an actor"))
|
||||
(let [expected false
|
||||
actual (actor-type? "Duck")]
|
||||
(is (= actual expected) "A duck is not an actor"))
|
||||
(let [expected true
|
||||
actual (actor-type? "Person")]
|
||||
(is (= actual expected) "A person is an actor"))
|
||||
(let [expected true
|
||||
actual (actor-type? "Service")]
|
||||
(is (= actual expected) "A service is an actor"))))
|
||||
|
||||
(deftest verb-type-test
|
||||
(testing "identification of verb types"
|
||||
(let [expected false
|
||||
actual (verb-type? nil)]
|
||||
(is (= actual expected) "nil is not a verb"))
|
||||
(let [expected false
|
||||
actual (verb-type? "Quack")]
|
||||
(is (= actual expected) "Quack is not a verb"))
|
||||
(let [expected true
|
||||
actual (verb-type? "Create")]
|
||||
(is (= actual expected) "Create is a verb"))
|
||||
(let [expected true
|
||||
actual (verb-type? "Reject")]
|
||||
(is (= actual expected) "Reject is a verb"))))
|
||||
|
||||
(deftest context-test
|
||||
(testing "identification of valid contexts"
|
||||
(let [expected false
|
||||
actual (context? "https://foo.bar/ban/")]
|
||||
(is (= actual expected)
|
||||
"Only `activitystreams-context-uri` is valid as a context on its own"))
|
||||
(let [expected true
|
||||
actual (context? activitystreams-context-uri)]
|
||||
(is (= actual expected)
|
||||
"`activitystreams-context-uri` is valid as a context on its own"))
|
||||
(let [expected false
|
||||
actual (context? [{:foo "bar"} "https://foo.bar/ban/"])]
|
||||
(is (= actual expected)
|
||||
"Only `activitystreams-context-uri` is valid as a context uri"))
|
||||
(let [expected true
|
||||
actual (context? [{:foo "bar"} activitystreams-context-uri])]
|
||||
(is (= actual expected)
|
||||
"`activitystreams-context-uri` is valid as a context uri"))
|
||||
(let [expected true
|
||||
actual (context? [activitystreams-context-uri {:foo "bar"}])]
|
||||
(is (= actual expected)
|
||||
"order of elements within a context should not matter"))
|
||||
))
|
||||
|
||||
(deftest actor-test
|
||||
(testing "identification of actors"
|
||||
(let [expected false
|
||||
actual (actor? (-> "resources/activitystreams-test-documents/simple0008.json" slurp clean first))]
|
||||
(is (= actual expected) "A Note is not an actor"))
|
||||
(let [expected true
|
||||
actual (actor? (-> "resources/activitystreams-test-documents/simple0020.json" slurp clean first :actor))]
|
||||
(is (= actual expected) "A Person is an actor"))
|
||||
))
|
||||
Loading…
Add table
Add a link
Reference in a new issue