* fix lanterna constants ns name * add multigrep lib test and example
This commit is contained in:
parent
bb57d220d0
commit
83b6d1e662
6 changed files with 69 additions and 1 deletions
1
deps.edn
1
deps.edn
|
|
@ -87,6 +87,7 @@
|
||||||
com.grammarly/omniconf {:mvn/version "0.4.3"}
|
com.grammarly/omniconf {:mvn/version "0.4.3"}
|
||||||
crispin/crispin {:mvn/version "0.3.8"}
|
crispin/crispin {:mvn/version "0.3.8"}
|
||||||
org.clojure/data.json {:mvn/version "2.4.0"}
|
org.clojure/data.json {:mvn/version "2.4.0"}
|
||||||
|
clj-commons/multigrep {:mvn/version "0.5.0"}
|
||||||
amperity/vault-clj {:mvn/version "1.0.4"}}
|
amperity/vault-clj {:mvn/version "1.0.4"}}
|
||||||
:classpath-overrides {org.clojure/clojure nil
|
:classpath-overrides {org.clojure/clojure nil
|
||||||
org.clojure/spec.alpha nil
|
org.clojure/spec.alpha nil
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ The following libraries and projects are known to work with babashka.
|
||||||
- [hasch](#hasch)
|
- [hasch](#hasch)
|
||||||
- [crispin](#crispin)
|
- [crispin](#crispin)
|
||||||
- [ffclj](#ffclj)
|
- [ffclj](#ffclj)
|
||||||
|
- [multigrep](#multigrep)
|
||||||
- [Pods](#pods)
|
- [Pods](#pods)
|
||||||
- [Projects](#projects-1)
|
- [Projects](#projects-1)
|
||||||
- [babashka-test-action](#babashka-test-action)
|
- [babashka-test-action](#babashka-test-action)
|
||||||
|
|
@ -633,6 +634,44 @@ FOO=1 script.clj
|
||||||
|
|
||||||
A wrapper around executing `ffmpeg` and `ffprobe`. Supports progress reporting via core.async channels.
|
A wrapper around executing `ffmpeg` and `ffprobe`. Supports progress reporting via core.async channels.
|
||||||
|
|
||||||
|
### [multigrep](https://github.com/clj-commons/multigrep)
|
||||||
|
|
||||||
|
Regex-based file grepping and/or text substitution.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
- find the words that are exactly four letters long in some strings:
|
||||||
|
```clj
|
||||||
|
(ns multigrep-demo
|
||||||
|
(:require [babashka.deps :as deps]
|
||||||
|
[clojure.pprint :refer [pprint]])
|
||||||
|
(:import (java.io StringReader)))
|
||||||
|
|
||||||
|
(deps/add-deps '{:deps {clj-commons/multigrep {:mvn/version "0.5.0"}}})
|
||||||
|
|
||||||
|
(require '[multigrep.core :as grep])
|
||||||
|
|
||||||
|
; the StringReaders could be anything that clojure.java.io/reader will accept (files, URLs, etc.)
|
||||||
|
(let [sentence1 (StringReader. "the quick brown fox jumps over the lazy dog")
|
||||||
|
sentence2 (StringReader. "Lorem ipsum dolor sit amet")]
|
||||||
|
(pprint (grep/grep #"\b[a-z]{4}\b" [sentence1 sentence2])))
|
||||||
|
```
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
```
|
||||||
|
({:file
|
||||||
|
#object[java.io.StringReader...],
|
||||||
|
:line "the quick brown fox jumps over the lazy dog",
|
||||||
|
:line-number 1,
|
||||||
|
:regex #"\b[a-z]{4}\b",
|
||||||
|
:re-seq ("over" "lazy")}
|
||||||
|
{:file
|
||||||
|
#object[java.io.StringReader...],
|
||||||
|
:line "Lorem ipsum dolor sit amet",
|
||||||
|
:line-number 1,
|
||||||
|
:regex #"\b[a-z]{4}\b",
|
||||||
|
:re-seq ("amet")})
|
||||||
|
```
|
||||||
|
|
||||||
## Pods
|
## Pods
|
||||||
|
|
||||||
[Babashka pods](https://github.com/babashka/babashka.pods) are programs that can
|
[Babashka pods](https://github.com/babashka/babashka.pods) are programs that can
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
(def tns (sci/create-ns 'lanterna.terminal nil))
|
(def tns (sci/create-ns 'lanterna.terminal nil))
|
||||||
(def sns (sci/create-ns 'lanterna.screen nil))
|
(def sns (sci/create-ns 'lanterna.screen nil))
|
||||||
(def cns (sci/create-ns 'lanterna.screen nil))
|
(def cns (sci/create-ns 'lanterna.constants nil))
|
||||||
|
|
||||||
(def lanterna-terminal-namespace
|
(def lanterna-terminal-namespace
|
||||||
{'add-resize-listener (copy-var lanterna.terminal/add-resize-listener tns)
|
{'add-resize-listener (copy-var lanterna.terminal/add-resize-listener tns)
|
||||||
|
|
|
||||||
|
|
@ -237,6 +237,8 @@
|
||||||
(test-namespaces 'clojure.data.json-test
|
(test-namespaces 'clojure.data.json-test
|
||||||
'clojure.data.json-test-suite-test)
|
'clojure.data.json-test-suite-test)
|
||||||
|
|
||||||
|
(test-namespaces 'multigrep.core-test)
|
||||||
|
|
||||||
(test-namespaces
|
(test-namespaces
|
||||||
;; TODO: env tests don't work because envoy lib isn't compatible with bb
|
;; TODO: env tests don't work because envoy lib isn't compatible with bb
|
||||||
#_'vault.env-test
|
#_'vault.env-test
|
||||||
|
|
|
||||||
23
test-resources/lib_tests/multigrep/core_test.clj
Normal file
23
test-resources/lib_tests/multigrep/core_test.clj
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
(ns multigrep.core-test
|
||||||
|
(:require [clojure.java.io :as io]
|
||||||
|
[clojure.test :refer [deftest is testing]]
|
||||||
|
[multigrep.core :as grep])
|
||||||
|
(:import (java.io StringReader)))
|
||||||
|
|
||||||
|
(def lorem-ipsum "Lorem ipsum dolor sit amet, consectetur adipiscing
|
||||||
|
elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||||
|
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
|
||||||
|
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
|
||||||
|
in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||||
|
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
|
||||||
|
officia deserunt mollit anim id est laborum.")
|
||||||
|
|
||||||
|
(deftest single-regex-test
|
||||||
|
(testing "single regex, single text source"
|
||||||
|
(let [result (grep/grep #"t[,.]" (StringReader. lorem-ipsum))]
|
||||||
|
(is (= [1 2 4 6] (mapv :line-number result))))))
|
||||||
|
|
||||||
|
(deftest multi-regex-test
|
||||||
|
(testing "multiple regexes, multiple text sources"
|
||||||
|
(let [result (grep/grep [#"t[,.]" #"s\s"] [(StringReader. lorem-ipsum) (io/resource "multigrep/haiku.txt")])]
|
||||||
|
(is (= 8 (count result))))))
|
||||||
3
test-resources/lib_tests/multigrep/haiku.txt
Normal file
3
test-resources/lib_tests/multigrep/haiku.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
haikus are easy
|
||||||
|
but sometimes they make no sense
|
||||||
|
refrigerator
|
||||||
Loading…
Reference in a new issue