mirror of
https://github.com/typst/typst
synced 2025-06-28 00:03:17 +08:00
Fix array.pop()
This commit is contained in:
parent
93138e2d4b
commit
9a99beec94
@ -84,9 +84,8 @@ impl Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Remove the last value in the array.
|
/// Remove the last value in the array.
|
||||||
pub fn pop(&mut self) -> StrResult<()> {
|
pub fn pop(&mut self) -> StrResult<Value> {
|
||||||
Arc::make_mut(&mut self.0).pop().ok_or_else(array_is_empty)?;
|
Arc::make_mut(&mut self.0).pop().ok_or_else(array_is_empty)
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a value at the specified index.
|
/// Insert a value at the specified index.
|
||||||
|
@ -144,7 +144,7 @@ pub fn call_mut(
|
|||||||
match value {
|
match value {
|
||||||
Value::Array(array) => match method {
|
Value::Array(array) => match method {
|
||||||
"push" => array.push(args.expect("value")?),
|
"push" => array.push(args.expect("value")?),
|
||||||
"pop" => array.pop().at(span)?,
|
"pop" => output = array.pop().at(span)?,
|
||||||
"insert" => {
|
"insert" => {
|
||||||
array.insert(args.expect("index")?, args.expect("value")?).at(span)?
|
array.insert(args.expect("index")?, args.expect("value")?).at(span)?
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@
|
|||||||
// Test the `push` and `pop` methods.
|
// Test the `push` and `pop` methods.
|
||||||
#{
|
#{
|
||||||
let tasks = (a: (1, 2, 3), b: (4, 5, 6))
|
let tasks = (a: (1, 2, 3), b: (4, 5, 6))
|
||||||
tasks.at("a").pop()
|
test(tasks.at("a").pop(), 3)
|
||||||
tasks.b.push(7)
|
tasks.b.push(7)
|
||||||
test(tasks.a, (1, 2))
|
test(tasks.a, (1, 2))
|
||||||
test(tasks.at("b"), (4, 5, 6, 7))
|
test(tasks.at("b"), (4, 5, 6, 7))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user