mirror of https://github.com/boa-dev/boa.git
Browse Source
* Fixed top level indents * Fixed function definitions * For loops display correctly now * Await expressions display correctly * Await calls no longer have a custom display() function * Fixed async function declaration * Added spacing to do-while loop * Fixed for of loop * Fixed object declaration formatter * Fixed switch statements formatting * Added operator fmt test * Added array display test * Added tests for await expressions. Unclear if let a = await blah() has been implemented yet, but I got parse errors when testing that * Added block display test * Added break formatting test * Added a potential test for when block labels are added * Added call formatting tests * Added a testing utility function for formatting tests * Using custom testing function instead of a bunch of asserts in formatting tests * Improved formatting of failed parsing formatting tests * Added conditional formatting tests * Wrote function tests, and found out that functions are still horribly broken * Fixed arrow function declaration * Fixed the formatting for the rest of the functions. Async function expressions don't seem to be parsed correctly * Re-ordered functions to match the output of StatementList * Fixed async function expressions * Added field formatting tests * Added formatting test for 'for' loops * For in loops now display their label if they have one * Added test for the rest of the loops * Added fmt for labels for all the types of loops * Added test for new keyword formatting * Added object formatting * Partially fixed object display function * Split Node::display into two functions, allowing objects to be displayed correctly * Added a first implementation of a MethodDefinition formatter * Added tests for the rest of object function fields (every branch of MethodDefinitionField) * Operator test uses propper formatting test * Added return statment formatter test * Added spread argument formatting test * Added switch statement formatting test * Added a formatting test for templates * Added a throw statement formatter test * Added try catch test * Removed unused import * Formatting test now uses eprintln! instead of println!pull/1334/head
macmv
3 years ago
committed by
GitHub
42 changed files with 581 additions and 80 deletions
@ -0,0 +1,9 @@ |
|||||||
|
#[test] |
||||||
|
fn fmt() { |
||||||
|
super::super::test_formatting( |
||||||
|
r#" |
||||||
|
let a = [1, 2, 3, "words", "more words"]; |
||||||
|
let b = []; |
||||||
|
"#, |
||||||
|
); |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
#[test] |
||||||
|
fn fmt() { |
||||||
|
// TODO: `let a = await fn()` is invalid syntax as of writing. It should be tested here once implemented.
|
||||||
|
super::super::test_formatting( |
||||||
|
r#" |
||||||
|
await function_call(); |
||||||
|
"#, |
||||||
|
); |
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
#[test] |
||||||
|
fn fmt() { |
||||||
|
super::super::test_formatting( |
||||||
|
r#" |
||||||
|
{ |
||||||
|
let a = function_call(); |
||||||
|
console.log("hello"); |
||||||
|
} |
||||||
|
another_statement(); |
||||||
|
"#, |
||||||
|
); |
||||||
|
// TODO: Once block labels are implemtned, this should be tested:
|
||||||
|
// super::super::test_formatting(
|
||||||
|
// r#"
|
||||||
|
// block_name: {
|
||||||
|
// let a = function_call();
|
||||||
|
// console.log("hello");
|
||||||
|
// }
|
||||||
|
// another_statement();
|
||||||
|
// "#,
|
||||||
|
// );
|
||||||
|
} |
@ -0,0 +1,10 @@ |
|||||||
|
#[test] |
||||||
|
fn fmt() { |
||||||
|
super::super::test_formatting( |
||||||
|
r#" |
||||||
|
call_1(1, 2, 3); |
||||||
|
call_2("argument here"); |
||||||
|
call_3(); |
||||||
|
"#, |
||||||
|
); |
||||||
|
} |
@ -0,0 +1,13 @@ |
|||||||
|
#[test] |
||||||
|
fn fmt() { |
||||||
|
super::super::test_formatting( |
||||||
|
r#" |
||||||
|
let a = true ? 5 : 6; |
||||||
|
if (false) { |
||||||
|
a = 10; |
||||||
|
} else { |
||||||
|
a = 20; |
||||||
|
} |
||||||
|
"#, |
||||||
|
); |
||||||
|
} |
@ -0,0 +1,10 @@ |
|||||||
|
#[test] |
||||||
|
fn fmt() { |
||||||
|
super::super::test_formatting( |
||||||
|
r#" |
||||||
|
a.field_name; |
||||||
|
a[5]; |
||||||
|
a["other_field_name"]; |
||||||
|
"#, |
||||||
|
); |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
#[test] |
||||||
|
fn fmt() { |
||||||
|
super::super::test_formatting( |
||||||
|
r#" |
||||||
|
function MyClass() {}; |
||||||
|
let inst = new MyClass(); |
||||||
|
"#, |
||||||
|
); |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
#[test] |
||||||
|
fn fmt() { |
||||||
|
super::super::test_formatting( |
||||||
|
r#" |
||||||
|
let other = { |
||||||
|
c: 10, |
||||||
|
}; |
||||||
|
let inst = { |
||||||
|
val: 5, |
||||||
|
b: "hello world", |
||||||
|
nested: { |
||||||
|
a: 5, |
||||||
|
b: 6, |
||||||
|
}, |
||||||
|
...other, |
||||||
|
say_hi: function() { |
||||||
|
console.log("hello!"); |
||||||
|
}, |
||||||
|
get a() { |
||||||
|
return this.val + 1; |
||||||
|
}, |
||||||
|
set a(new_value) { |
||||||
|
this.val = new_value; |
||||||
|
}, |
||||||
|
say_hello(msg) { |
||||||
|
console.log("hello " + msg); |
||||||
|
}, |
||||||
|
}; |
||||||
|
inst.a = 20; |
||||||
|
inst.a; |
||||||
|
inst.say_hello("humans"); |
||||||
|
"#, |
||||||
|
); |
||||||
|
} |
@ -0,0 +1,16 @@ |
|||||||
|
#[test] |
||||||
|
fn fmt() { |
||||||
|
super::super::test_formatting( |
||||||
|
r#" |
||||||
|
function say_hello(msg) { |
||||||
|
if (msg === "") { |
||||||
|
return 0; |
||||||
|
} |
||||||
|
console.log("hello " + msg); |
||||||
|
return; |
||||||
|
}; |
||||||
|
say_hello(""); |
||||||
|
say_hello("world"); |
||||||
|
"#, |
||||||
|
); |
||||||
|
} |
@ -0,0 +1,12 @@ |
|||||||
|
#[test] |
||||||
|
fn fmt() { |
||||||
|
super::super::test_formatting( |
||||||
|
r#" |
||||||
|
try { |
||||||
|
throw "hello"; |
||||||
|
} catch(e) { |
||||||
|
console.log(e); |
||||||
|
}; |
||||||
|
"#, |
||||||
|
); |
||||||
|
} |
Loading…
Reference in new issue