style: 自动格式化

This commit is contained in:
爱特每羊队
2026-06-08 20:09:00 +08:00
parent 209374fc02
commit fe3dd80bc5
20 changed files with 454 additions and 156 deletions
@@ -10,7 +10,9 @@ fn make_vm() -> Vm {
fn eval(source: &str) -> Result<JsValue, String> {
let allocator = oxide_parser::Allocator::default();
let program = oxide_parser::parse(&allocator, source).map_err(|e| format!("Parse: {:?}", e))?;
let module = Compiler::new().compile(&program).map_err(|e| format!("Compile: {}", e))?;
let module = Compiler::new()
.compile(&program)
.map_err(|e| format!("Compile: {}", e))?;
let mut vm = make_vm();
vm.run(&module)
}
@@ -124,6 +124,10 @@ fn number_epsilon_is_positive() {
fn number_to_exponential() {
let mut vm = Vm::new();
let result = eval(&mut vm, "var n = 123.456; n.toExponential(2)").unwrap();
let s = vm.kernel().string_forge().lookup(result.as_string_index()).unwrap_or_default();
let s = vm
.kernel()
.string_forge()
.lookup(result.as_string_index())
.unwrap_or_default();
assert_eq!(s, "1.23e2");
}
@@ -154,7 +154,11 @@ fn regexp_exec_global_last_index_advances() {
#[test]
fn regexp_exec_global_resets_on_exhaustion() {
let mut vm = Vm::new();
let result = eval(&mut vm, "var re = /a/g; re.exec('a'); re.exec('a') === null").unwrap();
let result = eval(
&mut vm,
"var re = /a/g; re.exec('a'); re.exec('a') === null",
)
.unwrap();
assert!(result.as_bool());
}
+8 -2
View File
@@ -5,7 +5,9 @@ use oxide_vm::vm::Vm;
fn eval(source: &str) -> Result<JsValue, String> {
let allocator = oxide_parser::Allocator::default();
let program = oxide_parser::parse(&allocator, source).map_err(|e| format!("Parse: {:?}", e))?;
let module = Compiler::new().compile(&program).map_err(|e| format!("Compile: {}", e))?;
let module = Compiler::new()
.compile(&program)
.map_err(|e| format!("Compile: {}", e))?;
let mut vm = Vm::new();
vm.run(&module)
}
@@ -21,7 +23,11 @@ fn const_reassignment_throws() {
let result = eval("const x = 1; x = 2");
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.contains("TypeError") || err.contains("constant"), "got: {}", err);
assert!(
err.contains("TypeError") || err.contains("constant"),
"got: {}",
err
);
}
#[test]