       "chr1\t10\tA\t1\t.\tI\n"
       "chr1\t10\tA\t4\t.,Tt\tIABC\n"
       "chr1\t10\tA\t4\t^].+3TTT,-2tg$Tt\tIABC\n")))
+
+(deftest source-type-test
+  (testing "reader"
+    (with-open [server (http-server)]
+      (are [x] (= the-last-pile
+                  (with-open [r (plpio/reader x)]
+                    (rec->map (last (plpio/read-piles r)))))
+        test-pileup-file
+        (cio/file test-pileup-file)
+        (cio/as-url (cio/file test-pileup-file))
+        (cio/as-url (str (:uri server) "/pileup/test.pileup")))))
+
+  (testing "writer"
+    (let [tmp-pileup-file (cio/file temp-dir "pileup-source-type-writer.mpileup")]
+      (are [x] (with-before-after {:before (prepare-cache!)
+                                   :after (clean-cache!)}
+                 (with-open [w (plpio/writer x)]
+                   (not-throw? (plpio/write-piles w [the-last-pile]))))
+        (.getCanonicalPath tmp-pileup-file)
+        tmp-pileup-file
+        (cio/as-url tmp-pileup-file)))))


(deftest read-piles
  (with-open [r (plpio/reader test-pileup-file)]
    (is (= {:rname "ref2",
            :pos 36,
            :ref \N,
            :count 1,
            :pile [{:start? false,
                    :mapq nil,
                    :base \A,
                    :qual 30,
                    :reverse? false,
                    :end? true,
                    :insertion nil,
                    :deletion nil
                    :alignment nil}]}
           (->> xs
                (map #(into {} %))
                (fn [xs])
                (update (last (plpio/read-piles r)) :pile)
                (into {}))))))

;; Writer
;; ------

                                            {:start? false, :mapq nil, :base \A, :qual 33, :reverse? false, :end? true, :insertion nil, :deletion 2, :alignment nil}]}))
  (testing "with-ref"
    (are [?in ?out]
        (= ?out (rec->map (#'plpio/parse-pileup-line ?in)))
      "chr1\t10\tA\t0\t\t" {:rname "chr1", :pos 10, :ref \A, :count 0,
                            :pile []}
      "chr1\t10\ta\t1\t.\tI" {:rname "chr1", :pos 10, :ref \a, :count 1,
