mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Many commented out report tests and report_problem_as helper
This commit is contained in:
parent
221581432a
commit
da4e97fd25
3 changed files with 159 additions and 121 deletions
|
@ -25,7 +25,7 @@ pub enum Problem {
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum PrecedenceProblem {
|
pub enum PrecedenceProblem {
|
||||||
BothNonAssociative(Located<BinOp>, Located<BinOp>),
|
BothNonAssociative(Symbol, Located<BinOp>, Symbol, Located<BinOp>, Symbol),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::report::ReportText::{Batch, Module, Region, Value};
|
use crate::report::ReportText::{Batch, 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::Problem;
|
use roc_problem::can::Problem;
|
||||||
use roc_types::pretty_print::content_to_string;
|
use roc_types::pretty_print::content_to_string;
|
||||||
use roc_types::subs::{Content, Subs};
|
use roc_types::subs::{Content, Subs};
|
||||||
|
@ -119,6 +120,24 @@ pub fn can_problem(filename: PathBuf, problem: Problem) -> Report {
|
||||||
texts.push(Value(argument_symbol));
|
texts.push(Value(argument_symbol));
|
||||||
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(
|
||||||
|
_left_symbol,
|
||||||
|
_left_bin_op,
|
||||||
|
_middle_symbol,
|
||||||
|
_right_bin_op,
|
||||||
|
_right_symbol,
|
||||||
|
)) => panic!("TODO implement precedence problem report"),
|
||||||
|
Problem::UnsupportedPattern(_pattern_type, _region) => {
|
||||||
|
panic!("TODO implement unsupported pattern report")
|
||||||
|
}
|
||||||
|
Problem::ShadowingInAnnotation {
|
||||||
|
original_region,
|
||||||
|
shadow,
|
||||||
|
} => {
|
||||||
|
let _a = original_region;
|
||||||
|
let _b = shadow;
|
||||||
|
panic!("TODO implement shadow report")
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
panic!("TODO implement others");
|
panic!("TODO implement others");
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,28 @@ mod test_report {
|
||||||
assert_eq!(buf, expected_rendering);
|
assert_eq!(buf, expected_rendering);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn report_problem_as(src: &str, expected_rendering: &str) {
|
||||||
|
let (_type_problems, can_problems, mut subs, home, interns) = infer_expr_help(src);
|
||||||
|
|
||||||
|
let mut buf: String = String::new();
|
||||||
|
let src_lines: Vec<&str> = src.split('\n').collect();
|
||||||
|
|
||||||
|
match can_problems.first() {
|
||||||
|
None => {}
|
||||||
|
Some(problem) => {
|
||||||
|
let report = can_problem(
|
||||||
|
filename_from_string(r"\code\proj\Main.roc"),
|
||||||
|
problem.clone(),
|
||||||
|
);
|
||||||
|
report
|
||||||
|
.text
|
||||||
|
.render_ci(&mut buf, &mut subs, home, &src_lines, &interns)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(buf, expected_rendering);
|
||||||
|
}
|
||||||
|
|
||||||
fn human_readable(str: &str) -> String {
|
fn human_readable(str: &str) -> String {
|
||||||
return str
|
return str
|
||||||
.replace(RED_CODE, "<red>")
|
.replace(RED_CODE, "<red>")
|
||||||
|
@ -247,35 +269,15 @@ mod test_report {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn report_unused_def() {
|
fn report_unused_def() {
|
||||||
let src: &str = indoc!(
|
report_problem_as(
|
||||||
r#"
|
indoc!(
|
||||||
|
r#"
|
||||||
x = 1
|
x = 1
|
||||||
y = 2
|
y = 2
|
||||||
|
|
||||||
x
|
x
|
||||||
"#
|
"#
|
||||||
);
|
),
|
||||||
|
|
||||||
let (_type_problems, can_problems, mut subs, home, interns) = infer_expr_help(src);
|
|
||||||
|
|
||||||
let mut buf: String = String::new();
|
|
||||||
let src_lines: Vec<&str> = src.split('\n').collect();
|
|
||||||
|
|
||||||
match can_problems.first() {
|
|
||||||
None => {}
|
|
||||||
Some(problem) => {
|
|
||||||
let report = can_problem(
|
|
||||||
filename_from_string(r"\code\proj\Main.roc"),
|
|
||||||
problem.clone(),
|
|
||||||
);
|
|
||||||
report
|
|
||||||
.text
|
|
||||||
.render_ci(&mut buf, &mut subs, home, &src_lines, &interns)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
buf,
|
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
y is not used anywhere in your code.
|
y is not used anywhere in your code.
|
||||||
|
@ -283,108 +285,125 @@ mod test_report {
|
||||||
2 ┆ y = 2
|
2 ┆ y = 2
|
||||||
|
|
||||||
If you didn't intend on using y then remove it so future readers of your code don't wonder why it is there."#
|
If you didn't intend on using y then remove it so future readers of your code don't wonder why it is there."#
|
||||||
)
|
),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
// #[test]
|
||||||
fn report_unused_argument() {
|
// fn report_shadow() {
|
||||||
let src: &str = indoc!(
|
// report_problem_as(
|
||||||
r#"
|
// indoc!(
|
||||||
y = 9
|
// r#"
|
||||||
|
// i = 1
|
||||||
|
//
|
||||||
|
// s = \i ->
|
||||||
|
// i + 1
|
||||||
|
//
|
||||||
|
// s i
|
||||||
|
// "#
|
||||||
|
// ),
|
||||||
|
// indoc!(r#" "#),
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
|
||||||
box = \class, htmlChildren ->
|
// #[test]
|
||||||
div [ class ] []
|
// fn report_unsupported_top_level_def() {
|
||||||
|
// report_problem_as(
|
||||||
|
// indoc!(
|
||||||
|
// r#"
|
||||||
|
// x = 1
|
||||||
|
//
|
||||||
|
// 5 = 2 + 1
|
||||||
|
//
|
||||||
|
// x
|
||||||
|
// "#
|
||||||
|
// ),
|
||||||
|
// indoc!(r#" "#),
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
|
||||||
div = 4
|
// #[test]
|
||||||
|
// fn report_precedence_problem() {
|
||||||
|
// report_problem_as(
|
||||||
|
// indoc!(
|
||||||
|
// r#"
|
||||||
|
// x = 1
|
||||||
|
// y =
|
||||||
|
// if 1 == 2 == 3 then
|
||||||
|
// 4
|
||||||
|
//
|
||||||
|
// else
|
||||||
|
// 5
|
||||||
|
//
|
||||||
|
// x
|
||||||
|
// "#
|
||||||
|
// ),
|
||||||
|
// indoc!(
|
||||||
|
// r#"
|
||||||
|
// Which expression should I evaluate first? "selectedId == thisId" or "thisId == adminsId"?
|
||||||
|
//
|
||||||
|
// 3 ┆ if selecteId == thisId == adminsId then
|
||||||
|
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
//
|
||||||
|
// Please clarify this for me by adding some parentheses. Either "(selectedId == thisId) == adminsId" or "selectedId == (thisId == adminsId)""#
|
||||||
|
// ),
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
|
||||||
box "wizard" []
|
// #[test]
|
||||||
"#
|
// fn report_unused_argument() {
|
||||||
);
|
// report_problem_as(
|
||||||
|
// indoc!(r#"
|
||||||
|
// y = 9
|
||||||
|
//
|
||||||
|
// box = \class, htmlChildren ->
|
||||||
|
// div [ class ] []
|
||||||
|
//
|
||||||
|
// div = 4
|
||||||
|
//
|
||||||
|
// box "wizard" []
|
||||||
|
// "#),
|
||||||
|
// indoc!(
|
||||||
|
// r#"
|
||||||
|
// box doesn't use htmlChildren.
|
||||||
|
//
|
||||||
|
// 3 ┆ box = \class, htmlChildren ->
|
||||||
|
//
|
||||||
|
// If you don't need htmlChildren, then you can just remove it. However, if you really do need htmlChildren as an argument of box, prefix it with an underscore, like this: "_htmlChildren". Adding an underscore at the start of a variable name is a way of saying that the variable is not used."#
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
let (_type_problems, can_problems, mut subs, home, interns) = infer_expr_help(src);
|
// #[test]
|
||||||
|
// fn report_unused_import() {
|
||||||
let mut buf: String = String::new();
|
// report_problem_as(
|
||||||
let src_lines: Vec<&str> = src.split('\n').collect();
|
// indoc!(r#"
|
||||||
|
// interface Report
|
||||||
match can_problems.first() {
|
// exposes [
|
||||||
None => {}
|
// plainText,
|
||||||
Some(problem) => {
|
// emText
|
||||||
let report = can_problem(
|
// ]
|
||||||
filename_from_string(r"\code\proj\Main.roc"),
|
// imports [
|
||||||
problem.clone(),
|
// Symbol.{ Interns }
|
||||||
);
|
// ]
|
||||||
report
|
//
|
||||||
.text
|
// plainText = \str -> PlainText str
|
||||||
.render_ci(&mut buf, &mut subs, home, &src_lines, &interns)
|
//
|
||||||
}
|
// emText = \str -> EmText str
|
||||||
}
|
// "#),
|
||||||
|
// indoc!(
|
||||||
assert_eq!(
|
// r#"
|
||||||
buf,
|
// Nothing from Symbol is used in this module.
|
||||||
indoc!(
|
//
|
||||||
r#"
|
// 6 ┆ imports [
|
||||||
box doesn't use htmlChildren.
|
// 7 ┆ Symbol.{ Interns }
|
||||||
|
// ┆ ^^^^^^
|
||||||
3 ┆ box = \class, htmlChildren ->
|
// 8 ┆ ]
|
||||||
|
//
|
||||||
If you don't need htmlChildren, then you can just remove it. However, if you really do need htmlChildren as an argument of box, prefix it with an underscore, like this: "_htmlChildren". Adding an underscore at the start of a variable name is a way of saying that the variable is not used."#
|
// Since Symbol isn't used, you don't need to import it."#
|
||||||
)
|
// ),
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn report_unused_import() {
|
|
||||||
let src: &str = indoc!(
|
|
||||||
r#"
|
|
||||||
interface Report
|
|
||||||
exposes [
|
|
||||||
plainText,
|
|
||||||
emText
|
|
||||||
]
|
|
||||||
imports [
|
|
||||||
Symbol.{ Interns }
|
|
||||||
]
|
|
||||||
|
|
||||||
plainText = \str -> PlainText str
|
|
||||||
|
|
||||||
emText = \str -> EmText str
|
|
||||||
"#
|
|
||||||
);
|
|
||||||
|
|
||||||
let (_type_problems, can_problems, mut subs, home, interns) = infer_expr_help(src);
|
|
||||||
|
|
||||||
let mut buf: String = String::new();
|
|
||||||
let src_lines: Vec<&str> = src.split('\n').collect();
|
|
||||||
|
|
||||||
match can_problems.first() {
|
|
||||||
None => {}
|
|
||||||
Some(problem) => {
|
|
||||||
let report = can_problem(
|
|
||||||
filename_from_string(r"\code\proj\Main.roc"),
|
|
||||||
problem.clone(),
|
|
||||||
);
|
|
||||||
report
|
|
||||||
.text
|
|
||||||
.render_ci(&mut buf, &mut subs, home, &src_lines, &interns)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
buf,
|
|
||||||
indoc!(
|
|
||||||
r#"
|
|
||||||
Nothing from Symbol is used in this module.
|
|
||||||
|
|
||||||
6 ┆ imports [
|
|
||||||
7 ┆ Symbol.{ Interns }
|
|
||||||
^^^^^^
|
|
||||||
8 ┆ ]
|
|
||||||
|
|
||||||
Since Symbol isn't used, you don't need to import it."#
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn report_plain_text_color() {
|
fn report_plain_text_color() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue