Concrete syntax tree of expectations and actual outputs
These types represent the contents of an %expect node or of the actual output. We
keep information about the original layout so that we can give an corrected
expectation that follows the original formatting.
In the following names, blank means ' ' or '\t', while space means blank or newline.
module Line : sig ... endtype 'a single_line = {leading_blanks : Base.string; | (** regexp: " |
trailing_spaces : Base.string; | (** regexp: " |
orig : Base.string; | (** regexp: " |
data : 'a; |
}Single line represent %expect nodes with data on the first line but not on the
subsequent ones.
For instance:
[%expect " blah "];
[%expect {| blah
|}]
include sig ... endval compare_single_line : ('a ‑> 'a ‑> Base.int) ‑> 'a single_line ‑> 'a single_line ‑> Base.intval sexp_of_single_line : ('a ‑> Sexplib.Sexp.t) ‑> 'a single_line ‑> Sexplib.Sexp.ttype 'a multi_lines = {leading_spaces : Base.string; | (** regexp: "\( |
trailing_spaces : Base.string; | (** regexp: " |
indentation : Base.string; | (** regexp: " |
lines : 'a Line.t Base.list; | (** regexp: not_blank (.* not_blank)? *) |
}Any %expect node with one or more newlines and at least one non-blank line.
This also include the case with exactly one non-blank line such as:
[%expect {|
blah
|}]
This is to preserve this formatting in case the correction is multi-line.
leading_spaces contains everything until the first non-blank line, while
trailing_spaces is either:
[%expect {|
abc
def |}]
[%expect {|
abc
def
|}]
include sig ... endval compare_multi_lines : ('a ‑> 'a ‑> Base.int) ‑> 'a multi_lines ‑> 'a multi_lines ‑> Base.intval sexp_of_multi_lines : ('a ‑> Sexplib.Sexp.t) ‑> 'a multi_lines ‑> Sexplib.Sexp.ttype 'a t = | Empty of Base.string | (** regexp: " |
| Single_line of 'a single_line | |
| Multi_lines of 'a multi_lines |
include sig ... endval sexp_of_t : ('a ‑> Sexplib.Sexp.t) ‑> 'a t ‑> Sexplib.Sexp.tval empty : 'a tval map : 'a t ‑> f:(Base.string ‑> 'a ‑> 'b) ‑> 'b tval to_string : _ t ‑> Base.stringval reconcile : 'a t ‑> lines:'a Line.t Base.list ‑> default_indentation:Base.int ‑> pad_single_line:Base.bool ‑> 'a tGiven a contents t and a list of lines, try to produce a new contents containing
lines but with the same formating as t.
default_indentation is the indentation to use in case we ignore t's indentation
(for instance if t is Single_line or Empty).
val extract_indentation : 'a Line.t Base.list ‑> Base.string * 'a Line.t Base.listCompuute the longest indentation of a list of lines and trim it from every line. It returns the found indentation and the list of trimmed lines.
val stripped_original_lines : _ t ‑> Base.string Base.listAll the .orig fields of Line.t or single_line values, using "" for blank
lines.