Fork me on GitHub

Hi, how does one deal with unsupported escape chars in strings? "[1A],[1ZA],[3B],[8A],[19A]|http:\/\/\/place\/img1.jpg|I" this is response i get from one site which is location of a picture. i just get erros what ever i do saying \/ is unsupported which is ok but i can't even replace them or do anything with that kind of string. How do i deal with this?


@lepistane How are you trying to read the string? You should be able to read it as raw bytes, then replace \/ then process it as strings.


In a luminus project, for a postgres connection, in dev-config.edn, should it be with or without jdbc in :database-url "jdbc:?


well test it 😄 try both see how it goes once you finish you will know it's without jdbc


the template just showed


So I'm trying write some unit tests where I need to mock some imported static java functions below

  (:import [com.auth0.jwt JWT JWTVerifier]))

(defn decode-token [JWT token]
    (JWT/decode token)
    (catch Exception e
      (log/warn "Invalid Token: " e)


  (:import [com.auth0.jwt JWT JWTVerifier]))

(def mock-jwt (proxy [JWT] []
                (decode [^String a] "decoded")))

(deftest decode-token-test
  (testing "should decode"
    (println (decode-token mock-jwt "foo"))))


mock-jwt/decode is not being overloaded by my proxy call. What am I doing wrong?


it's a little confusing that you have imported JWT and also have a parameter called JWT. I'm honestly not sure which is resolved there. I'm also not convinced this test tests any actual code besides the try/catch and logging but that doesn't seem to be what you are testing. But I would do something like this:


@dpsutton I'm aware of that but we are trying to be strict about code coverage here.


also thought it would be better to pass in JWT to the function so that I can easily mock it and the function becomes pure.


the problem here is having an object with the same name as the class


(or at least potential problem)


if your param is x x/foo shouldn't work - you can't call static methods on classes passed as args like that


if x/foo is referring to the class x which was imported, your param is being ignored


@U6X9NEMP1 If interested in more details on that subject: Clojure has no secret power when it comes to doing something like a static method call on a class (this is just Java interop), it information needed at compile-time, otherwise you have to use reflection.


If you are familiar with Java, think of how you would try to do what you what you did there in Java and you’d run into the same problem


void blah ( Class<JWT> jwtClass ) {

jwtClass.decode("thing"); // not going to work

Volodymyr Sereda16:05:14

You might find with-redefs useful. It lets you redefine a function for testing without having to pass it in as an argument.


replacing a parameter in order to use with-redefs is a bad idea - with-redefs is fragile, even for testing

Volodymyr Sereda16:05:25

How is it fragile?


it's a global mutation that has no respect for scope


and it only works on some functions - anything statically compiled or special cased in the clojure compiler won't be redeffed properly


in order to replace the class with something you with-redef, you need it to be a var, at that point you've already done the fix that allows you to use it as an arg

Volodymyr Sereda16:05:14

It only redefines things within the with-redefs block though. We use it frequently for testing and it helps us write code that doesn’t care about the details of how it’s being tested.


it doesn't, it applies to all threads until that block exits


it means you can't run any tests concurrently

Volodymyr Sereda16:05:19

Hm, interesting to know 🙂 That’s not something we’re doing so I never came across that.


i'm a big fan of the higher order type and make it easy to pass in a test param. and then def or defn a version in the code that correctly composes the actual implementation. I've found that writing code that cares about the details of how its being tested makes cleaner code often

👍 4

thanks @alexmiller I was looking for a good writeup and failing :D


how do I programmatically access the source code of a function as a string?


source :: functionName -> String


nevermind I found it in clojure.repl/source-fn