1
0
Fork 0
tinmop/src/tests/link-header-tests.lisp

44 lines
2.1 KiB
Common Lisp

;; tinmop: an humble gemini and pleroma client
;; Copyright (C) 2020 cage
;; 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 3 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, see [[http://www.gnu.org/licenses/][http://www.gnu.org/licenses/]].
(in-package :link-header-tests)
(defsuite link-header-suite (all-suite))
(defun test-link-header (link-header results)
(let ((parsed (parse-header link-header)))
(loop for field in parsed
for original-field in results do
(when (not (and (iri= (first field) (first original-field))
(equalp (second field) (second original-field))))
(return-from test-link-header nil)))
t))
(defparameter *test-cases* `(("<http://invalid/a/b?p=5>; rel=\"f\"" .
(("http://invalid/a/b?p=5" (("rel" . "f")))))
,(cons (format nil "<https://example.org/>; rel=\"start\",~%<https://example.org/index>; rel=\"index\"")
'(("https://example.org/" (("rel" . "start")))
("https://example.org/index" (("rel" . "index")))))))
(deftest test-parsing (link-header-suite)
(loop for (a . b) in *test-cases* do
(assert-true (test-link-header a b) b)))
(deftest test-extraction-next-pagination-id (link-header-suite)
(let ((link-pagination "<https://invalid/api/v1/accounts/111013574088566395/following?max_id=123456>; rel=\"next\", <https://invalid/api/v1/accounts/111013574088566395/following?since_id=654321>; rel=\"prev\""))
(assert-equalp "123456" (extract-pagination-current-max-id link-pagination))))