Last active
August 29, 2015 14:07
-
-
Save potetm/b60f2fcf9ded797e214d to your computer and use it in GitHub Desktop.
Create a file system from a data structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns clojure-nio.jimfs-test | |
(:require [clojure.test :refer :all] | |
[clojure-nio.core :as nio] | |
[clojure-nio.jimfs :as jimfs])) | |
(defn existing-file? [path] | |
(and (nio/exists? path) | |
(nio/file? path))) | |
(defn existing-dir? [path] | |
(and (nio/exists? path) | |
(nio/dir? path))) | |
(defn existing-sym-link-to? [link link-to] | |
(and (nio/exists? link) | |
(nio/sym-link? link) | |
(= (nio/read-sym-link link) link-to))) | |
(deftest create-fs-test | |
(testing "a complex structure" | |
(let [s [{:name "my" | |
:children [{:name "path" | |
:children [{:name "to" | |
:children [{:name "file"}]} | |
{:name "empty-dir" | |
:type :dir}]} | |
{:name "link" | |
:type :sym-link | |
:link-to "/my/path/to"}]} | |
{:name "hard-link" | |
:type :link | |
:link-to "/my/path/to/file"}] | |
fs (jimfs/create-fs s)] | |
(is (existing-dir? (nio/path fs "/my"))) | |
(is (existing-dir? (nio/path fs "/my/path"))) | |
(is (existing-dir? (nio/path fs "/my/path/to"))) | |
(is (existing-dir? (nio/path fs "/my/path/empty-dir"))) | |
(is (existing-file? (nio/path fs "/my/path/to/file"))) | |
(is (existing-file? (nio/path fs "/hard-link"))) | |
(is (existing-sym-link-to? (nio/path fs "/my/link") (nio/path fs "/my/path/to")))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment