Fix reporting tests

This commit is contained in:
Richard Feldman 2022-11-24 10:12:38 -05:00
parent d2900630f2
commit ed0c64ca7c
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
3 changed files with 65 additions and 41 deletions

View file

@ -1238,9 +1238,8 @@ fn to_bad_ident_expr_report<'b>(
lines.convert_region(surroundings),
lines.convert_region(region),
),
alloc.concat([alloc.reflow(
r"I recommend using camelCase, it is the standard in the Roc ecosystem.",
)]),
alloc.concat([alloc
.reflow(r"I recommend using camelCase. It's the standard style in Roc code!")]),
])
}

View file

@ -549,8 +549,8 @@ impl<'a> RocDocAllocator<'a> {
let this_line_number_length = line_number.len();
let line = self.src_lines[i as usize];
let rest_of_line = if !line.trim().is_empty() {
let is_line_empty = line.trim().is_empty();
let rest_of_line = if !is_line_empty {
self.text(line).indent(indent)
} else {
self.nil()
@ -572,11 +572,17 @@ impl<'a> RocDocAllocator<'a> {
.append(self.text(GUTTER_BAR).annotate(Annotation::GutterBar))
.append(rest_of_line)
} else {
self.text(" ".repeat(max_line_number_length - this_line_number_length))
let up_to_gutter = self
.text(" ".repeat(max_line_number_length - this_line_number_length))
.append(self.text(line_number).annotate(Annotation::LineNumber))
.append(self.text(GUTTER_BAR).annotate(Annotation::GutterBar))
.append(self.text(" "))
.append(rest_of_line)
.append(self.text(GUTTER_BAR).annotate(Annotation::GutterBar));
if is_line_empty {
// Don't put an trailing space after the gutter
up_to_gutter
} else {
up_to_gutter.append(self.text(" ")).append(rest_of_line)
}
};
result = result.append(source_line);
@ -667,8 +673,8 @@ impl<'a> RocDocAllocator<'a> {
let this_line_number_length = line_number.len();
let line: &str = self.src_lines.get(i as usize).unwrap_or(&"");
let rest_of_line = if !line.trim().is_empty() {
let is_line_empty = line.trim().is_empty();
let rest_of_line = if !is_line_empty {
self.text(line)
.annotate(Annotation::CodeBlock)
.indent(indent)
@ -691,11 +697,17 @@ impl<'a> RocDocAllocator<'a> {
.append(self.text(GUTTER_BAR).annotate(Annotation::GutterBar))
.append(rest_of_line)
} else {
self.text(" ".repeat(max_line_number_length - this_line_number_length))
let up_to_gutter = self
.text(" ".repeat(max_line_number_length - this_line_number_length))
.append(self.text(line_number).annotate(Annotation::LineNumber))
.append(self.text(GUTTER_BAR).annotate(Annotation::GutterBar))
.append(self.text(" "))
.append(rest_of_line)
.append(self.text(GUTTER_BAR).annotate(Annotation::GutterBar));
if is_line_empty {
// Don't put an trailing space after the gutter
up_to_gutter
} else {
up_to_gutter.append(self.text(" ")).append(rest_of_line)
}
};
result = result.append(source_line);

View file

@ -4393,16 +4393,20 @@ mod test_reporting {
test_report!(
comment_with_tab,
"# comment with a \t\n4",
@r###"
TAB CHARACTER tmp/comment_with_tab/Test.roc
|golden| pretty_assertions::assert_eq!(
golden,
&format!(
r###"── TAB CHARACTER ─────────────────────────────── tmp/comment_with_tab/Test.roc ─
I encountered a tab character
I encountered a tab character
4 # comment with a
4 # comment with a {}
^
Tab characters are not allowed.
"###
Tab characters are not allowed."###,
"\t"
)
)
);
// TODO bad error message
@ -5680,23 +5684,27 @@ All branches in an `if` must have the same type!
main = 5 -> 3
"#
),
@r###"
UNKNOWN OPERATOR tmp/wild_case_arrow/Test.roc
|golden| pretty_assertions::assert_eq!(
golden,
&format!(
r###"── UNKNOWN OPERATOR ───────────────────────────── tmp/wild_case_arrow/Test.roc ─
This looks like an operator, but it's not one I recognize!
This looks like an operator, but it's not one I recognize!
1 app "test" provides [main] to "./platform"
2
3 main =
4 main = 5 -> 3
1 app "test" provides [main] to "./platform"
2
3 main =
4 main = 5 -> 3
^^
Looks like you are trying to define a function.
Looks like you are trying to define a function.{}
In roc, functions are always written as a lambda, like
In roc, functions are always written as a lambda, like{}
increment = \n -> n + 1
"###
increment = \n -> n + 1"###,
' ', ' '
)
)
);
#[test]
@ -9965,16 +9973,21 @@ All branches in an `if` must have the same type!
f 1 _ 1
"#
),
@r###"
SYNTAX PROBLEM /code/proj/Main.roc
|golden| pretty_assertions::assert_eq!(
golden,
&format!(
r###"── SYNTAX PROBLEM ──────────────────────────────────────── /code/proj/Main.roc ─
Underscores are not allowed in identifier names:
Underscores are not allowed in identifier names:
6 f 1 _ 1
6 f 1 _ 1
{}
I recommend using camelCase, it is the standard in the Roc ecosystem.
"###
I recommend using camelCase. It's the standard style in Roc code!
"###,
" " // TODO make the reporter not insert extraneous spaces here in the first place!
),
)
);
test_report!(