Created
March 11, 2014 02:30
-
-
Save shadowmint/9478400 to your computer and use it in GitHub Desktop.
rust nstrcmp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! trace( | |
($($arg:tt)*) => ( | |
{ let x = ::std::io::stdout().write_line(format_args!(::std::fmt::format, $($arg)*)); println!("{}", x); } | |
); | |
) | |
macro_rules! nstrcmp( | |
($x:ident, $y:ident, $n:expr) => ( | |
$x.len() >= $n && $y.len() >= $n && $x.slice(0, $n) == $y.slice(0, $n) | |
); | |
) | |
#[test] | |
fn test_nstrcmp() { | |
let x = ~"Hello World"; | |
let y = ~"Hello"; | |
let z = ~"hello"; | |
trace!("nstrcmp: {:?}", nstrcmp!(x, y, 5)); | |
trace!("nstrcmp: {:?}", nstrcmp!(x, y, 10)); | |
trace!("nstrcmp: {:?}", nstrcmp!(x, y, 3)); | |
trace!("nstrcmp: {:?}", nstrcmp!(z, y, 4)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
strcmp: true
nstrcmp: false
nstrcmp: true
nstrcmp: false
test nstrcmp::test_nstrcmp ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured