From ba1896b684098957f6d1d41e62b3c05e6b4b5443 Mon Sep 17 00:00:00 2001 From: Victor Porof Date: Wed, 1 Feb 2017 09:45:55 +0100 Subject: [PATCH] Extract assert_parses_to into a parser utility crate, r=rnewman. Fixes #200 Signed-off-by: Victor Porof --- Cargo.toml | 3 +++ parser-utils/Cargo.toml | 6 ++++++ parser-utils/src/lib.rs | 20 ++++++++++++++++++++ query-parser/Cargo.toml | 3 +++ query-parser/src/lib.rs | 5 ++++- query-parser/src/parse.rs | 8 -------- 6 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 parser-utils/Cargo.toml create mode 100644 parser-utils/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 4c6a7a4c..890babfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,9 @@ features = ["bundled"] [dependencies.edn] path = "edn" +[dependencies.parser_utils] +path = "parser-utils" + [dependencies.mentat_db] path = "db" diff --git a/parser-utils/Cargo.toml b/parser-utils/Cargo.toml new file mode 100644 index 00000000..9a97fd1d --- /dev/null +++ b/parser-utils/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "parser_utils" +version = "0.1.0" +authors = ["Victor Porof "] + +[dependencies] diff --git a/parser-utils/src/lib.rs b/parser-utils/src/lib.rs new file mode 100644 index 00000000..b20d9dbd --- /dev/null +++ b/parser-utils/src/lib.rs @@ -0,0 +1,20 @@ +// Copyright 2016 Mozilla +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +/// `assert_parses_to!` simplifies some of the boilerplate around running a +/// parser function against input and expecting a certain result. +#[macro_export] +macro_rules! assert_parses_to { + ( $parser: path, $input: expr, $expected: expr ) => {{ + let mut par = $parser(); + let result = par.parse(&$input[..]); + assert_eq!(result, Ok(($expected, &[][..]))); + }} +} \ No newline at end of file diff --git a/query-parser/Cargo.toml b/query-parser/Cargo.toml index 3202966a..6d4852a4 100644 --- a/query-parser/Cargo.toml +++ b/query-parser/Cargo.toml @@ -8,5 +8,8 @@ combine = "2.1.1" [dependencies.edn] path = "../edn" +[dependencies.parser_utils] + path = "../parser-utils" + [dependencies.mentat_query] path = "../query" diff --git a/query-parser/src/lib.rs b/query-parser/src/lib.rs index 7bd90c78..ae477ab7 100644 --- a/query-parser/src/lib.rs +++ b/query-parser/src/lib.rs @@ -8,8 +8,11 @@ // CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. +#![allow(unused_imports)] +#[macro_use] +extern crate parser_utils; + mod error; mod util; mod parse; pub mod find; - diff --git a/query-parser/src/parse.rs b/query-parser/src/parse.rs index 583db04d..4c9e50a5 100644 --- a/query-parser/src/parse.rs +++ b/query-parser/src/parse.rs @@ -190,14 +190,6 @@ mod test { use super::*; - macro_rules! assert_parses_to { - ( $parser: path, $input: expr, $expected: expr ) => {{ - let mut par = $parser(); - let result = par.parse(&$input[..]); - assert_eq!(result, Ok(($expected, &[][..]))); - }} - } - #[test] fn test_find_sp_variable() { let sym = edn::PlainSymbol::new("?x");