Implement a migration to new braces syntax and add migrate tests

This commit is contained in:
Joshua Warner 2025-02-16 09:34:10 -08:00
parent 017fd006c6
commit 109cb93b20
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
540 changed files with 3425 additions and 2 deletions

View file

@ -7,6 +7,7 @@ use roc_can::scope::Scope;
use roc_can_solo::env::SoloEnv;
use roc_can_solo::scope::SoloScope;
use roc_error_macros::set_panic_not_exit;
use roc_fmt::migrate::{MigrateError, Suffix};
use roc_fmt::{annotation::Formattable, header::fmt_header, MigrationFlags};
use roc_module::ident::QualifiedModuleName;
use roc_module::symbol::{IdentIds, Interns, ModuleIds, PackageModuleIds, Symbol};
@ -30,7 +31,7 @@ use roc_types::{
types::{AliasVar, Type},
};
use roc_fmt::Buf;
use roc_fmt::{migrate, Buf};
/// Source code to parse. Usually in the form of a test case.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
@ -253,6 +254,77 @@ impl<'a> Output<'a> {
}
}
}
pub fn migrate(&self) -> Result<InputOwned, MigrateError> {
match self {
Output::Header(header) => {
let arena = Bump::new();
let mut buf = Buf::new_in(
&arena,
MigrationFlags {
snakify: false,
parens_and_commas: false,
},
);
migrate::fmt_header(&mut buf, header)?;
buf.fmt_end_of_file();
Ok(InputOwned::Header(buf.as_str().to_string()))
}
Output::ModuleDefs(defs) => {
let arena = Bump::new();
let mut buf = Buf::new_in(
&arena,
MigrationFlags {
snakify: false,
parens_and_commas: false,
},
);
migrate::fmt_defs(&mut buf, defs)?;
buf.fmt_end_of_file();
Ok(InputOwned::ModuleDefs(buf.as_str().to_string()))
}
Output::Expr(expr) => {
let arena = Bump::new();
let mut buf = Buf::new_in(
&arena,
MigrationFlags {
snakify: false,
parens_and_commas: false,
},
);
migrate::fmt_expr_top_level(&mut buf, 0, &expr.value)?;
buf.fmt_end_of_file();
Ok(InputOwned::Expr(buf.as_str().to_string()))
}
Output::Full(full_ast) => {
let arena = Bump::new();
let mut buf = Buf::new_in(
&arena,
MigrationFlags {
snakify: false,
parens_and_commas: false,
},
);
migrate::fmt_header(&mut buf, &full_ast.header)?;
migrate::fmt_defs(&mut buf, &full_ast.defs)?;
buf.fmt_end_of_file();
Ok(InputOwned::Full(buf.as_str().to_string()))
}
Output::Pattern(pat) => {
let arena = Bump::new();
let mut buf = Buf::new_in(
&arena,
MigrationFlags {
snakify: false,
parens_and_commas: false,
},
);
migrate::fmt_pattern(&mut buf, 0, &pat.value, Suffix::None)?;
buf.fmt_end_of_file();
Ok(InputOwned::Pattern(buf.as_str().to_string()))
}
}
}
}
impl<'a> Malformed for Output<'a> {

View file

@ -0,0 +1,10 @@
O({p: if
a
{
A
} else {
&m
}}, #
) : e
i

View file

@ -0,0 +1,2 @@
N((implements),h,(0),) : B
T

View file

@ -0,0 +1,4 @@
B(@A,) : w
#
@A = e
i

View file

@ -0,0 +1,4 @@
M({s: s({J&
},)},{s: s({J&
},)},) : p
y

View file

@ -0,0 +1,4 @@
Q((
"""
"""("",)),) : a
q

View file

@ -0,0 +1,6 @@
il3(|k| # w#z
{
CCC(@C,( # i
t!(K,)),) : i
C
},)

View file

@ -0,0 +1,9 @@
if
h
{
A
} else {
&e
}
s #

View file

@ -0,0 +1,4 @@
foo: [True,Perhaps(Thing,),]
foo = True
42

View file

@ -0,0 +1,5 @@
launchTheNukes: {}, => Result(Bool,LaunchNukeErr,)
launchTheNukes = |{}|
crash("todo",)
launchTheNukes

View file

@ -0,0 +1,5 @@
2:
r where e
implements
P
u

View file

@ -0,0 +1,4 @@
foo: [True,Perhaps(Thing,),..*]
foo = True
42

View file

@ -0,0 +1,5 @@
x: a
where
e
implements K, -> Z
s

View file

@ -0,0 +1,4 @@
J() : [
] where e
implements T
i

View file

@ -0,0 +1,3 @@
1: (f,
ww, -> p,..e)
Mh

View file

@ -0,0 +1,4 @@
{x,y,}: Foo
{x,y,} = {x: "foo"y: 3.14}
x

View file

@ -0,0 +1,4 @@
UserId(x,): [UserId(I64,),]
UserId(x,) = UserId(42,)
x

View file

@ -0,0 +1,4 @@
(x,y,): Foo
(x,y,) = ("foo",3.14,)
x

View file

@ -0,0 +1,2 @@
s: eas A()as A()
s

View file

@ -0,0 +1,3 @@
3: (..n #
), -> n
0

View file

@ -0,0 +1,3 @@
Str.getUnsafe(haystack,haystackIndex,)
==
Str.getUnsafe(needle,needleIndex,)

View file

@ -0,0 +1,2 @@
foo
|> Dict.keepIf(|(k,_v,)| List.contains(keysToDelete,k,) |> Bool.not,)

View file

@ -0,0 +1,3 @@
a: N({h
},)
g

View file

@ -0,0 +1 @@
Whee(12,34,)

View file

@ -0,0 +1 @@
!whee(12,foo,)

View file

@ -0,0 +1,2 @@
|{x,y,} as point@Location(inner,) as outer|
crash("",)

View file

@ -0,0 +1,3 @@
e: J
as H(), -> A
r

View file

@ -0,0 +1,9 @@
## first line of docs
## second line
## third line
## fourth line
##
## sixth line after doc new line
x = 5
42

View file

@ -0,0 +1,5 @@
5 - (({
e = ((
r))
1
}))

View file

@ -0,0 +1,3 @@
d +
(|w| x)(
x,)

View file

@ -0,0 +1 @@
launchTheNukes!(123,)

View file

@ -0,0 +1,4 @@
|I({p? Y(
Y,)?,},[
],)|
K # (

View file

@ -0,0 +1,2 @@
m0(|w| w?(e,),)
/ s

View file

@ -0,0 +1,8 @@
Model(position,) :
{evaluated: Set(position,)
openSet: Set(position,)
costs: Dict.Dict(position,F64,)
cameFrom: Dict.Dict(position,position,)
}
a

Some files were not shown because too many files have changed in this diff Show more