1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#![warn(missing_docs)]
#[cfg(any(windows, feature="doc"))]
pub mod windows;
#[cfg(windows)]
pub use windows::{ansi_to_string, oem_to_string, string_to_ansi, string_to_oem};
pub mod posix;
#[cfg(any(not(windows), feature="doc"))]
pub use posix::{ansi_to_string, oem_to_string, string_to_ansi, string_to_oem};
#[cfg(test)]
mod tests {
use super::*;
use std::io::Result;
#[test]
fn oem_to_string_test() {
to_string_test(oem_to_string);
}
#[test]
fn ansi_to_string_test() {
to_string_test(ansi_to_string);
}
#[test]
fn string_to_oem_test() {
from_string_test(string_to_oem);
}
#[test]
fn string_to_ansi_test() {
from_string_test(string_to_ansi);
}
fn to_string_test<F: FnOnce(&[u8]) -> Result<String>>(f: F) {
assert_eq!(f(b"Test").unwrap(), "Test");
}
fn from_string_test<F: FnOnce(&str) -> Result<Vec<u8>>>(f: F) {
assert_eq!(&f("Test").unwrap(), b"Test");
}
}