rust/tests/run-pass/strings.rs

35 lines
662 B
Rust
Raw Normal View History

2016-03-18 23:19:39 -06:00
fn empty() -> &'static str {
""
}
fn hello() -> &'static str {
"Hello, world!"
}
2016-03-18 23:20:59 -06:00
fn hello_bytes() -> &'static [u8; 13] {
b"Hello, world!"
}
2016-03-21 18:51:25 -06:00
fn hello_bytes_fat() -> &'static [u8] {
b"Hello, world!"
}
2016-04-22 10:34:14 +02:00
2016-05-31 12:05:25 +02:00
fn fat_pointer_on_32_bit() {
Some(5).expect("foo");
}
2019-02-06 11:47:32 +01:00
fn str_indexing() {
let mut x = "Hello".to_string();
let _v = &mut x[..3]; // Test IndexMut on String.
}
fn main() {
assert_eq!(empty(), "");
assert_eq!(hello(), "Hello, world!");
assert_eq!(hello_bytes(), b"Hello, world!");
assert_eq!(hello_bytes_fat(), b"Hello, world!");
2019-02-06 11:47:32 +01:00
fat_pointer_on_32_bit(); // Should run without crashing.
2019-02-06 11:47:32 +01:00
str_indexing();
}