This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-09
Channels
- # admin-announcements (6)
- # arachne (3)
- # beginners (66)
- # boot (84)
- # braveandtrue (1)
- # cider (84)
- # cljs-site (1)
- # cljsjs (3)
- # cljsrn (2)
- # clojure (138)
- # clojure-austin (2)
- # clojure-czech (1)
- # clojure-gamedev (6)
- # clojure-germany (15)
- # clojure-italy (2)
- # clojure-russia (26)
- # clojure-uk (51)
- # clojurescript (97)
- # css (1)
- # cursive (1)
- # datascript (13)
- # datomic (6)
- # devcards (2)
- # docker (1)
- # emacs (5)
- # hoplon (9)
- # immutant (5)
- # jobs (4)
- # leiningen (6)
- # luminus (27)
- # mount (4)
- # om (16)
- # om-next (4)
- # onyx (15)
- # other-languages (36)
- # overtone (1)
- # proton (3)
- # quil (1)
- # re-frame (11)
- # reagent (24)
- # rum (4)
- # spacemacs (3)
anyone know of a function that checks if a string is alphanumeric?
@thug.nasty: does (defn alphanumeric? [s] (not (re-find #"[^A-Za-z0-9]" s)))
work for you?
@fasiha: where does that exist?
ah haha
I wrote my own, but I figured I’d ask instead of reinventing the wheel
Also, sorry that snippet shows how much of an anglophone I am… doesn't check non-ASCII alphabets or other scripts.
hah yes
@thug.nasty: https://github.com/funcool/cuerdas there's some nice string manipulation functions here
would be good to get a native Spanish speaker in here to confirm but I think “cuerda” has the same generality as the English “string"
ah, I see there’s a reference to a song about guitars on the README, guess I missed that bit
I suppose that puts it into context 😉
Hm, adding ^:whatever
metadata annotations doesn’t work in macros because the annotation is applied to the sym inside the macro, right? So how do I do that? with-meta?
whats the idiomatic way to map a sequence of functions across data, where each fn expects the whole collection and does some transformation?
user=> (clojure.walk/macroexpand-all '(defn foo [] (defn bar [])))
(def foo (fn* ([] (def bar (fn* ([]))))))
What is the preferred way to setup data for each clojure.test test? Right now I am just surrounding each test with a let block. Is this the normal way to do it?
@kenny: have you investigated fixtures? That may help, depending on what you’re trying to do: http://clojure.github.io/clojure/clojure.test-api.html#clojure.test/use-fixtures
@ddellacosta: I have looked at fixtures but it looks like you can only set them up for ALL tests. I want to be able to setup data for each test individually.
I see. I have not come up with a special way to do that, and I do just end up doing a fair amount of (deftest does-something (let [a …, b …] etc.)
In some cases I have helper functions to populate values
Right. That is where I am at right now. Just wasn't sure if there was a more conventional way to do that..
I would also love to hear it if anyone else has any other strategies that aren’t simply “use this other testing library…"
put let
s in each test. That's clear & conscise.
@stuartsierra: The only problem with that is it is a pain to run each test individually in the repl.
What's the source of pain?
For example:
(deftest example-test
(let [result (+ 1 2)]
(is (= 3 result))
(is (number? result))))
There is no way to run each is
individually. I must run the entire let block in the repl in order to run the tests. The solution here is not clear. We do not want to define the same let block for every test because both of the tests can use the same result
value.@stuartsierra: This may not be solvable through the clojure.test library, rather through some sort of repl integration. The repl needs additional context in order to run the individual test with it's "data" defined.
I typically treat a deftest
as the smallest unit, one "test".
It seems that is not the pattern that clojure.test is encouraging with multiple is
s per deftest
.
It's up to you
I've used various styles: many assertions per test, one assertion per test.
I aim for each deftest
to describe exactly one "thing," although I may make multiple assertions about that thing.
And that makes sense. But there is currently no facility to run assertions individually in a test with multiple assertions. This is mostly valuable when first creating the tests and being able to interact with each assertion.
it's just copy-and-paste with the REPL
hmmm, I don’t see why you would need to do so. I feel that if that is ever needed, it means the tests are not atomic enough.
@roberto: It is useful when first creating the tests and when debugging breaking assertion(s). It would be useful to continually rerun that single assertion without rerunning all of the assertions.
if assertions are grouped together, I think it is because they are tightly related/coupled, that if one breaks, they should all breaks. If one is run in isolation, you still need to run the others because a changed made to make that single assertion pass can break the others.
like the example above, if (number? result)
passes, it doesn’t mean that the number is 3
Yup, agreed. But it is much easier to debug the output of a single assertion rather than the output of more than one.
with a debugger you can cancel execution if the values are not what you expect when it hits that break point.
No. Just in the repl. Say I have 10 assertions in a deftest and a breaking change is made causing all 10 assertions the break. The test will now output 10 failing tests. That's great because all 10 assertions failed in that test. Now I want to start debugging why that test failed. I would probably start by looking at the first assertion and determining why it failed. I would want to make change, reload the file in the repl and rerun that individual assertion to see the output of the single assertion without polluting my repl with the output of all 10 failing assertions.
oh, I use a debugger for that. I can run evaluations when the execution is paused and I can see what the output is.
Hmm.. I have not used a debugger with Clojure before. Do you use Cursive and do you know if Cursive has a debugger?
you’re welcome. Having a debugger for this purpose is very handy. Has made my dev eperience with clojure even more enjoyable.
Sounds like it. That was always a large pain point when writing and debugging tests in Clojure for me. Sounds like there is a great solution to my problem 😃
Hi - I’m working on adding some type-hints to some code that does a bit of java interop, and am a bit confused by the following reflection warning Reflection warning, fernet/core.clj:47:4 - call to init can't be resolved.
The code being hinted is here: https://github.com/derwolfe/fernet-clj/pull/2/files#diff-52b6ee43a51f49a9a3235d5df781ece9R47
What I’m finding a bit confusing, is that the type of instance is known, so why would it need to be hinted? Or am I thinking about this incorrectly
I would think it would be needed on the return to (Cipher/getInstance "AES/CBC/PKCS7Padding”)
, whatever that is, rather
since you are using a doto
@ddellacosta: : the compiler understands that call and infers type automatically
@ghadi: if that’s the case, why is it complaining about .init
? I’m confused then
oh, or are you saying…right, gotcha.
ghadi: yep, I think that solved it.
clojure (defn aes128cbc
[mode key iv message]
(.doFinal
(doto (Cipher/getInstance "AES/CBC/PKCS7Padding")
(.init
^int (mode {:encrypt Cipher/ENCRYPT_MODE
:decrypt Cipher/DECRYPT_MODE})
(new SecretKeySpec key "AES")
(new IvParameterSpec iv)))
message))
is it reasonable/idiomatic to require clojure.walk just so I can transform map keys from strings into keywords?
sorta -- it actually goes through a different path. Here's @nathanmarz chiming in with specter 😃
Thanks lol
Yea this is a basic Specter use case
nathanmarz: does FIRST go through sequential, or is there a way to specifically tear mapentry's?
ALL navigates to each key/value pair independently
internaly it coerces mapentry into a vector of [key value]
FIRST uses a protocol to do updates – in the case of vectors it will do (assoc myvec 0 newval)
What is the meta tag, based on class, that an array of doubles should have? e.g. For string it is ^{:tag java.lang.String}
. I know you can use ^doubles
but I want a way that I can programmatically determine the correct tag.
Couldn't find any existing function for this.. For those interested.. Just had wrote a lookup table
{Double 'doubles
Integer 'ints
Float 'floats
Long 'longs
Boolean 'booleans
Short 'shorts
Byte 'bytes
Character 'chars}
Anyone use this? https://github.com/semperos/clj-webdriver
I've got it working with phantomjs except the window size is tiny when i take a screenshot.