Commit Graph
31 Commits
Author SHA1 Message Date
Michał Muskała aace60b863 Fix bug in Inspect.AlgebraTest (#10128) 2020-06-25 17:03:32 +02:00
Andrea Leopardi 1d14366ba4 Improve one test in the Inspect.Algebra test case 2018-03-20 14:48:01 +01:00
José Valim c063093d32 Inspect tuples closer to the formatter, closes #6509 2017-12-06 12:01:48 +01:00
José Valim d126531e58 Format more files with little formatting requirement 2017-10-10 19:36:20 +02:00
José Valim 294d44985a Improve docs and tests for algebra group 2017-10-09 13:47:21 +02:00
José Valim c8153ace25 Add Inspect.Algebra.container_doc/6
This function replaces surround_many as it attempts to fit
as many algebra documents on the same line if and only if
all documents are simple.

A simple document is a document made only of strings,
without breaks. This allows us to print lists of complex
structures with one element per line but lists of integers
or lists of atoms still try to fit as much as possible in a
single-line.
2017-09-21 14:51:15 +02:00
José Valim 2efb7691f7 Rename cancel_break to next_break_fits 2017-08-31 20:29:32 +02:00
José Valim 9c9d4daa7c Improve coverage of inspect algebra 2017-08-30 15:35:46 +02:00
José Valim f0d8219240 No longer group by default to avoid full document traversals 2017-08-29 11:56:35 +02:00
José Valim ef08afc34d Introduce force_break and cancel_break
Those replace the mechanisms imposed by hard lines and
next break fits but without the coupling to a given
representation.
2017-08-28 01:25:36 +02:00
José Valim 056450d575 Rename lines to soft and hard instead of boolean 2017-08-26 19:49:37 +02:00
José Valim 94da892129 Instead of flex groups, use flex breaks 2017-08-26 18:54:26 +02:00
José Valim eead746e9e Add conditional nesting 2017-08-26 17:22:52 +02:00
José Valim 0001511de0 Introduce forced line breaks 2017-08-26 11:04:47 +02:00
José Valim 6c0e35f6ab Make sure all lines in group must fit 2017-08-26 10:22:25 +02:00
José Valim 3b7bf4ed53 Add :strict and :flex modes to Inspect.Algebra
We have also changed all data-structures except non-keyword
lists and tuples to use strict mode. This means %Plug.Conn{}
was formatted as

    %Plug.Conn{adapter: {Plug.Adapters.Cowboy.Conn, :...}, assigns: %{},
     before_send: [], body_params: %Plug.Conn.Unfetched{aspect: :body_params},
     cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: false,
     host: "localhost", method: "GET", owner: #PID<0.272.0>,
     params: %Plug.Conn.Unfetched{aspect: :params}, path_info: ["favicon.ico"],
     path_params: %{}, peer: {{127, 0, 0, 1}, 64355}, port: 4000, private: %{},
     query_params: %Plug.Conn.Unfetched{aspect: :query_params}, query_string: "",
     remote_ip: {127, 0, 0, 1}, req_cookies: %Plug.Conn.Unfetched{aspect: :cookies},
     req_headers: [{"host", "localhost:4000"}, {"connection", "keep-alive"},
      {"user-agent",
       "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"},
      {"accept", "image/webp,image/apng,image/*,*/*;q=0.8"}, {"dnt", "1"},
      {"referer", "http://localhost:4000/"},
      {"accept-encoding", "gzip, deflate, br"},
      {"accept-language", "en-US,en;q=0.8,pt;q=0.6"},
      {"cookie", "foo=bar"}],
     request_path: "/favicon.ico", resp_body: nil, resp_cookies: %{},
     resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}],
     scheme: :http, script_name: [], secret_key_base: nil, state: :unset,
     status: nil}

