File: core_test.clj

package info (click to toggle)
yasnippet-snippets 1.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,328 kB
  • sloc: lisp: 127; sh: 13; ada: 5; makefile: 2; python: 2
file content (47 lines) | stat: -rw-r--r-- 1,587 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(ns core-test
  (:require [clojure.test :refer [deftest testing is]]
            [core :as sut]
            [clojure.string :as str]
            [clojure.java.io :as io]))

(deftest unique-test
  (let [all-modes (sut/parse-everything "../snippets")]
    (doseq [[k snippets] all-modes]
      (let [keys (map :name snippets)
            freq (->> (frequencies keys)
                      (filter #(> (second %) 1)))]
        (is (= (count keys) (count (set keys)))
            (str "failed for mode " k " and failing things:\n"
                 (str/join ", " (map first freq))))))))

(defn with-nil-key [ns key]
  (str/join ", " (map :filename (filter #(nil? (key %)) ns))))

(deftest non-nils-test
  (let [all-modes (sut/parse-everything "../snippets")]
    (doseq [[k snippets] all-modes]
      (let [ns (filter #(not (.startsWith (:filename %) ".yas-")) snippets)
            nil-names (with-nil-key ns :name)
            nil-keys (with-nil-key ns :key)]
        (is (empty? nil-names) (str "nils in " k " => " nil-names))
        (is (empty? nil-keys) (str "nils in " k "=> " nil-keys))))))

(comment
  (def reg #"key:(\w)")

  (doseq [f (file-seq (io/file "../snippets"))
          :when (.isFile f)
          :let [c (slurp f)]]

    (when (re-seq reg c)
      (let [new-c (str/replace c reg "key: $1")]
        (spit (.getPath f) new-c))))

  (doseq [f (file-seq (io/file "../snippets"))
          :when (.isFile f)
          :let [c (slurp f)
                res (re-seq #"contributor:" c)]]

    ;; should I clean all of them?
    (when (seq res)
      (println "file = " f))))