about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorArun Isaac2025-03-18 17:50:35 +0000
committerArun Isaac2025-03-18 17:50:35 +0000
commitaf43d1fa1bafd8f9e641da16eca45e0795af7935 (patch)
treef595faa4fb83475f39242c8350ced4eaad4ec705 /tests
parent9be0612b4b486f7d96ddd71c156be9284eff30b2 (diff)
downloadravanan-af43d1fa1bafd8f9e641da16eca45e0795af7935.tar.gz
ravanan-af43d1fa1bafd8f9e641da16eca45e0795af7935.tar.lz
ravanan-af43d1fa1bafd8f9e641da16eca45e0795af7935.zip
tests: Tolerate only path or location in File type inputs.
* tests/reader.scm: Import (ice-9 filesystem), (web uri), (ravanan
work command-line-tool) and (ravanan work utils).
(normalize-input): New variable.
("Normalize inputs with only location", "Normalize inputs with only
path"): New tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/reader.scm51
1 files changed, 50 insertions, 1 deletions
diff --git a/tests/reader.scm b/tests/reader.scm
index ea6472c..6266e65 100644
--- a/tests/reader.scm
+++ b/tests/reader.scm
@@ -18,8 +18,12 @@
 
 (use-modules (srfi srfi-1)
              (srfi srfi-64)
+             (ice-9 filesystem)
              (ice-9 match)
-             (ravanan reader))
+             (web uri)
+             (ravanan reader)
+             (ravanan work command-line-tool)
+             (ravanan work utils))
 
 (define normalize-formal-input
   (@@ (ravanan reader) normalize-formal-input))
@@ -27,6 +31,9 @@
 (define normalize-formal-output
   (@@ (ravanan reader) normalize-formal-output))
 
+(define normalize-input
+  (@@ (ravanan reader) normalize-input))
+
 (define (json=? tree1 tree2)
   (cond
    ;; Arrays
@@ -132,4 +139,46 @@
              ("id" . "foo")
              ("secondaryFiles" . #(".bai"))))))
 
+(test-assert "Normalize inputs with only location"
+  (call-with-temporary-directory
+   (lambda (dir)
+     (json=? (let ((path (expand-file-name "foo" dir)))
+               `(("class" . "File")
+                 ("location" . ,(uri->string (build-uri 'file #:path path)))
+                 ("path" . ,path)
+                 ("basename" . "foo")
+                 ("nameroot" . "foo")
+                 ("nameext" . "")
+                 ("size" . 0)
+                 ("checksum" . "sha1$da39a3ee5e6b4b0d3255bfef95601890afd80709")))
+             (call-with-current-directory dir
+               (lambda ()
+                 ;; Create an actual file called "foo" so that canonicalize-path
+                 ;; works.
+                 (call-with-output-file "foo"
+                   (const #t))
+                 (normalize-input '(("class" . "File")
+                                    ("location" . "foo")))))))))
+
+(test-assert "Normalize inputs with only path"
+  (call-with-temporary-directory
+   (lambda (dir)
+     (json=? (let ((path (expand-file-name "foo" dir)))
+               `(("class" . "File")
+                 ("location" . ,(uri->string (build-uri 'file #:path path)))
+                 ("path" . ,path)
+                 ("basename" . "foo")
+                 ("nameroot" . "foo")
+                 ("nameext" . "")
+                 ("size" . 0)
+                 ("checksum" . "sha1$da39a3ee5e6b4b0d3255bfef95601890afd80709")))
+             (call-with-current-directory dir
+               (lambda ()
+                 ;; Create an actual file called "foo" so that canonicalize-path
+                 ;; works.
+                 (call-with-output-file "foo"
+                   (const #t))
+                 (normalize-input '(("class" . "File")
+                                    ("path" . "foo")))))))))
+
 (test-end "reader")