-// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
use std::ffi;
use std::ops::Deref;
use smallvec::SmallVec;
+#[cfg(test)]
+mod tests;
+
const SIZE: usize = 36;
/// Like SmallVec but for C strings.
self.as_c_str()
}
}
-
-#[test]
-fn short() {
- const TEXT: &str = "abcd";
- let reference = ffi::CString::new(TEXT.to_string()).unwrap();
-
- let scs = SmallCStr::new(TEXT);
-
- assert_eq!(scs.len_with_nul(), TEXT.len() + 1);
- assert_eq!(scs.as_c_str(), reference.as_c_str());
- assert!(!scs.spilled());
-}
-
-#[test]
-fn empty() {
- const TEXT: &str = "";
- let reference = ffi::CString::new(TEXT.to_string()).unwrap();
-
- let scs = SmallCStr::new(TEXT);
-
- assert_eq!(scs.len_with_nul(), TEXT.len() + 1);
- assert_eq!(scs.as_c_str(), reference.as_c_str());
- assert!(!scs.spilled());
-}
-
-#[test]
-fn long() {
- const TEXT: &str = "01234567890123456789012345678901234567890123456789\
- 01234567890123456789012345678901234567890123456789\
- 01234567890123456789012345678901234567890123456789";
- let reference = ffi::CString::new(TEXT.to_string()).unwrap();
-
- let scs = SmallCStr::new(TEXT);
-
- assert_eq!(scs.len_with_nul(), TEXT.len() + 1);
- assert_eq!(scs.as_c_str(), reference.as_c_str());
- assert!(scs.spilled());
-}
-
-#[test]
-#[should_panic]
-fn internal_nul() {
- let _ = SmallCStr::new("abcd\0def");
-}