script

script

Split output in multiple lines in doc test

I have read doc test documentation. And apply it in my project but I couldn’t figure this out.
If my output is very long like a query then How can i split it on multiple line .

     iex> query_opts = %{
     ...>   "$select" => %{"$fields" => ["name", "designation", "experience_years"]},
     ...>   "$where" => %{"designation" => %{"$ilike" => "%surge %"}},
     ...>   "$order" => %{"rating" => "$asc"}
     ...> }
     iex> #{FatEcto.FatQuery}.build(FatEcto.FatDoctor, query_opts)
     #Ecto.Query<from f in FatEcto.FatDoctor, where: ilike(fragment("(?)::TEXT", f.designation), ^"%surge %") and ^true, order_by: [asc: f.rating], select: map(f, [:name, :designation, :experience_years])>

this works and test passes but i would like the result like this:

       #Ecto.Query<from f in FatEcto.FatDoctor, where: ilike(fragment("(?)::TEXT", f.designation), ^"%surge %") 
       and ^true,
       order_by: [asc: f.rating], 
       select: map(f, [:name, :designation, :experience_years])>

It fails because I am using line break and the result of this function using spaces:

           left:  "#Ecto.Query<from f in FatEcto.FatDoctor, where: ilike(fragment(\"(?)::TEXT\", f.designation), 
           ^\"%surge %\") and ^true, order_by: [asc: f.rating], select: map(f, [:name, :designation, 
           :experience_years])>"

           right: "#Ecto.Query<from f in FatEcto.FatDoctor, where: ilike(fragment(\"(?)::TEXT\", f.designation), 
          ^\"%surge %\")\nand ^true,\norder_by: [asc: f.rating],\nselect: map(f, [:name, :designation, 
        :experience_years])>"

Is there any workaround?

Thanks

Marked As Solved

josevalim

josevalim

Creator of Elixir

Unfortunately that is not possible when you are matching on the printed value, which is exactly what you are doing by matching on #Ecto.Query. I don’t think there is a fix in this case, sorry! :frowning:

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement