Extract assert_parses_to into a parser utility crate, r=rnewman. Fixes #200

Signed-off-by: Victor Porof <vporof@mozilla.com>
This commit is contained in:
Victor Porof 2017-02-01 09:45:55 +01:00
parent a9929249eb
commit ba1896b684
6 changed files with 36 additions and 9 deletions

View file

@ -18,6 +18,9 @@ features = ["bundled"]
[dependencies.edn] [dependencies.edn]
path = "edn" path = "edn"
[dependencies.parser_utils]
path = "parser-utils"
[dependencies.mentat_db] [dependencies.mentat_db]
path = "db" path = "db"

6
parser-utils/Cargo.toml Normal file
View file

@ -0,0 +1,6 @@
[package]
name = "parser_utils"
version = "0.1.0"
authors = ["Victor Porof <vporof@mozilla.com>"]
[dependencies]

20
parser-utils/src/lib.rs Normal file
View file

@ -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, &[][..])));
}}
}

View file

@ -8,5 +8,8 @@ combine = "2.1.1"
[dependencies.edn] [dependencies.edn]
path = "../edn" path = "../edn"
[dependencies.parser_utils]
path = "../parser-utils"
[dependencies.mentat_query] [dependencies.mentat_query]
path = "../query" path = "../query"

View file

@ -8,8 +8,11 @@
// CONDITIONS OF ANY KIND, either express or implied. See the License for the // CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License. // specific language governing permissions and limitations under the License.
#![allow(unused_imports)]
#[macro_use]
extern crate parser_utils;
mod error; mod error;
mod util; mod util;
mod parse; mod parse;
pub mod find; pub mod find;

View file

@ -190,14 +190,6 @@ mod test {
use super::*; 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] #[test]
fn test_find_sp_variable() { fn test_find_sp_variable() {
let sym = edn::PlainSymbol::new("?x"); let sym = edn::PlainSymbol::new("?x");