<commit_before>(ns remworks.exif-reader-test
  #?(:cljs (:require-macros [cljs.test :refer [is deftest]]))
  #?(:cljs (:require [cljs.test :as t]
                     [cljs.nodejs :as nodejs]
                     [remworks.exif-reader :as sut])
     :clj (:require [clojure.java.io :as io]
                    [clojure.test :refer :all]
                    [remworks.exif-reader :as sut])))

#?(:cljs
   (do
     (def fs (nodejs/require "fs"))
     (defn data-from-file [filename]
       (->> filename (.readFileSync fs) (js/Uint8Array.) .-buffer)))
   :clj
   (defn data-from-file [filename]
     (java.io.File. filename)))

(deftest basic
  (let [exif (-> "resources/test/exif.jpg" data-from-file sut/from-jpeg)]
    (is (= "Canon PowerShot G3" (:model exif)))
    (is (= 4.5 (double (:aperture-value exif))))
    (is (= "1/1244" (str (:shutter-speed-value exif))))))

(deftest gps
  (let [exif (-> "resources/test/gps.tif" data-from-file sut/from-tiff)]
    (is (= "6°47'19\"" (str (:gps-longitude exif))))
    (is (= "53°33'19\"" (str (:gps-latitude exif))))))

(deftest malformed
  (doseq [name ["malformed.jpg"
                "multiple-app1.jpg"]]
    (let [m (-> (str "resources/test/" name) data-from-file sut/from-jpeg)]
      (is (identity m) (str "expect " name " to yield some values"))))
  (doseq [name ["apple-aperture-1.5.exif"
                "bad-shutter_speed_value.exif"
                "endless-loop.exif"
                "negative-exposure-bias-value.exif"
                "out-of-range.exif"
                "weird_date.exif"]]
    (let [m (-> (str "resources/test/" name) data-from-file sut/from-tiff)]
      (is (identity m) (str "expect " name " to yield some values")))))

(deftest date-time
  (let [exif (-> "resources/test/milliseconds.jpg" data-from-file sut/from-jpeg)]
    (is (= #inst "2018-05-25T05:13:09.000-00:00" (:date-time exif))
        "won't parse milliseconds but also won't choke on them")))

(deftest jpeg-meta
  (let [{:keys [width height bits comments]} (-> "resources/test/comment.jpg"
                                                 data-from-file
                                                 sut/from-jpeg
                                                 :jpeg)]
    (is (= ["Here's a comment!"] comments))
    (is (= 100 width))
    (is (= 75 height))
    (is (= 8 bits)))

  (let [{:keys [width height bits] :as jpeg} (-> "resources/test/exif.jpg"
                                                 data-from-file
                                                 sut/from-jpeg
                                                 :jpeg)]
    (is (= 100 width))
    (is (= 75 height))
    (is (= 8 bits))<commit_msg>I don't want to deal with time zones..<commit_after>(ns remworks.exif-reader-test
  #?(:cljs (:require-macros [cljs.test :refer [is deftest]]))
  #?(:cljs (:require [cljs.test :as t]
                     [cljs.nodejs :as nodejs]
                     [remworks.exif-reader :as sut])
     :clj (:require [clojure.java.io :as io]
                    [clojure.test :refer :all]
                    [remworks.exif-reader :as sut])))

#?(:cljs
   (do
     (def fs (nodejs/require "fs"))
     (defn data-from-file [filename]
       (->> filename (.readFileSync fs) (js/Uint8Array.) .-buffer)))
   :clj
   (defn data-from-file [filename]
     (java.io.File. filename)))

(deftest basic
  (let [exif (-> "resources/test/exif.jpg" data-from-file sut/from-jpeg)]
    (is (= "Canon PowerShot G3" (:model exif)))
    (is (= 4.5 (double (:aperture-value exif))))
    (is (= "1/1244" (str (:shutter-speed-value exif))))))

(deftest gps
  (let [exif (-> "resources/test/gps.tif" data-from-file sut/from-tiff)]
    (is (= "6°47'19\"" (str (:gps-longitude exif))))
    (is (= "53°33'19\"" (str (:gps-latitude exif))))))

(deftest malformed
  (doseq [name ["malformed.jpg"
                "multiple-app1.jpg"]]
    (let [m (-> (str "resources/test/" name) data-from-file sut/from-jpeg)]
      (is (identity m) (str "expect " name " to yield some values"))))
  (doseq [name ["apple-aperture-1.5.exif"
                "bad-shutter_speed_value.exif"
                "endless-loop.exif"
                "negative-exposure-bias-value.exif"
                "out-of-range.exif"
                "weird_date.exif"]]
    (let [m (-> (str "resources/test/" name) data-from-file sut/from-tiff)]
      (is (identity m) (str "expect " name " to yield some values")))))

(deftest date-time
  (let [exif (-> "resources/test/milliseconds.jpg" data-from-file sut/from-jpeg)]
    (is (:date-time exif)
        "won't parse milliseconds but also won't choke on them")))

(deftest jpeg-meta
  (let [{:keys [width height bits comments]} (-> "resources/test/comment.jpg"
                                                 data-from-file
                                                 sut/from-jpeg
                                                 :jpeg)]
    (is (= ["Here's a comment!"] comments))
    (is (= 100 width))
    (is (= 75 height))
    (is (= 8 bits)))

  (let [{:keys [width height bits] :as jpeg} (-> "resources/test/exif.jpg"
                                                 data-from-file
                                                 sut/from-jpeg
                                                 :jpeg)]
    (is (= 100 width))
    (is (= 75 height))
    (is (= 8 bits))
{'fraction_non_alphanumeric': 0.16933207902163688, 'fraction_numerical': 0.017121354656632174, 'mean_word_length': 1.76730869338886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5882483', 'n_tokens_mistral': 1906, 'n_tokens_neox': 1737, 'n_words': 414}