jethrogb / rust-cexpr

A C expression parser and evaluator
Apache License 2.0
45 stars 19 forks source link

String escaping is not handled correctly. #12

Closed emilio closed 5 years ago

emilio commented 5 years ago

The following test fails:

```diff From 6579bb4b08c164ead6a29db20984b3cbb1b0f796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 14 Jan 2019 14:28:37 +0100 Subject: [PATCH] Add a test for string escaping. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/clang.rs | 14 ++++++++++++++ tests/input/string_escape.h | 1 + 2 files changed, 15 insertions(+) create mode 100644 tests/input/string_escape.h diff --git a/tests/clang.rs b/tests/clang.rs index 322bf5e..dd64cfe 100644 --- a/tests/clang.rs +++ b/tests/clang.rs @@ -244,3 +244,17 @@ test_file!(strings); test_file!(int_signed); test_file!(int_unsigned); test_file!(fail); + +#[test] +fn string_escaped() { + use cexpr::expr::EvalResult::*; + let mut value = None; + file_visit_macros("tests/input/string_escape.h", fix_bug_9069(), |ident, tokens| { + assert_eq!(&ident, b"escaped"); + value = IdentifierParser::new(&mut Default::default()) + .macro_definition(&tokens) + .map(|(_, (_,val))|val) + .ok(); + }); + assert_eq!(value, Some(Str(b"foo bar\nbaz".to_vec()))); +} diff --git a/tests/input/string_escape.h b/tests/input/string_escape.h new file mode 100644 index 0000000..b720b24 --- /dev/null +++ b/tests/input/string_escape.h @@ -0,0 +1 @@ +#define escaped "foo\sbar\nbaz" -- 2.20.1 ```

Though per https://github.com/rust-lang/rust-bindgen/issues/1468#issuecomment-453892486 looks like it should pass.