style: 自动格式化修正
This commit is contained in:
@@ -19,7 +19,7 @@ impl From<oxc_diagnostics::OxcDiagnostic> for OxideError {
|
|||||||
let span = diag
|
let span = diag
|
||||||
.labels
|
.labels
|
||||||
.clone()
|
.clone()
|
||||||
.and_then(|labels| labels.first().map(|l| (l.offset() as usize, (l.offset() + l.len()) as usize)))
|
.and_then(|labels| labels.first().map(|l| (l.offset(), l.offset() + l.len())))
|
||||||
.unwrap_or((0, 0));
|
.unwrap_or((0, 0));
|
||||||
|
|
||||||
OxideError {
|
OxideError {
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ pub use oxc_allocator::Allocator;
|
|||||||
pub use oxc_ast::ast::*;
|
pub use oxc_ast::ast::*;
|
||||||
pub use oxc_span::Span;
|
pub use oxc_span::Span;
|
||||||
|
|
||||||
pub fn parse<'a>(allocator: &'a Allocator, source: &'a str) -> Result<Program<'a>, Vec<OxideError>> {
|
pub fn parse<'a>(
|
||||||
|
allocator: &'a Allocator,
|
||||||
|
source: &'a str,
|
||||||
|
) -> Result<Program<'a>, Vec<OxideError>> {
|
||||||
use oxc_parser::Parser;
|
use oxc_parser::Parser;
|
||||||
use oxc_span::SourceType;
|
use oxc_span::SourceType;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ fn parse_empty_string() {
|
|||||||
let result = oxide_parser::parse(&allocator, "");
|
let result = oxide_parser::parse(&allocator, "");
|
||||||
assert!(result.is_ok(), "empty string should parse");
|
assert!(result.is_ok(), "empty string should parse");
|
||||||
let program = result.unwrap();
|
let program = result.unwrap();
|
||||||
assert!(program.body.is_empty(), "empty program should have empty body");
|
assert!(
|
||||||
|
program.body.is_empty(),
|
||||||
|
"empty program should have empty body"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -22,7 +25,10 @@ fn parse_function_declaration() {
|
|||||||
let result = oxide_parser::parse(&allocator, "function foo() { return 42; }");
|
let result = oxide_parser::parse(&allocator, "function foo() { return 42; }");
|
||||||
assert!(result.is_ok(), "function declaration should parse");
|
assert!(result.is_ok(), "function declaration should parse");
|
||||||
let program = result.unwrap();
|
let program = result.unwrap();
|
||||||
assert!(!program.body.is_empty(), "program with function should not be empty");
|
assert!(
|
||||||
|
!program.body.is_empty(),
|
||||||
|
"program with function should not be empty"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -31,7 +37,10 @@ fn parse_syntax_error() {
|
|||||||
let result = oxide_parser::parse(&allocator, "function(");
|
let result = oxide_parser::parse(&allocator, "function(");
|
||||||
assert!(result.is_err(), "syntax error should return Err");
|
assert!(result.is_err(), "syntax error should return Err");
|
||||||
let errors = result.unwrap_err();
|
let errors = result.unwrap_err();
|
||||||
assert!(!errors.is_empty(), "syntax error should produce at least one error");
|
assert!(
|
||||||
|
!errors.is_empty(),
|
||||||
|
"syntax error should produce at least one error"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -44,10 +53,7 @@ fn parse_variable_declaration() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn parse_multiple_statements() {
|
fn parse_multiple_statements() {
|
||||||
let allocator = Allocator::default();
|
let allocator = Allocator::default();
|
||||||
let result = oxide_parser::parse(
|
let result = oxide_parser::parse(&allocator, "var a = 1; var b = 2; var c = a + b;");
|
||||||
&allocator,
|
|
||||||
"var a = 1; var b = 2; var c = a + b;",
|
|
||||||
);
|
|
||||||
assert!(result.is_ok(), "multiple statements should parse");
|
assert!(result.is_ok(), "multiple statements should parse");
|
||||||
let program = result.unwrap();
|
let program = result.unwrap();
|
||||||
assert_eq!(program.body.len(), 3, "should have 3 statements");
|
assert_eq!(program.body.len(), 3, "should have 3 statements");
|
||||||
|
|||||||
Reference in New Issue
Block a user