will now be formatted as

    %Plug.Conn{
      adapter: {Plug.Adapters.Cowboy.Conn, :...},
      assigns: %{},
      before_send: [],
      body_params: %Plug.Conn.Unfetched{aspect: :body_params},
      cookies: %Plug.Conn.Unfetched{aspect: :cookies},
      halted: false,
      host: "localhost",
      method: "GET",
      owner: #PID<0.330.0>,
      params: %Plug.Conn.Unfetched{aspect: :params},
      path_info: ["favicon.ico"],
      path_params: %{},
      peer: {{127, 0, 0, 1}, 64696},
      port: 4000,
      private: %{},
      query_params: %Plug.Conn.Unfetched{aspect: :query_params},
      query_string: "",
      remote_ip: {127, 0, 0, 1},
      req_cookies: %Plug.Conn.Unfetched{aspect: :cookies},
      req_headers: [{"host", "localhost:4000"}, {"connection", "keep-alive"},
       {"user-agent",
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"},
       {"accept", "image/webp,image/apng,image/*,*/*;q=0.8"}, {"dnt", "1"},
       {"referer", "http://localhost:4000/"},
       {"accept-encoding", "gzip, deflate, br"},
       {"accept-language", "en-US,en;q=0.8,pt;q=0.6"},
       {"cookie", "foo=bar"}],
      request_path: "/favicon.ico",
      resp_body: nil,
      resp_cookies: %{},
      resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}],
      scheme: :http,
      script_name: [],
      secret_key_base: nil,
      state: :unset,
      status: nil
    }

Notice this won't affect logs, error messages and so on.
Those are always "flat" (single line).
2017-07-19 18:59:13 +02:00
Aleksei Magusev 44d26b493a Tidy up code around syntax highlighting in IEx 2016-11-20 17:20:38 +01:00
Andrea Leopardi a0e695b180 Fix the spec and guards for Inspect.Algebra.surround_many/6 (#5450)
The old spec said that the "left", "right", and "separator" arguments
had to be binaries but they can instead be documents.
2016-11-15 17:48:34 +01:00
Louis Pilfold 16a7758955 Syntax highlighting of IEx results (#5355) 2016-11-15 12:11:13 +01:00
Aleksei Magusev 96da837136 Emit warning when variable is being expanded to function call (#3517) 2016-06-11 22:31:03 +02:00
Aleksei Magusev f8a82f604a Move doctests from central place to the modules they describe 2015-11-25 00:26:07 +01:00
eksperimental ecff4ad729 Simplify code by using pipe operator 2015-10-25 12:59:11 +07:00
gabriele.lana feacf14a35 surround_many/5 handles empty documents
`surround/3` correctly handles empty documents, ex

    iex> doc = Inspect.Algebra.surround "[", Inspect.Algebra.empty, "]"
    iex> Inspect.Algebra.format(doc, 80) |> IO.iodata_to_binary
    "[]"

But `surround_many/5` didn't

    iex> fun = fn(d, _) -> d end
    iex> opts = %Inspect.Opts{}
    iex> what = ["a", Inspect.Algebra.empty]
    iex> doc = Inspect.Algebra.surround_many("[", what, "]", opts, fun, ",")
    iex> Inspect.Algebra.format(doc, 80) |> IO.iodata_to_binary
    "[a, ]"

This is what I expect and what it does now

    iex> doc = Inspect.Algebra.surround_many("[", what, "]", opts, fun, ",")
    iex> Inspect.Algebra.format(doc, 80) |> IO.iodata_to_binary
    "[a]"
2015-05-27 22:38:26 +02:00
José Valim c42fe88dcc Provide Inspect.Algebra.format/2 that returns iodata 2014-07-19 13:32:45 +02:00
José Valim a80f9d9ae1 Remove dependency on Record.Backend 2014-05-16 12:21:36 +02:00
José Valim 56f15d9f4e Do not add spaces after { and before }
This makes the source code consistent with the result
returned by inspect/2.
2014-04-21 19:06:35 +02:00
José Valim c240a49f04 Ensure doc_line resets algebra formatting line buffer, closes #2014 2014-01-23 09:09:56 +01:00
José Valim e65eee49c4 Make inspect in general 20% faster
There are two main optimizations:

1. We have optimized Module.concat/2 (it is roughly 100% faster)
2. We have optimized rendering of Inspect.Algebra by skipping
   the intermediate s_doc representation. This reduces memory
   allocation and skips one extra pass on rendering.
2013-11-19 10:21:31 +01:00
José Valim 2dc1e41aca Pretty printer now prints grouped elements in the same line, closes #1383
This implementation slightly changes the semantic of Lindig's algorithm
to allow elements that belong to the same group to be printed together
in the same line, even if they do not fit the line fully. This was achieved
by changing `:break` to mean a possible break and `:flat` to force a flat
structure. Then deciding if a break works as a newline is just a matter
of checking if we have enough space until the next break that is not
inside a group (which is still flat).
2013-07-09 02:24:59 +02:00
José Valim 35d019559d Remove the need for Inspect.Utils.return and Inspect.Algebra.text 2013-07-05 23:19:39 +02:00
José Valim b335b1663d Rename Binary.Inspect -> Inspect and Wadler -> Inspect.Algebra 2013-07-05 22:15:16 +02:00