diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index 8bf8044f81431..e80c5c11d457b 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -64,7 +64,8 @@ #![feature(vec_push_all)] #![cfg_attr(windows, feature(libc))] -#[macro_use] extern crate log; +#[macro_use] +extern crate log; pub use terminfo::TerminfoTerminal; #[cfg(windows)] @@ -100,25 +101,19 @@ impl Write for WriterWrapper { /// Return a Terminal wrapping stdout, or None if a terminal couldn't be /// opened. pub fn stdout() -> Option + Send>> { - TerminfoTerminal::new(WriterWrapper { - wrapped: box std::io::stdout(), - }) + TerminfoTerminal::new(WriterWrapper { wrapped: box std::io::stdout() }) } #[cfg(windows)] /// Return a Terminal wrapping stdout, or None if a terminal couldn't be /// opened. pub fn stdout() -> Option + Send>> { - let ti = TerminfoTerminal::new(WriterWrapper { - wrapped: box std::io::stdout(), - }); + let ti = TerminfoTerminal::new(WriterWrapper { wrapped: box std::io::stdout() }); match ti { Some(t) => Some(t), None => { - WinConsole::new(WriterWrapper { - wrapped: box std::io::stdout(), - }) + WinConsole::new(WriterWrapper { wrapped: box std::io::stdout() }) } } } @@ -127,25 +122,19 @@ pub fn stdout() -> Option + Send>> { /// Return a Terminal wrapping stderr, or None if a terminal couldn't be /// opened. pub fn stderr() -> Option + Send>> { - TerminfoTerminal::new(WriterWrapper { - wrapped: box std::io::stderr(), - }) + TerminfoTerminal::new(WriterWrapper { wrapped: box std::io::stderr() }) } #[cfg(windows)] /// Return a Terminal wrapping stderr, or None if a terminal couldn't be /// opened. pub fn stderr() -> Option + Send>> { - let ti = TerminfoTerminal::new(WriterWrapper { - wrapped: box std::io::stderr(), - }); + let ti = TerminfoTerminal::new(WriterWrapper { wrapped: box std::io::stderr() }); match ti { Some(t) => Some(t), None => { - WinConsole::new(WriterWrapper { - wrapped: box std::io::stderr(), - }) + WinConsole::new(WriterWrapper { wrapped: box std::io::stderr() }) } } } @@ -157,23 +146,23 @@ pub mod color { /// Number for a terminal color pub type Color = u16; - pub const BLACK: Color = 0; - pub const RED: Color = 1; - pub const GREEN: Color = 2; - pub const YELLOW: Color = 3; - pub const BLUE: Color = 4; + pub const BLACK: Color = 0; + pub const RED: Color = 1; + pub const GREEN: Color = 2; + pub const YELLOW: Color = 3; + pub const BLUE: Color = 4; pub const MAGENTA: Color = 5; - pub const CYAN: Color = 6; - pub const WHITE: Color = 7; - - pub const BRIGHT_BLACK: Color = 8; - pub const BRIGHT_RED: Color = 9; - pub const BRIGHT_GREEN: Color = 10; - pub const BRIGHT_YELLOW: Color = 11; - pub const BRIGHT_BLUE: Color = 12; + pub const CYAN: Color = 6; + pub const WHITE: Color = 7; + + pub const BRIGHT_BLACK: Color = 8; + pub const BRIGHT_RED: Color = 9; + pub const BRIGHT_GREEN: Color = 10; + pub const BRIGHT_YELLOW: Color = 11; + pub const BRIGHT_BLUE: Color = 12; pub const BRIGHT_MAGENTA: Color = 13; - pub const BRIGHT_CYAN: Color = 14; - pub const BRIGHT_WHITE: Color = 15; + pub const BRIGHT_CYAN: Color = 14; + pub const BRIGHT_WHITE: Color = 15; } /// Terminal attributes @@ -206,7 +195,7 @@ pub mod attr { /// Convenience attribute to set the foreground color ForegroundColor(super::color::Color), /// Convenience attribute to set the background color - BackgroundColor(super::color::Color) + BackgroundColor(super::color::Color), } } diff --git a/src/libterm/terminfo/mod.rs b/src/libterm/terminfo/mod.rs index ffe896b93a718..b8fda21b95881 100644 --- a/src/libterm/terminfo/mod.rs +++ b/src/libterm/terminfo/mod.rs @@ -28,13 +28,13 @@ use self::parm::{expand, Number, Variables}; #[derive(Debug)] pub struct TermInfo { /// Names for the terminal - pub names: Vec , + pub names: Vec, /// Map of capability name to boolean value pub bools: HashMap, /// Map of capability name to numeric value pub numbers: HashMap, /// Map of capability name to raw (unexpanded) string - pub strings: HashMap > + pub strings: HashMap>, } pub mod searcher; @@ -49,19 +49,19 @@ pub mod parm; fn cap_for_attr(attr: attr::Attr) -> &'static str { match attr { - attr::Bold => "bold", - attr::Dim => "dim", - attr::Italic(true) => "sitm", - attr::Italic(false) => "ritm", - attr::Underline(true) => "smul", - attr::Underline(false) => "rmul", - attr::Blink => "blink", - attr::Standout(true) => "smso", - attr::Standout(false) => "rmso", - attr::Reverse => "rev", - attr::Secure => "invis", + attr::Bold => "bold", + attr::Dim => "dim", + attr::Italic(true) => "sitm", + attr::Italic(false) => "ritm", + attr::Underline(true) => "smul", + attr::Underline(false) => "rmul", + attr::Blink => "blink", + attr::Standout(true) => "smso", + attr::Standout(false) => "rmso", + attr::Reverse => "rev", + attr::Secure => "invis", attr::ForegroundColor(_) => "setaf", - attr::BackgroundColor(_) => "setab" + attr::BackgroundColor(_) => "setab", } } @@ -70,7 +70,7 @@ fn cap_for_attr(attr: attr::Attr) -> &'static str { pub struct TerminfoTerminal { num_colors: u16, out: T, - ti: Box + ti: Box, } impl Terminal for TerminfoTerminal { @@ -80,12 +80,12 @@ impl Terminal for TerminfoTerminal { let s = expand(self.ti .strings .get("setaf") - .unwrap() - , - &[Number(color as isize)], &mut Variables::new()); + .unwrap(), + &[Number(color as isize)], + &mut Variables::new()); if s.is_ok() { try!(self.out.write_all(&s.unwrap())); - return Ok(true) + return Ok(true); } } Ok(false) @@ -97,12 +97,12 @@ impl Terminal for TerminfoTerminal { let s = expand(self.ti .strings .get("setab") - .unwrap() - , - &[Number(color as isize)], &mut Variables::new()); + .unwrap(), + &[Number(color as isize)], + &mut Variables::new()); if s.is_ok() { try!(self.out.write_all(&s.unwrap())); - return Ok(true) + return Ok(true); } } Ok(false) @@ -116,12 +116,10 @@ impl Terminal for TerminfoTerminal { let cap = cap_for_attr(attr); let parm = self.ti.strings.get(cap); if parm.is_some() { - let s = expand(parm.unwrap(), - &[], - &mut Variables::new()); + let s = expand(parm.unwrap(), &[], &mut Variables::new()); if s.is_ok() { try!(self.out.write_all(&s.unwrap())); - return Ok(true) + return Ok(true); } } Ok(false) @@ -151,22 +149,27 @@ impl Terminal for TerminfoTerminal { cap = self.ti.strings.get("op"); } } - let s = cap.map_or(Err("can't find terminfo capability `sgr0`".to_owned()), |op| { - expand(op, &[], &mut Variables::new()) - }); + let s = cap.map_or(Err("can't find terminfo capability `sgr0`".to_owned()), + |op| expand(op, &[], &mut Variables::new())); if s.is_ok() { - return self.out.write_all(&s.unwrap()) + return self.out.write_all(&s.unwrap()); } Ok(()) } - fn get_ref<'a>(&'a self) -> &'a T { &self.out } + fn get_ref<'a>(&'a self) -> &'a T { + &self.out + } - fn get_mut<'a>(&'a mut self) -> &'a mut T { &mut self.out } + fn get_mut<'a>(&'a mut self) -> &'a mut T { + &mut self.out + } } impl UnwrappableTerminal for TerminfoTerminal { - fn unwrap(self) -> T { self.out } + fn unwrap(self) -> T { + self.out + } } impl TerminfoTerminal { @@ -186,16 +189,16 @@ impl TerminfoTerminal { Err(err) => return match env::var("MSYSCON") { Ok(ref val) if &val[..] == "mintty.exe" => { // msys terminal - Some(box TerminfoTerminal{ + Some(box TerminfoTerminal { out: out, ti: msys_terminfo(), num_colors: 8, }) - }, + } _ => { debug!("error finding terminfo entry: {:?}", err); None - }, + } }, }; @@ -206,20 +209,25 @@ impl TerminfoTerminal { } let inf = ti.unwrap(); - let nc = if inf.strings.get("setaf").is_some() - && inf.strings.get("setab").is_some() { - inf.numbers.get("colors").map_or(0, |&n| n) - } else { 0 }; - - Some(box TerminfoTerminal {out: out, - ti: inf, - num_colors: nc}) + let nc = if inf.strings.get("setaf").is_some() && inf.strings.get("setab").is_some() { + inf.numbers.get("colors").map_or(0, |&n| n) + } else { + 0 + }; + + Some(box TerminfoTerminal { + out: out, + ti: inf, + num_colors: nc, + }) } fn dim_if_necessary(&self, color: color::Color) -> color::Color { if color >= self.num_colors && color >= 8 && color < 16 { color-8 - } else { color } + } else { + color + } } } diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index 9110be33907b0..daedba86f89d0 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -32,14 +32,14 @@ enum States { SeekIfElse(isize), SeekIfElsePercent(isize), SeekIfEnd(isize), - SeekIfEndPercent(isize) + SeekIfEndPercent(isize), } #[derive(Copy, Clone, PartialEq)] enum FormatState { FormatStateFlags, FormatStateWidth, - FormatStatePrecision + FormatStatePrecision, } /// Types of parameters a capability can use @@ -47,7 +47,7 @@ enum FormatState { #[derive(Clone)] pub enum Param { Words(String), - Number(isize) + Number(isize), } /// Container for static and dynamic variable arrays @@ -55,7 +55,7 @@ pub struct Variables { /// Static variables A-Z sta: [Param; 26], /// Dynamic variables a-z - dyn: [Param; 26] + dyn: [Param; 26], } impl Variables { @@ -91,8 +91,7 @@ impl Variables { /// /// To be compatible with ncurses, `vars` should be the same between calls to `expand` for /// multiple capabilities for the same terminal. -pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) - -> Result , String> { +pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result, String> { let mut state = Nothing; // expanded cap will only rarely be larger than the cap itself @@ -119,10 +118,13 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) } else { output.push(c); } - }, + } Percent => { match cur { - '%' => { output.push(c); state = Nothing }, + '%' => { + output.push(c); + state = Nothing + } 'c' => if !stack.is_empty() { match stack.pop().unwrap() { // if c is 0, use 0200 (128) for ncurses compatibility @@ -133,7 +135,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) c as u8 }) } - _ => return Err("a non-char was used with %c".to_owned()) + _ => return Err("a non-char was used with %c".to_owned()), } } else { return Err("stack is empty".to_owned()) }, 'p' => state = PushParam, @@ -146,76 +148,100 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) Words(s) => stack.push(Number(s.len() as isize)), _ => return Err("a non-str was used with %l".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, '+' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x + y)), _ => return Err("non-numbers on stack with +".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, '-' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x - y)), _ => return Err("non-numbers on stack with -".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, '*' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x * y)), _ => return Err("non-numbers on stack with *".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, '/' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x / y)), _ => return Err("non-numbers on stack with /".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, 'm' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x % y)), _ => return Err("non-numbers on stack with %".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, '&' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x & y)), _ => return Err("non-numbers on stack with &".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, '|' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x | y)), _ => return Err("non-numbers on stack with |".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, '^' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x ^ y)), _ => return Err("non-numbers on stack with ^".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, '=' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(if x == y { 1 } else { 0 })), _ => return Err("non-numbers on stack with =".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, '>' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(if x > y { 1 } else { 0 })), _ => return Err("non-numbers on stack with >".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, '<' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(if x < y { 1 } else { 0 })), _ => return Err("non-numbers on stack with <".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, 'A' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(0), Number(_)) => stack.push(Number(0)), @@ -223,27 +249,35 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) (Number(_), Number(_)) => stack.push(Number(1)), _ => return Err("non-numbers on stack with logical and".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, 'O' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(0), Number(0)) => stack.push(Number(0)), (Number(_), Number(_)) => stack.push(Number(1)), _ => return Err("non-numbers on stack with logical or".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, '!' => if !stack.is_empty() { match stack.pop().unwrap() { Number(0) => stack.push(Number(1)), Number(_) => stack.push(Number(0)), _ => return Err("non-number on stack with logical not".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, '~' => if !stack.is_empty() { match stack.pop().unwrap() { Number(x) => stack.push(Number(!x)), _ => return Err("non-number on stack with %~".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, 'i' => match (mparams[0].clone(), mparams[1].clone()) { (Number(x), Number(y)) => { mparams[0] = Number(x+1); @@ -256,10 +290,14 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) 'd'|'o'|'x'|'X'|'s' => if !stack.is_empty() { let flags = Flags::new(); let res = format(stack.pop().unwrap(), FormatOp::from_char(cur), flags); - if res.is_err() { return res } + if res.is_err() { + return res; + } output.push_all(&res.unwrap()) - } else { return Err("stack is empty".to_owned()) }, - ':'|'#'|' '|'.'|'0'...'9' => { + } else { + return Err("stack is empty".to_owned()); + }, + ':' | '#' | ' ' | '.' | '0'...'9' => { let mut flags = Flags::new(); let mut fstate = FormatStateFlags; match cur { @@ -271,7 +309,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) flags.width = cur as usize - '0' as usize; fstate = FormatStateWidth; } - _ => unreachable!() + _ => unreachable!(), } state = FormatPattern(flags, fstate); } @@ -285,7 +323,9 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) _ => return Err("non-number on stack \ with conditional".to_owned()) } - } else { return Err("stack is empty".to_owned()) }, + } else { + return Err("stack is empty".to_owned()); + }, 'e' => state = SeekIfEnd(0), ';' => (), @@ -293,29 +333,33 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) return Err(format!("unrecognized format option {:?}", cur)) } } - }, + } PushParam => { // params are 1-indexed stack.push(mparams[match cur.to_digit(10) { Some(d) => d as usize - 1, None => return Err("bad param number".to_owned()) }].clone()); - }, + } SetVar => { if cur >= 'A' && cur <= 'Z' { if !stack.is_empty() { let idx = (cur as u8) - b'A'; vars.sta[idx as usize] = stack.pop().unwrap(); - } else { return Err("stack is empty".to_owned()) } + } else { + return Err("stack is empty".to_owned()); + } } else if cur >= 'a' && cur <= 'z' { if !stack.is_empty() { let idx = (cur as u8) - b'a'; vars.dyn[idx as usize] = stack.pop().unwrap(); - } else { return Err("stack is empty".to_owned()) } + } else { + return Err("stack is empty".to_owned()); + } } else { return Err("bad variable name in %P".to_owned()); } - }, + } GetVar => { if cur >= 'A' && cur <= 'Z' { let idx = (cur as u8) - b'A'; @@ -326,16 +370,16 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) } else { return Err("bad variable name in %g".to_owned()); } - }, + } CharConstant => { stack.push(Number(c as isize)); state = CharClose; - }, + } CharClose => { if cur != '\'' { return Err("malformed character constant".to_owned()); } - }, + } IntConstant(i) => { match cur { '}' => { @@ -354,12 +398,16 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) match (*fstate, cur) { (_,'d')|(_,'o')|(_,'x')|(_,'X')|(_,'s') => if !stack.is_empty() { let res = format(stack.pop().unwrap(), FormatOp::from_char(cur), *flags); - if res.is_err() { return res } + if res.is_err() { + return res; + } output.push_all(&res.unwrap()); // will cause state to go to Nothing old_state = FormatPattern(*flags, *fstate); - } else { return Err("stack is empty".to_owned()) }, - (FormatStateFlags,'#') => { + } else { + return Err("stack is empty".to_owned()); + }, + (FormatStateFlags, '#') => { flags.alternate = true; } (FormatStateFlags,'-') => { @@ -381,7 +429,9 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) (FormatStateWidth,'0'...'9') => { let old = flags.width; flags.width = flags.width * 10 + (cur as usize - '0' as usize); - if flags.width < old { return Err("format width overflow".to_owned()) } + if flags.width < old { + return Err("format width overflow".to_owned()); + } } (FormatStateWidth,'.') => { *fstate = FormatStatePrecision; @@ -451,13 +501,19 @@ struct Flags { alternate: bool, left: bool, sign: bool, - space: bool + space: bool, } impl Flags { fn new() -> Flags { - Flags{ width: 0, precision: 0, alternate: false, - left: false, sign: false, space: false } + Flags { + width: 0, + precision: 0, + alternate: false, + left: false, + sign: false, + space: false, + } } } @@ -467,7 +523,7 @@ enum FormatOp { FormatOctal, FormatHex, FormatHEX, - FormatString + FormatString, } impl FormatOp { @@ -478,7 +534,7 @@ impl FormatOp { 'x' => FormatHex, 'X' => FormatHEX, 's' => FormatString, - _ => panic!("bad FormatOp char") + _ => panic!("bad FormatOp char"), } } fn to_char(self) -> char { @@ -487,7 +543,7 @@ impl FormatOp { FormatOctal => 'o', FormatHex => 'x', FormatHEX => 'X', - FormatString => 's' + FormatString => 's', } } } @@ -538,7 +594,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result ,String> { s.extend(s_); } } - FormatString => unreachable!() + FormatString => unreachable!(), } s } @@ -552,8 +608,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result ,String> { s } _ => { - return Err(format!("non-string on stack with %{:?}", - op.to_char())) + return Err(format!("non-string on stack with %{:?}", op.to_char())); } } } @@ -594,7 +649,8 @@ mod tests { fn test_op_i() { let mut vars = Variables::new(); assert_eq!(expand(b"%p1%d%p2%d%p3%d%i%p1%d%p2%d%p3%d", - &[Number(1),Number(2),Number(3)], &mut vars), + &[Number(1), Number(2), Number(3)], + &mut vars), Ok("123233".bytes().collect::>())); assert_eq!(expand(b"%p1%d%p2%d%i%p1%d%p2%d", &[], &mut vars), Ok("0011".bytes().collect::>())); @@ -616,7 +672,8 @@ mod tests { for &cap in &caps { let res = get_res("", cap, &[], vars); assert!(res.is_err(), - "Op {} succeeded incorrectly with 0 stack entries", cap); + "Op {} succeeded incorrectly with 0 stack entries", + cap); let p = if cap == "%s" || cap == "%l" { Words("foo".to_string()) } else { @@ -624,19 +681,25 @@ mod tests { }; let res = get_res("%p1", cap, &[p], vars); assert!(res.is_ok(), - "Op {} failed with 1 stack entry: {}", cap, res.err().unwrap()); + "Op {} failed with 1 stack entry: {}", + cap, + res.err().unwrap()); } let caps = ["%+", "%-", "%*", "%/", "%m", "%&", "%|", "%A", "%O"]; for &cap in &caps { let res = expand(cap.as_bytes(), &[], vars); assert!(res.is_err(), - "Binop {} succeeded incorrectly with 0 stack entries", cap); + "Binop {} succeeded incorrectly with 0 stack entries", + cap); let res = get_res("%{1}", cap, &[], vars); assert!(res.is_err(), - "Binop {} succeeded incorrectly with 1 stack entry", cap); + "Binop {} succeeded incorrectly with 1 stack entry", + cap); let res = get_res("%{1}%{2}", cap, &[], vars); assert!(res.is_ok(), - "Binop {} failed with 2 stack entries: {:?}", cap, res.err().unwrap()); + "Binop {} failed with 2 stack entries: {:?}", + cap, + res.err().unwrap()); } } @@ -670,16 +733,13 @@ mod tests { let s = b"\\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m"; let res = expand(s, &[Number(1)], &mut vars); assert!(res.is_ok(), res.err().unwrap()); - assert_eq!(res.unwrap(), - "\\E[31m".bytes().collect::>()); + assert_eq!(res.unwrap(), "\\E[31m".bytes().collect::>()); let res = expand(s, &[Number(8)], &mut vars); assert!(res.is_ok(), res.err().unwrap()); - assert_eq!(res.unwrap(), - "\\E[90m".bytes().collect::>()); + assert_eq!(res.unwrap(), "\\E[90m".bytes().collect::>()); let res = expand(s, &[Number(42)], &mut vars); assert!(res.is_ok(), res.err().unwrap()); - assert_eq!(res.unwrap(), - "\\E[38;5;42m".bytes().collect::>()); + assert_eq!(res.unwrap(), "\\E[38;5;42m".bytes().collect::>()); } #[test] @@ -690,14 +750,17 @@ mod tests { &[Words("foo".to_string()), Words("foo".to_string()), Words("f".to_string()), - Words("foo".to_string())], vars), + Words("foo".to_string())], + vars), Ok("foofoo ffo".bytes().collect::>())); assert_eq!(expand(b"%p1%:-4.2s", &[Words("foo".to_owned())], vars), Ok("fo ".bytes().collect::>())); assert_eq!(expand(b"%p1%d%p1%.3d%p1%5d%p1%:+d", &[Number(1)], vars), Ok("1001 1+1".bytes().collect::>())); - assert_eq!(expand(b"%p1%o%p1%#o%p2%6.4x%p2%#6.4X", &[Number(15), Number(27)], vars), + assert_eq!(expand(b"%p1%o%p1%#o%p2%6.4x%p2%#6.4X", + &[Number(15), Number(27)], + vars), Ok("17017 001b0X001B".bytes().collect::>())); } }