(library (test helper sph storage dg filesystem-layer) (export test-env-fl-create-files test-env-fl-create-relations test-env-fl-exit test-env-fl-file-number->ide test-env-fl-ide->file-number test-env-fl-prepare-result test-env-fl-reset test-env-fl-string-path-input test-env-fl-translate-result-ele) (import (guile) (rnrs base) (sph) (sph alist) (sph hashtable) (sph list) (sph storage dg) (sph storage dg faceted) (sph storage dg filesystem-layer path) (sph storage dg one) (sph tree) (test helper sph storage dg) (only (rnrs hashtables) ht-set!)) (define file-number->ide-ht (hashtable)) (define (test-env-fl-create-files count) (let (ide (dg-create-extern count)) (dg-ensure-pairs ide-alias-file ide) (fold (l (ele number) (ht-set! file-number->ide-ht number ele) (system* "touch" (dg-ide->path ele)) (- number 1)) count ide))) (define (test-env-fl-create-relations arg) (each (l (ele) (apply dg-ensure-pairs (map any->list (dg-tree-ensure-strings-as-facets (test-env-fl-tree-replace-file-numbers ele))))) arg)) (define (test-env-fl-file-number->ide arg) (ht-ref file-number->ide-ht arg)) (define (test-env-fl-ide->file-number arg) (ht-key file-number->ide-ht arg)) (define (test-env-fl-file-number->path-element arg) (string-append "," (number->string (test-env-fl-file-number->ide arg) 16))) (define (test-env-fl-tree-replace-file-numbers arg) (tree-map (l (ele) (if (integer? ele) (test-env-fl-file-number->ide ele) ele)) arg)) (define (test-env-fl-reset file-count . relations) (if dg-initialised (test-env-fl-exit)) (system* "rm" "-r" test-env-path) (test-env-dg-init) (test-env-fl-create-files file-count) (test-env-fl-create-relations relations)) (define test-env-fl-exit test-env-dg-exit) (define (test-env-fl-string-path-input arg) "-> parsed-path" (if (string? arg) (string->parsed-path arg) (if (list? arg) (string->parsed-path (string-join (map (l (ele) (if (integer? ele) (test-env-fl-file-number->path-element ele) ele)) arg) "/")) (if (integer? arg) (test-env-fl-file-number->path-element arg) (throw (q cannot-process-input)))))) (define (test-env-fl-translate-result-ele arg) (if (integer? arg) (if (dg-intern? arg) (dg-ide->intern arg (q string)) (if (dg-extern? arg) (test-env-fl-ide->file-number arg) arg)) arg)) (define (test-env-fl-prepare-result arg) (if (list? arg) (map test-env-fl-translate-result-ele arg) (test-env-fl-translate-result-ele arg))))