kxio/examples/printer.rs
Paul Campbell bc7219755e
Some checks failed
Test / build (map[name:nightly]) (push) Failing after 5m3s
Test / build (map[name:stable]) (push) Failing after 6m4s
feat(print): add print module
2024-12-12 08:26:06 +00:00

34 lines
848 B
Rust

use kxio::{kxprintln, print::Printer};
// Example using kxprintln macro
fn greet(printer: &Printer, name: &str) {
kxprintln!(printer, "Hello, {}!", name);
}
fn main() {
// Production code example
let printer = Printer::standard();
kxprintln!(printer, "Macro says: Hello, {}!", "Carol");
greet(&printer, "Carol");
}
#[cfg(test)]
mod test {
use super::*;
use kxio::print::TestPrint;
#[test]
fn test_printer() {
// Test code
let printer = Printer::test();
// Get reference to TestPrinter so we can make assertions
let test_print = printer.as_test().unwrap();
greet(&printer, "Bob");
assert_eq!(test_print.output(), "Hello, Bob!\n");
test_print.clear();
greet(&printer, "Dave");
assert_eq!(test_print.output(), "Hello, Dave!\n");
}
}