Module Expect_test_matcher.Cst
Concrete syntax tree of expectations and actual outputs
module Line : sig ... end
type 'a single_line
=
{
leading_blanks : Base.string;
regexp: "
\t
*"trailing_spaces : Base.string;
regexp: "
\t\n
*"orig : Base.string;
regexp: "
^ \t\n
(^\n
*^ \t\n
)?"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 |}]
val sexp_of_single_line : ('a -> Base.Sexp.t) -> 'a single_line -> Base.Sexp.t
val compare_single_line : ('a -> 'a -> Base.int) -> 'a single_line -> 'a single_line -> Base.int
val equal_single_line : ('a -> 'a -> Base.bool) -> 'a single_line -> 'a single_line -> Base.bool
type 'a multi_lines
=
{
leading_spaces : Base.string;
regexp: "\(
\t
*\n\)*"trailing_spaces : Base.string;
regexp: "
\t
*" or "\(\n\t
*\)*"indentation : Base.string;
regexp: "
\t
*"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, whiletrailing_spaces
is either:- trailing blanks on the last line if of the form:
[%expect {| abc def |}]
- all trailing spaces from the newline character (inclusive) on the last non-blank line to the end if of the form:
[%expect {| abc def |}]
val sexp_of_multi_lines : ('a -> Base.Sexp.t) -> 'a multi_lines -> Base.Sexp.t
val compare_multi_lines : ('a -> 'a -> Base.int) -> 'a multi_lines -> 'a multi_lines -> Base.int
val equal_multi_lines : ('a -> 'a -> Base.bool) -> 'a multi_lines -> 'a multi_lines -> Base.bool
type 'a t
=
|
Empty of Base.string
regexp: "
\t\n
*"|
Single_line of 'a single_line
|
Multi_lines of 'a multi_lines
val invariant : ('a -> Base.unit) -> 'a t -> Base.unit
val empty : 'a t
val map : 'a t -> f:(Base.string -> 'a -> 'b) -> 'b t
val data : 'a t -> blank:'a -> 'a Base.list
val strip : 'a t -> 'a t
val to_string : _ t -> Base.string
val to_lines : 'a t -> 'a Line.t Base.list
For single line expectation, leading blanks and trailing spaces are dropped.
val trim_lines : 'a Line.t Base.list -> 'a Line.t Base.list
Remove blank lines at the beginning and end of the list.
val reconcile : 'a t -> lines:'a Line.t Base.list -> default_indentation:Base.int -> pad_single_line:Base.bool -> 'a t
Given a contents
t
and a list oflines
, try to produce a new contents containinglines
but with the same formating ast
.default_indentation
is the indentation to use in case we ignoret
's indentation (for instance ift
isSingle_line
orEmpty
).
val extract_indentation : 'a Line.t Base.list -> Base.string * 'a Line.t Base.list
Compuute 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.list
All the
.orig
fields ofLine.t
orsingle_line
values, using""
for blank lines.