Skip to content

Instantly share code, notes, and snippets.

Dustin Getz dustingetz

View GitHub Profile
View match.clj
[:db/add [:idos.cpc/email "asdf@qwer"] :idos.cpc/email "asdf@qwer"]
(def invalid?
(matches?
#{nil
^:& [map? #(<= (count %) 1)]
#{[_ [a v] a v]
[_ _ :db/id _]}}))
View microtest.clj
(ns user.test
(:refer-clojure :exclude [test])
(:require
[meander.epsilon :as m]
[taoensso.timbre :refer [error]]))
(def tests-enabled true)
(defmacro test [& body]
View do-via.cljc
(ns contrib.do
#?(:cljs (:require-macros [contrib.do])))
(defn tag-type [tag]
(some->> (re-matches #"^([A-Z][-a-z]*)(.*)$" (name tag)) second keyword))
(defn typed-tag? [tag]
(not (nil? (tag-type tag))))
(defn typed-action? [val]
View datomic stage .clj
(ns user.stage
(:require
[datomic.api :as d]))
(defn with [$ tx]
(:db-after (d/with $ tx)))
(comment
(datomic.api/create-database "datomic:mem://app-db")
View contrib-test.md

I am tired of black box magic test frameworks with long command line incantations and opaque source code that soaks up weeks of attention to understand, so I really want something lightweight like this to become popular. I don't yet know the gap between this and production test functionality, and don't have much attention to spend on this, what are your ideas?

I especially love Brandon Bloom's idea of (defmacro tests [body]) which can erase the tests at compile time depending on build target. Does this mean we can finally co-locate our tests with our functions, like Rich comment blocks?

(ns contrib.test
  (:gen-class)
  (:require
    [clojure.spec.alpha :as s]
    [taoensso.timbre :refer [warn error info]]))
View .md
    (def s (r/atom 0))

    (defn foo []
      [:input {:type "text" 
               :value @s 
               :on-click #(reset! s (.-target.value %)}]) ; unstable closure reference
      
      
    (defn change [e] (reset! s (.-target.value e)) ; you're suggesting we name it
View clojure-value-errors.md
(defn foo! [i]
  (rand-nth (concat
              (range 20)
              [{:cognitect.anomalies/anomaly {:cognitect.anomalies/category :cognitect.anomalies/unavailable}}
               {:cognitect.anomalies/anomaly {:cognitect.anomalies/category :cognitect.anomalies/busy}}
               {:cognitect.anomalies/anomaly {:cognitect.anomalies/category :cognitect.anomalies/forbidden}}])))

(map foo! (range 15))
View when-if.md

Unbalanced if with effect

(defn- pprint-list [alis]
  (if-not (pprint-reader-macro alis)
    (pprint-simple-list alis)))

When without effect

(defn- diff-associative-key
View redux.js
var Mocha = require('mocha')
var assert = require('assert')
var _ = require('lodash')
var mocha = new Mocha()
mocha.suite.emit('pre-require', this, 'solution', mocha)
describe('Test suite', function() {
it('should work', function() {
assert(true)
You can’t perform that action at this time.