| 1 | extern crate swrite; |
| 2 | use swrite::{swrite, swriteln, SWrite}; |
| 3 | |
| 4 | #[test] |
| 5 | fn test_swrite() { |
| 6 | let mut buf = String::new(); |
| 7 | swrite!(buf, "Hello, {}!", "world"); |
| 8 | assert_eq!(buf, "Hello, world!"); |
| 9 | } |
| 10 | |
| 11 | #[test] |
| 12 | fn test_swriteln() { |
| 13 | let mut buf = String::new(); |
| 14 | swriteln!(buf, "Hello, {}!", "world"); |
| 15 | assert_eq!(buf, "Hello, world!\n"); |
| 16 | } |
| 17 | |
| 18 | #[test] |
| 19 | fn test_swriteln_appends() { |
| 20 | let mut buf = String::new(); |
| 21 | swrite!(buf, "Hello, {}", "world"); |
| 22 | assert_eq!(buf, "Hello, world"); |
| 23 | swriteln!(buf, "!"); |
| 24 | assert_eq!(buf, "Hello, world!\n"); |
| 25 | } |
| 26 | |
| 27 | #[test] |
| 28 | fn test_swriteln_empty() { |
| 29 | let mut buf = String::new(); |
| 30 | swriteln!(buf); |
| 31 | assert_eq!(buf, "\n"); |
| 32 | let mut buf = String::new(); |
| 33 | swriteln!(buf,); |
| 34 | assert_eq!(buf, "\n"); |
| 35 | } |
| 36 | |
| 37 | mod qualified { |
| 38 | use swrite::SWrite; |
| 39 | |
| 40 | #[test] |
| 41 | fn test_swrite() { |
| 42 | let mut buf = String::new(); |
| 43 | swrite::swrite!(buf, "Hello, {}!", "world"); |
| 44 | assert_eq!(buf, "Hello, world!"); |
| 45 | } |
| 46 | |
| 47 | #[test] |
| 48 | fn test_swriteln() { |
| 49 | let mut buf = String::new(); |
| 50 | swrite::swriteln!(buf, "Hello, {}!", "world"); |
| 51 | assert_eq!(buf, "Hello, world!\n"); |
| 52 | } |
| 53 | |
| 54 | #[test] |
| 55 | fn test_swriteln_appends() { |
| 56 | let mut buf = String::new(); |
| 57 | swrite::swrite!(buf, "Hello, {}", "world"); |
| 58 | assert_eq!(buf, "Hello, world"); |
| 59 | swrite::swriteln!(buf, "!"); |
| 60 | assert_eq!(buf, "Hello, world!\n"); |
| 61 | } |
| 62 | |
| 63 | #[test] |
| 64 | fn test_swriteln_empty() { |
| 65 | let mut buf = String::new(); |
| 66 | swrite::swriteln!(buf); |
| 67 | assert_eq!(buf, "\n"); |
| 68 | let mut buf = String::new(); |
| 69 | swrite::swriteln!(buf,); |
| 70 | assert_eq!(buf, "\n"); |
| 71 | } |
| 72 | } |