diff options
| author | bors <bors@rust-lang.org> | 2014-06-18 02:06:37 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-06-18 02:06:37 +0000 |
| commit | d6736a1440d42f6af967a8a20ab8d73522112b72 (patch) | |
| tree | 2a92204127cf1512a60c81ecbb5700288d8f1b92 /src/test | |
| parent | 5c81a186e9d835ca66865bd9807524b805a06d8d (diff) | |
| parent | 3744d828513092d1ed64c4c6f8cd2536f7a5ff0d (diff) | |
| download | rust-d6736a1440d42f6af967a8a20ab8d73522112b72.tar.gz rust-d6736a1440d42f6af967a8a20ab8d73522112b72.zip | |
auto merge of #14880 : SimonSapin/rust/byte-literals, r=alexcrichton
See #14646 (tracking issue) and rust-lang/rfcs#69. This does not close the tracking issue, as the `bytes!()` macro still needs to be removed. It will be later, after a snapshot is made with the changes in this PR, so that the new syntax can be used when bootstrapping the compiler.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/byte-literals.rs | 25 | ||||
| -rw-r--r-- | src/test/compile-fail/byte-string-literals.rs | 23 | ||||
| -rw-r--r-- | src/test/compile-fail/concat.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/lex-unknown-str-escape.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/raw-byte-string-eof.rs | 16 | ||||
| -rw-r--r-- | src/test/compile-fail/raw-byte-string-literals.rs | 17 | ||||
| -rw-r--r-- | src/test/run-pass/byte-literals.rs | 56 |
7 files changed, 140 insertions, 1 deletions
diff --git a/src/test/compile-fail/byte-literals.rs b/src/test/compile-fail/byte-literals.rs new file mode 100644 index 00000000000..436078fa762 --- /dev/null +++ b/src/test/compile-fail/byte-literals.rs @@ -0,0 +1,25 @@ +// Copyright 2014 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. + + +// ignore-tidy-tab + +static FOO: u8 = b'\f'; //~ ERROR unknown byte escape + +pub fn main() { + b'\f'; //~ ERROR unknown byte escape + b'\x0Z'; //~ ERROR illegal character in numeric character escape: Z + b' '; //~ ERROR byte constant must be escaped + b'''; //~ ERROR byte constant must be escaped + b'é'; //~ ERROR byte constant must be ASCII + b'a //~ ERROR unterminated byte constant +} + + diff --git a/src/test/compile-fail/byte-string-literals.rs b/src/test/compile-fail/byte-string-literals.rs new file mode 100644 index 00000000000..ec67cdd77e1 --- /dev/null +++ b/src/test/compile-fail/byte-string-literals.rs @@ -0,0 +1,23 @@ +// Copyright 2014 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. + + +// ignore-tidy-tab + +static FOO: &'static [u8] = b"\f"; //~ ERROR unknown byte escape + +pub fn main() { + b"\f"; //~ ERROR unknown byte escape + b"\x0Z"; //~ ERROR illegal character in numeric character escape: Z + b"é"; //~ ERROR byte constant must be ASCII + b"a //~ ERROR unterminated double quote byte string +} + + diff --git a/src/test/compile-fail/concat.rs b/src/test/compile-fail/concat.rs index c34e402c90b..dc31126e6d6 100644 --- a/src/test/compile-fail/concat.rs +++ b/src/test/compile-fail/concat.rs @@ -9,6 +9,8 @@ // except according to those terms. fn main() { + concat!(b'f'); //~ ERROR: cannot concatenate a binary literal + concat!(b"foo"); //~ ERROR: cannot concatenate a binary literal concat!(foo); //~ ERROR: expected a literal concat!(foo()); //~ ERROR: expected a literal } diff --git a/src/test/compile-fail/lex-unknown-str-escape.rs b/src/test/compile-fail/lex-unknown-str-escape.rs index f7809b02b0b..9a59c422711 100644 --- a/src/test/compile-fail/lex-unknown-str-escape.rs +++ b/src/test/compile-fail/lex-unknown-str-escape.rs @@ -9,5 +9,5 @@ // except according to those terms. static s: &'static str = - "\●" //~ ERROR: unknown string escape + "\●" //~ ERROR: unknown character escape ; diff --git a/src/test/compile-fail/raw-byte-string-eof.rs b/src/test/compile-fail/raw-byte-string-eof.rs new file mode 100644 index 00000000000..83ea9db39b7 --- /dev/null +++ b/src/test/compile-fail/raw-byte-string-eof.rs @@ -0,0 +1,16 @@ +// Copyright 2014 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. + + +pub fn main() { + br##"a"#; //~ unterminated raw string +} + + diff --git a/src/test/compile-fail/raw-byte-string-literals.rs b/src/test/compile-fail/raw-byte-string-literals.rs new file mode 100644 index 00000000000..7a3d1b2318a --- /dev/null +++ b/src/test/compile-fail/raw-byte-string-literals.rs @@ -0,0 +1,17 @@ +// Copyright 2014 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. + + +pub fn main() { + br"é"; //~ raw byte string must be ASCII + br##~"a"~##; //~ only `#` is allowed in raw string delimitation +} + + diff --git a/src/test/run-pass/byte-literals.rs b/src/test/run-pass/byte-literals.rs new file mode 100644 index 00000000000..5317fdc391f --- /dev/null +++ b/src/test/run-pass/byte-literals.rs @@ -0,0 +1,56 @@ +// Copyright 2014 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. + + +static FOO: u8 = b'\xF0'; +static BAR: &'static [u8] = b"a\xF0\t"; +static BAZ: &'static [u8] = br"a\n"; + +pub fn main() { + assert_eq!(b'a', 97u8); + assert_eq!(b'\n', 10u8); + assert_eq!(b'\r', 13u8); + assert_eq!(b'\t', 9u8); + assert_eq!(b'\\', 92u8); + assert_eq!(b'\'', 39u8); + assert_eq!(b'\"', 34u8); + assert_eq!(b'\0', 0u8); + assert_eq!(b'\xF0', 240u8); + assert_eq!(FOO, 240u8); + + assert_eq!([42, ..b'\t'].as_slice(), &[42, 42, 42, 42, 42, 42, 42, 42, 42]); + + match 42 { + b'*' => {}, + _ => fail!() + } + + match 100 { + b'a' .. b'z' => {}, + _ => fail!() + } + + assert_eq!(b"a\n\r\t\\\'\"\0\xF0", + &[97u8, 10u8, 13u8, 9u8, 92u8, 39u8, 34u8, 0u8, 240u8]); + assert_eq!(b"a\ + b", &[97u8, 98u8]); + assert_eq!(BAR, &[97u8, 240u8, 9u8]); + + match &[97u8, 10u8] { + b"a\n" => {}, + _ => fail!(), + } + + assert_eq!(BAZ, &[97u8, 92u8, 110u8]); + assert_eq!(br"a\n", &[97u8, 92u8, 110u8]); + assert_eq!(br"a\n", b"a\\n"); + assert_eq!(br###"a"##b"###, &[97u8, 34u8, 35u8, 35u8, 98u8]); + assert_eq!(br###"a"##b"###, b"a\"##b"); +} |
