Skip to content

Commit

Permalink
auto merge of #7160 : kballard/rust/terminfo-parm-i-fix, r=thestinger
Browse files Browse the repository at this point in the history
My latest terminfo work introduced a bug in the handling of %i, which was noticed by @huonw after the PR was already merged in.

r? @thestinger
  • Loading branch information
bors committed Jun 16, 2013
2 parents 03dff61 + 9c4f9bb commit c154899
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/libextra/terminfo/parm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
}
} else { return Err(~"stack is empty") },
'i' => match (copy mparams[0], copy mparams[1]) {
(Number(ref mut x), Number(ref mut y)) => {
*x += 1;
*y += 1;
(Number(x), Number(y)) => {
mparams[0] = Number(x+1);
mparams[1] = Number(y+1);
},
(_, _) => return Err(~"first two params not numbers with %i")
},
Expand Down Expand Up @@ -352,6 +352,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
#[cfg(test)]
mod test {
use super::*;
use core::result::Ok;

#[test]
fn test_basic_setabf() {
Expand All @@ -366,6 +367,16 @@ mod test {
bytes!("21").to_owned());
}

#[test]
fn test_op_i() {
let mut vars = Variables::new();
assert_eq!(expand(bytes!("%p1%d%p2%d%p3%d%i%p1%d%p2%d%p3%d"),
[Number(1),Number(2),Number(3)], &mut vars),
Ok(bytes!("123233").to_owned()));
assert_eq!(expand(bytes!("%p1%d%p2%d%i%p1%d%p2%d"), [], &mut vars),
Ok(bytes!("0011").to_owned()));
}

#[test]
fn test_param_stack_failure_conditions() {
let mut varstruct = Variables::new();
Expand Down

0 comments on commit c154899

Please sign in to comment.