690 lines
43 KiB
HTML
690 lines
43 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link rel="stylesheet" href="../../coverage.css"/> <title> dog_and_duck/quack/quack.clj </title>
|
|
</head>
|
|
<body>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
001 (ns dog-and-duck.quack.quack
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
002 "Validator for ActivityPub objects: if it walks like a duck, and it quacks
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
003 like a duck...
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
004
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
005 **NOTE THAT the ActivityPub spec
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
006 [says](https://www.w3.org/TR/activitypub/#obj)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
007
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
008 > Servers SHOULD validate the content they receive to avoid content
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
009 > spoofing attacks
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
010
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
011 but in practice ActivityPub content collected in the wild bears only
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
012 a hazy relationship to the spec, so this is difficult. I suspect that
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
013 I may have to implement a `*strict*` dynamic variable, so that users can
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
014 toggle some checks off."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
015
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
016 ;;(:require [clojure.spec.alpha as s])
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
017 (:require [dog-and-duck.quack.picky :refer [filter-severity has-context?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
018 object-faults]])
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
019 (:import [java.net URI URISyntaxException]))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
020
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
021 ;;; Copyright (C) Simon Brooke, 2022
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
022
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
023 ;;; This program is free software; you can redistribute it and/or
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
024 ;;; modify it under the terms of the GNU General Public License
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
025 ;;; as published by the Free Software Foundation; either version 2
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
026 ;;; of the License, or (at your option) any later version.
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
027
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
028 ;;; This program is distributed in the hope that it will be useful,
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
029 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
030 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
031 ;;; GNU General Public License for more details.
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
032
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
033 ;;; You should have received a copy of the GNU General Public License
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
034 ;;; along with this program; if not, write to the Free Software
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
035 ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
036
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
037 (defn object?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
038 "Returns `true` iff `x` is recognisably an ActivityStreams object.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
039
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
040 **NOTE THAT** The ActivityStreams spec
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
041 [says](https://www.w3.org/TR/activitystreams-core/#object):
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
042
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
043 > All properties are optional (including the id and type)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
044
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
045 But we are *just not having that*, because otherwise we're flying blind.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
046 We *shall* reject objects lacking at least `:type`. Missing `:id` keys are
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
047 tolerable because they represent transient objects, which we expect to
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
048 handle.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
049
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
050 **NOTE THAT** The ActivityPub spec [says](https://www.w3.org/TR/activitypub/#obj)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
051
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
052 > Implementers SHOULD include the ActivityPub context in their object
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
053 > definitions
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
054
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
055 but in samples found in the wild they typically don't."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
056 ([x]
|
|
</span><br/>
|
|
<span class="covered" title="15 out of 15 forms covered">
|
|
057 (and (map? x) (:type x) true))
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
058 ([x severity]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 8 forms covered">
|
|
059 (empty? (filter-severity (object-faults x) severity))))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
060
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
061 (defn persistent-object?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
062 "`true` iff `x` is a persistent object.
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
063
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
064 Transient objects in ActivityPub are not required to have an `id` key, but persistent
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
065 ones must have a key, and it must be an IRI (but normally a URI)."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
066 [x]
|
|
</span><br/>
|
|
<span class="partial" title="1 out of 2 forms covered">
|
|
067 (try
|
|
</span><br/>
|
|
<span class="covered" title="13 out of 13 forms covered">
|
|
068 (and (object? x) (uri? (URI. (:id x))))
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
069 (catch URISyntaxException _ false)))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
070
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
071 ;; (persistent-object? {:type "test" :id "https://mastodon.scot/@barfilfarm"})
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
072
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
073 (def ^:const actor-types
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
074 "The set of types we will accept as actors.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
075
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
076 There's an [explicit set of allowed actor types]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
077 (https://www.w3.org/TR/activitystreams-vocabulary/#actor-types)."
|
|
</span><br/>
|
|
<span class="covered" title="6 out of 6 forms covered">
|
|
078 #{"Application"
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
079 "Group"
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
080 "Organization"
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
081 "Person"
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
082 "Service"})
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
083
|
|
</span><br/>
|
|
<span class="partial" title="33 out of 34 forms covered">
|
|
084 (defmacro actor-type?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
085 "Return `true` iff the `x` is a recognised actor type, else `false`."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
086 [^String x]
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
087 `(if (actor-types ~x) true false))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
088
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
089 ;; (actor-type? "Group")
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
090
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
091 (def ^:const verb-types
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
092 "The set of types we will accept as verbs.
|
|
</span><br/>
|
|
<span class="partial" title="2 out of 4 forms covered">
|
|
093
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
094 There's an [explicit set of allowed verb types]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
095 (https://www.w3.org/TR/activitystreams-vocabulary/#activity-types)."
|
|
</span><br/>
|
|
<span class="covered" title="29 out of 29 forms covered">
|
|
096 #{"Accept" "Add" "Announce" "Arrive" "Block" "Create" "Delete" "Dislike"
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
097 "Flag" "Follow" "Ignore" "Invite" "Join" "Leave" "Like" "Listen" "Move"
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
098 "Offer" "Question" "Reject" "Read" "Remove" "TentativeAccept"
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
099 "TentativeReject" "Travel" "Undo" "Update" "View"})
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
100
|
|
</span><br/>
|
|
<span class="partial" title="33 out of 34 forms covered">
|
|
101 (defmacro verb-type?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
102 ;; TODO: better as a macro
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
103 [^String x]
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
104 `(if (verb-types ~x) true false))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
105
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
106
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
107 (defn actor?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
108 "Returns `true` if `x` quacks like an actor, else false.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
109
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
110 **NOTE THAT** [Section 4.1 of the spec]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
111 (https://www.w3.org/TR/activitypub/#actor-objects) says explicitly that
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
112
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
113 > Actor objects MUST have, in addition to the properties mandated by 3.1 Object Identifiers, the following properties:
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
114 >
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
115 > inbox
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
116 > A reference to an [ActivityStreams] OrderedCollection comprised of all the messages received by the actor; see 5.2 Inbox.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
117 > outbox
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
118 > An [ActivityStreams] OrderedCollection comprised of all the messages produced by the actor; see 5.1 Outbox.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
119
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
120 However, none of the provided examples in the [activitystreams-test-documents repository]() does in fact have these properties"
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
121 [x]
|
|
</span><br/>
|
|
<span class="partial" title="7 out of 21 forms covered">
|
|
122 (and
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
123 (object? x)
|
|
</span><br/>
|
|
<span class="covered" title="5 out of 5 forms covered">
|
|
124 (has-context? x)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 6 forms covered">
|
|
125 (uri? (URI. (:inbox x)))
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 6 forms covered">
|
|
126 (uri? (URI. (:outbox x)))
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 7 forms covered">
|
|
127 (actor-type? (:type x))
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
128 true))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
129
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
130 (defn actor-or-uri?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
131 "`true` if `x` is either a URI or an actor.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
132
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
133 **TODO**: I need to decide about whether to reify referenced objects
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
134 before validation or after. After reification, every reference to an actor
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
135 *must be* to an actor object, but before, may only be to a URI pointing to
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
136 one."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
137 [x]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 5 forms covered">
|
|
138 (and
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 9 forms covered">
|
|
139 (cond (string? x) (uri? (URI. x))
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
140 :else (actor? x))
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
141 true))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
142
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
143 (defn activity?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
144 "`true` iff `x` quacks like an activity, else false."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
145 [x]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 2 forms covered">
|
|
146 (try
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 28 forms covered">
|
|
147 (and (object? x)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 5 forms covered">
|
|
148 (has-context? x)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 5 forms covered">
|
|
149 (string? (:summary x))
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 5 forms covered">
|
|
150 (actor-or-uri? (:actor x))
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 7 forms covered">
|
|
151 (verb-type? (:type x))
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 15 forms covered">
|
|
152 (or (object? (:object x)) (uri? (URI. (:object x))))
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
153 true)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
154 (catch URISyntaxException _ false)))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
155
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
156 (defn link?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
157 "`true` iff `x` quacks like a link, else false."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
158 [x]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 16 forms covered">
|
|
159 (and (object? x)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 5 forms covered">
|
|
160 (= (:type x) "Link")
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 6 forms covered">
|
|
161 (uri? (URI. (:href x)))
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
162 true))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
163
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
164 (defn link-or-uri?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
165 "`true` iff `x` is either a URI or a link, else false.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
166
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
167 There are several points in the specification where e.g. the `:image`
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
168 property (if present) may be either a link or a URI."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
169 [x]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 5 forms covered">
|
|
170 (and
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 9 forms covered">
|
|
171 (cond (string? x) (uri? (URI. x))
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
172 :else (link? x))
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
173 true))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
174
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
175 (defn collection?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
176 "`true` iff `x` quacks like a collection of type `object-type`, else `false`.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
177
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
178 With one argument, will recognise plain collections and ordered collections,
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
179 but (currently) not collection pages."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
180 ([x ^String object-type]
|
|
</span><br/>
|
|
<span class="partial" title="10 out of 11 forms covered">
|
|
181 (let [items (or (:items x) (:orderedItems x))]
|
|
</span><br/>
|
|
<span class="partial" title="14 out of 17 forms covered">
|
|
182 (and
|
|
</span><br/>
|
|
<span class="partial" title="5 out of 6 forms covered">
|
|
183 (cond
|
|
</span><br/>
|
|
<span class="partial" title="3 out of 8 forms covered">
|
|
184 (:items x) (nil? (:orderedItems x))
|
|
</span><br/>
|
|
<span class="covered" title="8 out of 8 forms covered">
|
|
185 (:orderedItems x) (nil? (:items x)) ;; can't have both properties
|
|
</span><br/>
|
|
<span class="covered" title="5 out of 5 forms covered">
|
|
186 (integer? (:totalItems x)) true ;; can have neither, provided it has totalItems.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
187 :else false)
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
188 (object? x)
|
|
</span><br/>
|
|
<span class="covered" title="5 out of 5 forms covered">
|
|
189 (= (:type x) object-type)
|
|
</span><br/>
|
|
<span class="partial" title="2 out of 3 forms covered">
|
|
190 (if items
|
|
</span><br/>
|
|
<span class="partial" title="10 out of 12 forms covered">
|
|
191 (and (coll? items)
|
|
</span><br/>
|
|
<span class="covered" title="4 out of 4 forms covered">
|
|
192 (every? object? items) ;; if there are items, they must form a
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
193 ;; collection of objects.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
194 true)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
195 true) ;; but it's OK if there aren't.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
196 true)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
197 ;; test for totalItems not done here, because collection pages don't
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
198 ;; have it.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
199 ))
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
200 ([x]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 9 forms covered">
|
|
201 (and
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 10 forms covered">
|
|
202 (or (collection? x "Collection")
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 2 forms covered">
|
|
203 (collection? x "OrderedCollection"))
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 5 forms covered">
|
|
204 (integer? (:totalItems x))
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
205 true)))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
206
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
207 (defn unordered-collection?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
208 "`true` iff `x` quacks like an unordered collection, else `false`."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
209 [x]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 18 forms covered">
|
|
210 (and (collection? x "Collection") (integer? (:totalItems x)) true))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
211
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
212 (defn ordered-collection?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
213 "`true` iff `x` quacks like an ordered collection, else `false`."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
214 [x]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 18 forms covered">
|
|
215 (and (collection? x "OrderedCollection") (integer? (:totalItems x)) true))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
216
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
217 (defn collection-page?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
218 "`true` iff `x` quacks like a page in a paged collection, else `false`."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
219 [x]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 4 forms covered">
|
|
220 (collection? x "CollectionPage"))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
221
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
222 (defn ordered-collection-page?
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
223 "`true` iff `x` quacks like a page in an ordered paged collection, else `false`."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
224 [x]
|
|
</span><br/>
|
|
<span class="covered" title="4 out of 4 forms covered">
|
|
225 (collection? x "OrderedCollectionPage"))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
226
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
227
|
|
</span><br/>
|
|
</body>
|
|
</html>
|