package ppx_expect_nobase
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=304f9e7141a486c0206ecdfcde09e57a022481a71539e5dbb530c0224e7e5d33
doc/ppx_expect_nobase.matcher/Expect_test_matcher/Cst/index.html
Module Expect_test_matcher.Cst
Source
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.
type 'a single_line = {
leading_blanks : string;
(*regexp: "
*)\t
*"trailing_spaces : string;
(*regexp: "
*)\t\n
*"orig : 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
|}]
type 'a multi_lines = {
leading_spaces : string;
(*regexp: "\(
*)\t
*\n\)*"trailing_spaces : string;
(*regexp: "
*)\t
*" or "\(\n\t
*\)*"indentation : string;
(*regexp: "
*)\t
*"lines : 'a Line.t 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:
- 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
|}]
type 'a t =
| Empty of string
(*regexp: "
*)\t\n
*"| Single_line of 'a single_line
| Multi_lines of 'a multi_lines
For single line expectation, leading blanks and trailing spaces are dropped.
Remove blank lines at the beginning and end of the list.
val reconcile :
'a t ->
lines:'a Line.t list ->
default_indentation:int ->
pad_single_line:bool ->
'a t
Given a contents t
and a list of lines
, try to produce a new contents containing lines
but with the same formatting 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
).
Compute 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.