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

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
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
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
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
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
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
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
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
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement