pastebin-data
| 1 | #!/usr/bin/env sh |
| 2 | exec guile -s "$0" "$@" |
| 3 | !# |
| 4 | |
| 5 | ;;; SPDX-FileCopyrightText: 2025 Evgeny Pisemsky <mail@pisemsky.site> |
| 6 | ;;; |
| 7 | ;;; SPDX-License-Identifier: GPL-3.0-only |
| 8 | |
| 9 | (use-modules (srfi srfi-1) |
| 10 | (srfi srfi-26) |
| 11 | (srfi srfi-64) |
| 12 | (pastebin data)) |
| 13 | |
| 14 | (define (new-n-entries pb-data n) |
| 15 | (map (cut pb-data-new-entry pb-data <>) |
| 16 | (map number->string (iota n)))) |
| 17 | |
| 18 | (test-begin "pastebin-data") |
| 19 | |
| 20 | (test-begin "pb-entry-id-valid?") |
| 21 | (test-assert (pb-entry-id-valid? "00000")) |
| 22 | (test-assert (pb-entry-id-valid? "0001A")) |
| 23 | (test-assert (pb-entry-id-valid? "0002b")) |
| 24 | (test-assert (not (pb-entry-id-valid? "0../0"))) |
| 25 | (test-assert (not (pb-entry-id-valid? "12-34"))) |
| 26 | (test-assert (not (pb-entry-id-valid? "0000"))) |
| 27 | (test-assert (not (pb-entry-id-valid? "000000"))) |
| 28 | (test-end "pb-entry-id-valid?") |
| 29 | |
| 30 | (test-begin "pb-data-new-entry") |
| 31 | (let* ((dir (tmpnam)) |
| 32 | (pb-data (pb-data-open dir))) |
| 33 | (mkdir dir) |
| 34 | (let ((entry-list (new-n-entries pb-data 100))) |
| 35 | (test-equal "00000" (pb-entry-id (list-ref entry-list 0))) |
| 36 | (test-equal "00001" (pb-entry-id (list-ref entry-list 1))) |
| 37 | (test-equal "00009" (pb-entry-id (list-ref entry-list 9))) |
| 38 | (test-equal "0000A" (pb-entry-id (list-ref entry-list 10))) |
| 39 | (test-equal "0000B" (pb-entry-id (list-ref entry-list 11))) |
| 40 | (test-equal "0000Z" (pb-entry-id (list-ref entry-list 35))) |
| 41 | (test-equal "0000a" (pb-entry-id (list-ref entry-list 36))) |
| 42 | (test-equal "0000b" (pb-entry-id (list-ref entry-list 37))) |
| 43 | (test-equal "0000z" (pb-entry-id (list-ref entry-list 61))) |
| 44 | (test-equal "00010" (pb-entry-id (list-ref entry-list 62))) |
| 45 | (test-equal "0001A" (pb-entry-id (list-ref entry-list 72))) |
| 46 | (test-equal "0001a" (pb-entry-id (list-ref entry-list 98))))) |
| 47 | (test-end "pb-data-new-entry") |
| 48 | |
| 49 | (test-begin "pb-data-get-top") |
| 50 | (let* ((dir (tmpnam)) |
| 51 | (pb-data (pb-data-open dir))) |
| 52 | (mkdir dir) |
| 53 | (new-n-entries pb-data 5) |
| 54 | (let ((top-5 (pb-data-get-top pb-data 5))) |
| 55 | (test-equal "00004" (pb-entry-id (first top-5))) |
| 56 | (test-equal "00000" (pb-entry-id (last top-5)))) |
| 57 | (new-n-entries pb-data 195) |
| 58 | (let ((top-20 (pb-data-get-top pb-data 20))) |
| 59 | (test-equal "0003D" (pb-entry-id (first top-20))) |
| 60 | (test-equal "0002u" (pb-entry-id (last top-20))))) |
| 61 | (test-end "pb-data-get-top") |
| 62 | |
| 63 | (test-end "pastebin-data") |
| 64 | |
| 65 | ;; Local Variables: |
| 66 | ;; mode: scheme |
| 67 | ;; End: |
| 68 |