mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Merge pull request #2232 from rtfeldman/joshuawarner32/assert-module-formatting-stable
Also assert module formatting is stable
This commit is contained in:
commit
b8fe9a4d1d
1 changed files with 16 additions and 6 deletions
|
@ -15,7 +15,7 @@ mod test_fmt {
|
|||
use roc_test_utils::assert_multiline_str_eq;
|
||||
|
||||
// Not intended to be used directly in tests; please use expr_formats_to or expr_formats_same
|
||||
fn expect_format_helper(input: &str, expected: &str) {
|
||||
fn expect_format_expr_helper(input: &str, expected: &str) {
|
||||
let arena = Bump::new();
|
||||
match roc_parse::test_helpers::parse_expr_with(&arena, input.trim()) {
|
||||
Ok(actual) => {
|
||||
|
@ -34,21 +34,20 @@ mod test_fmt {
|
|||
let expected = expected.trim_end();
|
||||
|
||||
// First check that input formats to the expected version
|
||||
expect_format_helper(input, expected);
|
||||
expect_format_expr_helper(input, expected);
|
||||
|
||||
// Parse the expected result format it, asserting that it doesn't change
|
||||
// It's important that formatting be stable / idempotent
|
||||
expect_format_helper(expected, expected);
|
||||
expect_format_expr_helper(expected, expected);
|
||||
}
|
||||
|
||||
fn expr_formats_same(input: &str) {
|
||||
expr_formats_to(input, input);
|
||||
}
|
||||
|
||||
fn module_formats_to(src: &str, expected: &str) {
|
||||
// Not intended to be used directly in tests; please use module_formats_to or module_formats_same
|
||||
fn expect_format_module_helper(src: &str, expected: &str) {
|
||||
let arena = Bump::new();
|
||||
let src = src.trim_end();
|
||||
|
||||
match module::parse_header(&arena, State::new(src.as_bytes())) {
|
||||
Ok((actual, state)) => {
|
||||
let mut buf = Buf::new_in(&arena);
|
||||
|
@ -70,6 +69,17 @@ mod test_fmt {
|
|||
};
|
||||
}
|
||||
|
||||
fn module_formats_to(input: &str, expected: &str) {
|
||||
let input = input.trim_end();
|
||||
|
||||
// First check that input formats to the expected version
|
||||
expect_format_module_helper(input, expected);
|
||||
|
||||
// Parse the expected result format it, asserting that it doesn't change
|
||||
// It's important that formatting be stable / idempotent
|
||||
expect_format_module_helper(expected, expected);
|
||||
}
|
||||
|
||||
fn module_formats_same(input: &str) {
|
||||
module_formats_to(input, input);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue