style: 自动格式化

This commit is contained in:
爱特每羊队
2026-06-06 19:05:36 +08:00
parent a96b651feb
commit 33314265eb
6 changed files with 26 additions and 30 deletions
+3 -1
View File
@@ -306,7 +306,9 @@ impl Compiler {
let break_label = if let Some(sw_label) = ctx.current_switch() { let break_label = if let Some(sw_label) = ctx.current_switch() {
*sw_label *sw_label
} else { } else {
let (bl, _) = ctx.current_loop().ok_or("break outside switch or loop".to_string())?; let (bl, _) = ctx
.current_loop()
.ok_or("break outside switch or loop".to_string())?;
*bl *bl
}; };
let break_pos = ctx.resolve_label(break_label)?; let break_pos = ctx.resolve_label(break_label)?;
@@ -204,7 +204,10 @@ fn compile_do_while_emits_body_before_test() {
#[test] #[test]
fn compile_do_while_break() { fn compile_do_while_break() {
let module = compile_source("do { break; } while (true)"); let module = compile_source("do { break; } while (true)");
assert!(!module.bytecode.is_empty(), "do-while with break should compile"); assert!(
!module.bytecode.is_empty(),
"do-while with break should compile"
);
} }
#[test] #[test]
@@ -251,7 +254,10 @@ fn compile_for_in_let_decl() {
fn compile_switch_emits_jmp_if_true() { fn compile_switch_emits_jmp_if_true() {
let module = compile_source("var x=0; switch(x){case 1:1;case 2:2;}"); let module = compile_source("var x=0; switch(x){case 1:1;case 2:2;}");
assert!( assert!(
module.bytecode.iter().any(|&i| opcode::opcode(i) == OpCode::JMP_IF_TRUE), module
.bytecode
.iter()
.any(|&i| opcode::opcode(i) == OpCode::JMP_IF_TRUE),
"switch should emit JMP_IF_TRUE" "switch should emit JMP_IF_TRUE"
); );
} }
+6 -5
View File
@@ -186,7 +186,11 @@ fn run_test(path: &Path, source: &str, meta: &TestMeta) -> TestResult {
Ok(r) => r, Ok(r) => r,
Err(_panic) => { Err(_panic) => {
let dur = start.elapsed().as_millis() as u64; let dur = start.elapsed().as_millis() as u64;
TestResult::fail(path.to_path_buf(), dur, "engine panic (unsupported feature)") TestResult::fail(
path.to_path_buf(),
dur,
"engine panic (unsupported feature)",
)
} }
} }
} }
@@ -350,10 +354,7 @@ fn main() {
let source = match std::fs::read_to_string(path) { let source = match std::fs::read_to_string(path) {
Ok(s) => s, Ok(s) => s,
Err(e) => { Err(e) => {
results.push(TestResult::skip( results.push(TestResult::skip(path.clone(), format!("read error: {e}")));
path.clone(),
format!("read error: {e}"),
));
stats.skip += 1; stats.skip += 1;
continue; continue;
} }
+1 -2
View File
@@ -583,8 +583,7 @@ impl Vm {
let obj = unsafe { &*obj_val.as_js_object_ptr() }; let obj = unsafe { &*obj_val.as_js_object_ptr() };
let shape_id = obj.shape_id(); let shape_id = obj.shape_id();
let mut keys_vec = let mut keys_vec = bumpalo::collections::Vec::new_in(self.epoch.bump());
bumpalo::collections::Vec::new_in(self.epoch.bump());
let mut cursor = Some(shape_id); let mut cursor = Some(shape_id);
while let Some(id) = cursor { while let Some(id) = cursor {
if id == oxide_kernel::shape_forge::EMPTY_SHAPE_ID { if id == oxide_kernel::shape_forge::EMPTY_SHAPE_ID {
+4 -16
View File
@@ -171,10 +171,7 @@ fn eval_do_while_continue() {
#[test] #[test]
fn eval_for_in_enumerates_keys() { fn eval_for_in_enumerates_keys() {
assert_eq!( assert_eq!(eval("var n=0; for (k in {a:1,b:2}) { n=n+1; } n"), "2");
eval("var n=0; for (k in {a:1,b:2}) { n=n+1; } n"),
"2"
);
} }
#[test] #[test]
@@ -231,26 +228,17 @@ fn eval_switch_basic_match() {
#[test] #[test]
fn eval_switch_fallthrough() { fn eval_switch_fallthrough() {
assert_eq!( assert_eq!(eval("var x=0;switch(1){case 1:case 2:x=42;}x"), "42");
eval("var x=0;switch(1){case 1:case 2:x=42;}x"),
"42"
);
} }
#[test] #[test]
fn eval_switch_default() { fn eval_switch_default() {
assert_eq!( assert_eq!(eval("var x=0;switch(99){case 1:x=10;default:x=30;}x"), "30");
eval("var x=0;switch(99){case 1:x=10;default:x=30;}x"),
"30"
);
} }
#[test] #[test]
fn eval_switch_no_match_no_default() { fn eval_switch_no_match_no_default() {
assert_eq!( assert_eq!(eval("var x=0;switch(99){case 1:x=10;}x"), "0");
eval("var x=0;switch(99){case 1:x=10;}x"),
"0"
);
} }
#[test] #[test]