mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Binop precedence problem report test
This commit is contained in:
parent
2e2ce0f0de
commit
30dadd882c
4 changed files with 46 additions and 26 deletions
|
@ -133,6 +133,6 @@ impl std::fmt::Display for BinOp {
|
||||||
Pizza => "|>",
|
Pizza => "|>",
|
||||||
};
|
};
|
||||||
|
|
||||||
write!(f, "({})", as_str)
|
write!(f, "{}", as_str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,13 @@ edition = "2018"
|
||||||
roc_collections = { path = "../collections" }
|
roc_collections = { path = "../collections" }
|
||||||
roc_region = { path = "../region" }
|
roc_region = { path = "../region" }
|
||||||
roc_module = { path = "../module" }
|
roc_module = { path = "../module" }
|
||||||
|
roc_parse = { path = "../parse" }
|
||||||
roc_problem = { path = "../problem" }
|
roc_problem = { path = "../problem" }
|
||||||
roc_types = { path = "../types" }
|
roc_types = { path = "../types" }
|
||||||
roc_load = { path = "../load" }
|
roc_load = { path = "../load" }
|
||||||
roc_can = { path = "../can" }
|
roc_can = { path = "../can" }
|
||||||
inlinable_string = "0.1.0"
|
inlinable_string = "0.1.0"
|
||||||
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
roc_constrain = { path = "../constrain" }
|
roc_constrain = { path = "../constrain" }
|
||||||
roc_builtins = { path = "../builtins" }
|
roc_builtins = { path = "../builtins" }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::report::ReportText::{Batch, Module, Region, Value};
|
use crate::report::ReportText::{Batch, BinOp, Module, Region, Value};
|
||||||
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
||||||
use roc_problem::can::PrecedenceProblem::BothNonAssociative;
|
use roc_problem::can::PrecedenceProblem::BothNonAssociative;
|
||||||
use roc_problem::can::Problem;
|
use roc_problem::can::Problem;
|
||||||
|
@ -24,6 +24,7 @@ pub struct Palette {
|
||||||
pub line_number: Color,
|
pub line_number: Color,
|
||||||
pub gutter_bar: Color,
|
pub gutter_bar: Color,
|
||||||
pub module_name: Color,
|
pub module_name: Color,
|
||||||
|
pub binop: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
|
@ -49,6 +50,7 @@ pub const TEST_PALETTE: Palette = Palette {
|
||||||
line_number: Color::Cyan,
|
line_number: Color::Cyan,
|
||||||
gutter_bar: Color::Magenta,
|
gutter_bar: Color::Magenta,
|
||||||
module_name: Color::Green,
|
module_name: Color::Green,
|
||||||
|
binop: Color::Green,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Color {
|
impl Color {
|
||||||
|
@ -109,10 +111,21 @@ pub fn can_problem(filename: PathBuf, problem: Problem) -> Report {
|
||||||
texts.push(plain_text("\". Adding an underscore at the start of a variable name is a way of saying that the variable is not used."));
|
texts.push(plain_text("\". Adding an underscore at the start of a variable name is a way of saying that the variable is not used."));
|
||||||
}
|
}
|
||||||
Problem::PrecedenceProblem(BothNonAssociative(region, left_bin_op, right_bin_op)) => {
|
Problem::PrecedenceProblem(BothNonAssociative(region, left_bin_op, right_bin_op)) => {
|
||||||
texts.push(plain_text(&*format!(
|
if left_bin_op.value == right_bin_op.value {
|
||||||
"You cannot mix {} and {} without parentheses",
|
texts.push(plain_text("Using more than one "));
|
||||||
left_bin_op.value, right_bin_op.value
|
texts.push(BinOp(left_bin_op.value));
|
||||||
)));
|
texts.push(plain_text(
|
||||||
|
" like this requires parentheses, to clarify how things should be grouped.",
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
texts.push(plain_text("Using "));
|
||||||
|
texts.push(BinOp(left_bin_op.value));
|
||||||
|
texts.push(plain_text(" and "));
|
||||||
|
texts.push(BinOp(right_bin_op.value));
|
||||||
|
texts.push(plain_text(
|
||||||
|
" together requires parentheses, to clarify how they should be grouped.",
|
||||||
|
))
|
||||||
|
}
|
||||||
texts.push(Region(region));
|
texts.push(Region(region));
|
||||||
}
|
}
|
||||||
Problem::UnsupportedPattern(_pattern_type, _region) => {
|
Problem::UnsupportedPattern(_pattern_type, _region) => {
|
||||||
|
@ -165,6 +178,8 @@ pub enum ReportText {
|
||||||
/// The documentation for this symbol.
|
/// The documentation for this symbol.
|
||||||
Docs(Symbol),
|
Docs(Symbol),
|
||||||
|
|
||||||
|
BinOp(roc_parse::operator::BinOp),
|
||||||
|
|
||||||
/// Many ReportText that should be concatenated together.
|
/// Many ReportText that should be concatenated together.
|
||||||
Batch(Vec<ReportText>),
|
Batch(Vec<ReportText>),
|
||||||
}
|
}
|
||||||
|
@ -367,6 +382,9 @@ impl ReportText {
|
||||||
report_text.render_ci(buf, subs, home, src_lines, interns);
|
report_text.render_ci(buf, subs, home, src_lines, interns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BinOp(bin_op) => {
|
||||||
|
buf.push_str(bin_op.to_string().as_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,6 +525,9 @@ impl ReportText {
|
||||||
report_text.render_color_terminal(buf, subs, home, src_lines, interns, palette);
|
report_text.render_color_terminal(buf, subs, home, src_lines, interns, palette);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BinOp(bin_op) => {
|
||||||
|
buf.push_str(&palette.binop.render(bin_op.to_string().as_str()));
|
||||||
|
}
|
||||||
_ => panic!("TODO implement more ReportTexts in render color terminal"),
|
_ => panic!("TODO implement more ReportTexts in render color terminal"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -291,23 +291,22 @@ mod test_reporting {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// hits a TODO in reporting
|
// #[test]
|
||||||
// #[test]
|
// fn report_shadow() {
|
||||||
// fn report_shadow() {
|
// report_problem_as(
|
||||||
// report_problem_as(
|
// indoc!(
|
||||||
// indoc!(
|
// r#"
|
||||||
// r#"
|
// i = 1
|
||||||
// i = 1
|
|
||||||
//
|
//
|
||||||
// s = \i ->
|
// s = \i ->
|
||||||
// i + 1
|
// i + 1
|
||||||
//
|
//
|
||||||
// s i
|
// s i
|
||||||
// "#
|
// "#
|
||||||
// ),
|
// ),
|
||||||
// indoc!(r#" "#),
|
// indoc!(r#" "#),
|
||||||
// )
|
// )
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// #[test]
|
// #[test]
|
||||||
// fn report_unsupported_top_level_def() {
|
// fn report_unsupported_top_level_def() {
|
||||||
|
@ -342,7 +341,7 @@ mod test_reporting {
|
||||||
),
|
),
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
You cannot mix (!=) and (==) without parentheses
|
Using != and == together requires parentheses, to clarify how they should be grouped.
|
||||||
|
|
||||||
3 ┆ if selectedId != thisId == adminsId then
|
3 ┆ if selectedId != thisId == adminsId then
|
||||||
┆ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
┆ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
@ -359,7 +358,7 @@ mod test_reporting {
|
||||||
r#"
|
r#"
|
||||||
if
|
if
|
||||||
1
|
1
|
||||||
!= 2
|
== 2
|
||||||
== 3
|
== 3
|
||||||
then
|
then
|
||||||
2
|
2
|
||||||
|
@ -370,10 +369,10 @@ mod test_reporting {
|
||||||
),
|
),
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
You cannot mix (!=) and (==) without parentheses
|
Using more than one == like this requires parentheses, to clarify how things should be grouped.
|
||||||
|
|
||||||
2 ┆> 1
|
2 ┆> 1
|
||||||
3 ┆> != 2
|
3 ┆> == 2
|
||||||
4 ┆> == 3
|
4 ┆> == 3
|
||||||
|
|
||||||
"#
|
"#
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue