mirror of
https://github.com/roc-lang/roc.git
synced 2025-11-01 13:34:15 +00:00
Merge remote-tracking branch 'origin/main' into linux64
This commit is contained in:
commit
1d5c5b25ec
328 changed files with 11845 additions and 9244 deletions
|
|
@ -96,10 +96,10 @@ impl<'a> Output<'a> {
|
|||
|
||||
pub fn debug_format_inner(&self) -> String {
|
||||
match self {
|
||||
Output::Header(header) => format!("{:#?}\n", header),
|
||||
Output::ModuleDefs(defs) => format!("{:#?}\n", defs),
|
||||
Output::Expr(expr) => format!("{:#?}\n", expr),
|
||||
Output::Full { .. } => format!("{:#?}\n", self),
|
||||
Output::Header(header) => format!("{header:#?}\n"),
|
||||
Output::ModuleDefs(defs) => format!("{defs:#?}\n"),
|
||||
Output::Expr(expr) => format!("{expr:#?}\n"),
|
||||
Output::Full { .. } => format!("{self:#?}\n"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -224,7 +224,7 @@ impl<'a> Input<'a> {
|
|||
// the PartialEq implementation is returning `false` even when the Debug-formatted impl is exactly the same.
|
||||
// I don't have the patience to debug this right now, so let's leave it for another day...
|
||||
// TODO: fix PartialEq impl on ast types
|
||||
if format!("{:?}", ast_normalized) != format!("{:?}", reparsed_ast_normalized) {
|
||||
if format!("{ast_normalized:?}") != format!("{reparsed_ast_normalized:?}") {
|
||||
panic!(
|
||||
"Formatting bug; formatting didn't reparse to the same AST (after removing spaces)\n\n\
|
||||
* * * Source code before formatting:\n{}\n\n\
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
A := U8 has [Eq, Hash]
|
||||
|
||||
A := a | a has Other
|
||||
has [Eq, Hash]
|
||||
has [Eq, Hash]
|
||||
|
||||
A := a | a has Other
|
||||
has [Eq, Hash]
|
||||
has [Eq, Hash]
|
||||
|
||||
A := U8 has [Eq { eq }, Hash { hash }]
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ A := U8 has [Hash, Eq { eq, eq1 }]
|
|||
A := U8 has []
|
||||
|
||||
A := a | a has Other
|
||||
has [Eq { eq }, Hash { hash }]
|
||||
has [Eq { eq }, Hash { hash }]
|
||||
|
||||
A := U8 has [Eq {}]
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
app "example"
|
||||
packages { pf: "path" }
|
||||
imports [pf.Stdout]
|
||||
provides [main] to pf
|
||||
|
||||
main = Stdout.line "Hello"
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
Full {
|
||||
header: Module {
|
||||
comments: [],
|
||||
header: App(
|
||||
AppHeader {
|
||||
before_name: [],
|
||||
name: @4-13 PlainLine(
|
||||
"example",
|
||||
),
|
||||
packages: Some(
|
||||
KeywordItem {
|
||||
keyword: Spaces {
|
||||
before: [
|
||||
Newline,
|
||||
],
|
||||
item: PackagesKeyword,
|
||||
after: [],
|
||||
},
|
||||
item: [
|
||||
@29-40 PackageEntry {
|
||||
shorthand: "pf",
|
||||
spaces_after_shorthand: [],
|
||||
package_name: @34-40 PackageName(
|
||||
"path",
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
imports: Some(
|
||||
KeywordItem {
|
||||
keyword: Spaces {
|
||||
before: [
|
||||
Newline,
|
||||
],
|
||||
item: ImportsKeyword,
|
||||
after: [],
|
||||
},
|
||||
item: [
|
||||
@57-66 Package(
|
||||
"pf",
|
||||
ModuleName(
|
||||
"Stdout",
|
||||
),
|
||||
[],
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
provides: ProvidesTo {
|
||||
provides_keyword: Spaces {
|
||||
before: [
|
||||
Newline,
|
||||
],
|
||||
item: ProvidesKeyword,
|
||||
after: [],
|
||||
},
|
||||
entries: [
|
||||
@84-88 ExposedName(
|
||||
"main",
|
||||
),
|
||||
],
|
||||
types: None,
|
||||
to_keyword: Spaces {
|
||||
before: [],
|
||||
item: ToKeyword,
|
||||
after: [],
|
||||
},
|
||||
to: @94-96 ExistingPackage(
|
||||
"pf",
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
module_defs: Defs {
|
||||
tags: [
|
||||
Index(2147483648),
|
||||
],
|
||||
regions: [
|
||||
@98-124,
|
||||
],
|
||||
space_before: [
|
||||
Slice(start = 0, length = 2),
|
||||
],
|
||||
space_after: [
|
||||
Slice(start = 2, length = 0),
|
||||
],
|
||||
spaces: [
|
||||
Newline,
|
||||
Newline,
|
||||
],
|
||||
type_defs: [],
|
||||
value_defs: [
|
||||
Body(
|
||||
@98-102 Identifier(
|
||||
"main",
|
||||
),
|
||||
@105-124 Apply(
|
||||
@105-116 Var {
|
||||
module_name: "Stdout",
|
||||
ident: "line",
|
||||
},
|
||||
[
|
||||
@117-124 Str(
|
||||
PlainLine(
|
||||
"Hello",
|
||||
),
|
||||
),
|
||||
],
|
||||
Space,
|
||||
),
|
||||
),
|
||||
],
|
||||
},
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
app "example"
|
||||
packages { pf : "path" }
|
||||
imports [ pf.Stdout ]
|
||||
provides [ main ] to pf
|
||||
|
||||
main = Stdout.line "Hello"
|
||||
|
|
@ -43,8 +43,7 @@ mod test_fmt {
|
|||
fmt_defs(buf, &loc_defs, 0);
|
||||
}
|
||||
Err(error) => panic!(
|
||||
r"Unexpected parse failure when parsing this for defs formatting:\n\n{:?}\n\nParse error was:\n\n{:?}\n\n",
|
||||
src, error
|
||||
r"Unexpected parse failure when parsing this for defs formatting:\n\n{src:?}\n\nParse error was:\n\n{error:?}\n\n"
|
||||
),
|
||||
}
|
||||
}
|
||||
|
|
@ -67,8 +66,7 @@ mod test_fmt {
|
|||
|
||||
let (reparsed_ast, state) = module::parse_header(&arena, State::new(output.as_bytes())).unwrap_or_else(|err| {
|
||||
panic!(
|
||||
"After formatting, the source code no longer parsed!\n\nParse error was: {:?}\n\nThe code that failed to parse:\n\n{}\n\n",
|
||||
err, output
|
||||
"After formatting, the source code no longer parsed!\n\nParse error was: {err:?}\n\nThe code that failed to parse:\n\n{output}\n\n"
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -80,13 +78,11 @@ mod test_fmt {
|
|||
// the PartialEq implementation is returning `false` even when the Debug-formatted impl is exactly the same.
|
||||
// I don't have the patience to debug this right now, so let's leave it for another day...
|
||||
// TODO: fix PartialEq impl on ast types
|
||||
if format!("{:?}", ast_normalized) != format!("{:?}", reparsed_ast_normalized) {
|
||||
if format!("{ast_normalized:?}") != format!("{reparsed_ast_normalized:?}") {
|
||||
panic!(
|
||||
"Formatting bug; formatting didn't reparse to the same AST (after removing spaces)\n\n\
|
||||
* * * Source code before formatting:\n{}\n\n\
|
||||
* * * Source code after formatting:\n{}\n\n",
|
||||
src,
|
||||
output
|
||||
* * * Source code before formatting:\n{src}\n\n\
|
||||
* * * Source code after formatting:\n{output}\n\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +107,7 @@ mod test_fmt {
|
|||
// those more than we want to know that the expectation failed!
|
||||
assert_multiline_str_eq!(expected, output);
|
||||
}
|
||||
Err(error) => panic!("Unexpected parse failure when parsing this for module header formatting:\n\n{:?}\n\nParse error was:\n\n{:?}\n\n", src, error)
|
||||
Err(error) => panic!("Unexpected parse failure when parsing this for module header formatting:\n\n{src:?}\n\nParse error was:\n\n{error:?}\n\n")
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -5447,7 +5443,7 @@ mod test_fmt {
|
|||
indoc!(
|
||||
r#"
|
||||
A := U8
|
||||
has [Eq, Hash]
|
||||
has [Eq, Hash]
|
||||
|
||||
0
|
||||
"#
|
||||
|
|
@ -5465,7 +5461,7 @@ mod test_fmt {
|
|||
indoc!(
|
||||
r#"
|
||||
A := a | a has Hash
|
||||
has [Eq, Hash]
|
||||
has [Eq, Hash]
|
||||
|
||||
0
|
||||
"#
|
||||
|
|
@ -5555,11 +5551,11 @@ mod test_fmt {
|
|||
r#"
|
||||
A := U8 has [Eq { eq, eq1 }]
|
||||
A := U8 has [
|
||||
Eq {
|
||||
eq,
|
||||
eq1,
|
||||
},
|
||||
]
|
||||
Eq {
|
||||
eq,
|
||||
eq1,
|
||||
},
|
||||
]
|
||||
|
||||
0
|
||||
"#
|
||||
|
|
@ -5569,7 +5565,7 @@ mod test_fmt {
|
|||
expr_formats_same(indoc!(
|
||||
r#"
|
||||
A := a | a has Other
|
||||
has [Eq { eq }, Hash { hash }]
|
||||
has [Eq { eq }, Hash { hash }]
|
||||
|
||||
0
|
||||
"#
|
||||
|
|
|
|||
|
|
@ -430,6 +430,7 @@ mod test_snapshots {
|
|||
pass/requires_type.header,
|
||||
pass/single_arg_closure.expr,
|
||||
pass/single_underscore_closure.expr,
|
||||
pass/space_before_colon.full,
|
||||
pass/space_only_after_minus.expr,
|
||||
pass/spaced_singleton_list.expr,
|
||||
pass/spaces_inside_empty_list.expr,
|
||||
|
|
@ -525,14 +526,13 @@ mod test_snapshots {
|
|||
// Expect file to be missing
|
||||
assert!(
|
||||
!result_path.exists(),
|
||||
"Expected {:?} to be missing. \
|
||||
"Expected {result_path:?} to be missing. \
|
||||
This is how we represent a 'default' result (i.e. a test that \
|
||||
formats to the same thing as the input). \
|
||||
Consider running the tests with:\n\
|
||||
`env ROC_SNAPSHOT_TEST_OVERWRITE=1 cargo test ...`\n\
|
||||
(which will delete the file for you),\n\
|
||||
and commiting the delete.",
|
||||
result_path
|
||||
and commiting the delete."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -544,15 +544,12 @@ mod test_snapshots {
|
|||
let mut parent = std::path::PathBuf::from("tests");
|
||||
parent.push("snapshots");
|
||||
parent.push(expect.to_dir_name());
|
||||
let input_path = parent.join(format!("{}.{}.roc", name, ty));
|
||||
let result_path = parent.join(format!("{}.{}.result-ast", name, ty));
|
||||
let formatted_path = parent.join(format!("{}.{}.formatted.roc", name, ty));
|
||||
let input_path = parent.join(format!("{name}.{ty}.roc"));
|
||||
let result_path = parent.join(format!("{name}.{ty}.result-ast"));
|
||||
let formatted_path = parent.join(format!("{name}.{ty}.formatted.roc"));
|
||||
|
||||
let source = std::fs::read_to_string(&input_path).unwrap_or_else(|err| {
|
||||
panic!(
|
||||
"Could not find a snapshot test result at {:?} - {:?}",
|
||||
input_path, err
|
||||
)
|
||||
panic!("Could not find a snapshot test result at {input_path:?} - {err:?}")
|
||||
});
|
||||
|
||||
let input = func(&source);
|
||||
|
|
@ -565,14 +562,14 @@ mod test_snapshots {
|
|||
}
|
||||
Ok(ast.debug_format_inner())
|
||||
}
|
||||
Err(err) => Err(format!("{:?}", err)),
|
||||
Err(err) => Err(format!("{err:?}")),
|
||||
};
|
||||
|
||||
if expect == TestExpectation::Pass {
|
||||
let tokens = roc_parse::highlight::highlight(&source);
|
||||
for token in tokens {
|
||||
if token.value == roc_parse::highlight::Token::Error {
|
||||
panic!("Found an error highlight token in the input: {:?}", token);
|
||||
panic!("Found an error highlight token in the input: {token:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -652,7 +649,7 @@ mod test_snapshots {
|
|||
#[test]
|
||||
fn string_with_escaped_char_at_end() {
|
||||
parses_with_escaped_char(
|
||||
|esc| format!(r#""abcd{}""#, esc),
|
||||
|esc| format!(r#""abcd{esc}""#),
|
||||
|esc, arena| bumpalo::vec![in arena; Plaintext("abcd"), EscapedChar(esc)],
|
||||
);
|
||||
}
|
||||
|
|
@ -660,7 +657,7 @@ mod test_snapshots {
|
|||
#[test]
|
||||
fn string_with_escaped_char_in_front() {
|
||||
parses_with_escaped_char(
|
||||
|esc| format!(r#""{}abcd""#, esc),
|
||||
|esc| format!(r#""{esc}abcd""#),
|
||||
|esc, arena| bumpalo::vec![in arena; EscapedChar(esc), Plaintext("abcd")],
|
||||
);
|
||||
}
|
||||
|
|
@ -668,7 +665,7 @@ mod test_snapshots {
|
|||
#[test]
|
||||
fn string_with_escaped_char_in_middle() {
|
||||
parses_with_escaped_char(
|
||||
|esc| format!(r#""ab{}cd""#, esc),
|
||||
|esc| format!(r#""ab{esc}cd""#),
|
||||
|esc, arena| bumpalo::vec![in arena; Plaintext("ab"), EscapedChar(esc), Plaintext("cd")],
|
||||
);
|
||||
}
|
||||
|
|
@ -676,7 +673,7 @@ mod test_snapshots {
|
|||
#[test]
|
||||
fn string_with_multiple_escaped_chars() {
|
||||
parses_with_escaped_char(
|
||||
|esc| format!(r#""{}abc{}de{}fghi{}""#, esc, esc, esc, esc),
|
||||
|esc| format!(r#""{esc}abc{esc}de{esc}fghi{esc}""#),
|
||||
|esc, arena| bumpalo::vec![in arena; EscapedChar(esc), Plaintext("abc"), EscapedChar(esc), Plaintext("de"), EscapedChar(esc), Plaintext("fghi"), EscapedChar(esc)],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue