mirror of
https://github.com/loot/loot-condition-interpreter.git
synced 2026-07-27 14:16:09 -07:00
Update nom to v4 and regex to v1
This commit is contained in:
+2
-2
@@ -4,5 +4,5 @@ version = "0.1.0"
|
|||||||
authors = ["Oliver Hamlet <oliver.hamlet@gmail.com>"]
|
authors = ["Oliver Hamlet <oliver.hamlet@gmail.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nom = "3.2.1"
|
nom = "4.0.0"
|
||||||
regex = "0.2"
|
regex = "1.0.5"
|
||||||
|
|||||||
+3
-3
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
|
|||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use nom::{IError, IResult};
|
use nom::IResult;
|
||||||
|
|
||||||
use super::Error;
|
use super::Error;
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn function_parse_should_parse_a_file_path_function() {
|
fn function_parse_should_parse_a_file_path_function() {
|
||||||
let result = Function::parse("file(\"Cargo.toml\")").to_result().unwrap();
|
let result = Function::parse("file(\"Cargo.toml\")").unwrap().1;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Function::FilePath(f) => assert_eq!(PathBuf::from("Cargo.toml"), f),
|
Function::FilePath(f) => assert_eq!(PathBuf::from("Cargo.toml"), f),
|
||||||
@@ -75,7 +75,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn function_parse_should_parse_an_active_function() {
|
fn function_parse_should_parse_an_active_function() {
|
||||||
let result = Function::parse("active(\"Cargo.toml\")").to_result().unwrap();
|
let result = Function::parse("active(\"Cargo.toml\")").unwrap().1;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Function::ActivePath(f) => assert_eq!(PathBuf::from("Cargo.toml"), f),
|
Function::ActivePath(f) => assert_eq!(PathBuf::from("Cargo.toml"), f),
|
||||||
|
|||||||
+12
-19
@@ -2,7 +2,7 @@
|
|||||||
extern crate nom;
|
extern crate nom;
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
||||||
use nom::{IError, IResult};
|
use nom::{Err, IResult};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
@@ -17,11 +17,11 @@ pub enum Error {
|
|||||||
InvalidRegex(String),
|
InvalidRegex(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<IError> for Error {
|
impl<I> From<Err<I>> for Error {
|
||||||
fn from(error: IError) -> Self {
|
fn from(error: Err<I>) -> Self {
|
||||||
match error {
|
match error {
|
||||||
IError::Error(_) => Error::ParsingError,
|
Err::Incomplete(_) => Error::ParsingIncomplete,
|
||||||
_ => Error::ParsingIncomplete,
|
_ => Error::ParsingError,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,8 +115,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn expression_parse_should_handle_a_single_compound_condition() {
|
fn expression_parse_should_handle_a_single_compound_condition() {
|
||||||
let result = Expression::parse("file(\"Cargo.toml\")")
|
let result = Expression::parse("file(\"Cargo.toml\")")
|
||||||
.to_result()
|
.unwrap().1;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
match result.0.as_slice() {
|
match result.0.as_slice() {
|
||||||
[CompoundCondition(_)] => {}
|
[CompoundCondition(_)] => {}
|
||||||
@@ -127,8 +126,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn expression_parse_should_handle_multiple_compound_conditions() {
|
fn expression_parse_should_handle_multiple_compound_conditions() {
|
||||||
let result = Expression::parse("file(\"Cargo.toml\") or file(\"Cargo.toml\")")
|
let result = Expression::parse("file(\"Cargo.toml\") or file(\"Cargo.toml\")")
|
||||||
.to_result()
|
.unwrap().1;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
match result.0.as_slice() {
|
match result.0.as_slice() {
|
||||||
[CompoundCondition(_), CompoundCondition(_)] => {}
|
[CompoundCondition(_), CompoundCondition(_)] => {}
|
||||||
@@ -142,8 +140,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn compound_condition_parse_should_handle_a_single_condition() {
|
fn compound_condition_parse_should_handle_a_single_condition() {
|
||||||
let result = CompoundCondition::parse("file(\"Cargo.toml\")")
|
let result = CompoundCondition::parse("file(\"Cargo.toml\")")
|
||||||
.to_result()
|
.unwrap().1;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
match result.0.as_slice() {
|
match result.0.as_slice() {
|
||||||
[Condition::Function(Function::FilePath(f))] => {
|
[Condition::Function(Function::FilePath(f))] => {
|
||||||
@@ -159,8 +156,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn compound_condition_parse_should_handle_multiple_conditions() {
|
fn compound_condition_parse_should_handle_multiple_conditions() {
|
||||||
let result = CompoundCondition::parse("file(\"Cargo.toml\") and file(\"README.md\")")
|
let result = CompoundCondition::parse("file(\"Cargo.toml\") and file(\"README.md\")")
|
||||||
.to_result()
|
.unwrap().1;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
match result.0.as_slice() {
|
match result.0.as_slice() {
|
||||||
[Condition::Function(Function::FilePath(f1)), Condition::Function(Function::FilePath(f2))] =>
|
[Condition::Function(Function::FilePath(f1)), Condition::Function(Function::FilePath(f2))] =>
|
||||||
@@ -178,8 +174,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn condition_parse_should_handle_a_function() {
|
fn condition_parse_should_handle_a_function() {
|
||||||
let result = Condition::parse("file(\"Cargo.toml\")")
|
let result = Condition::parse("file(\"Cargo.toml\")")
|
||||||
.to_result()
|
.unwrap().1;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Condition::Function(Function::FilePath(f)) => {
|
Condition::Function(Function::FilePath(f)) => {
|
||||||
@@ -195,8 +190,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn condition_parse_should_handle_a_inverted_function() {
|
fn condition_parse_should_handle_a_inverted_function() {
|
||||||
let result = Condition::parse("not file(\"Cargo.toml\")")
|
let result = Condition::parse("not file(\"Cargo.toml\")")
|
||||||
.to_result()
|
.unwrap().1;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Condition::InvertedFunction(Function::FilePath(f)) => {
|
Condition::InvertedFunction(Function::FilePath(f)) => {
|
||||||
@@ -212,8 +206,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn condition_parse_should_handle_an_expression_in_parentheses() {
|
fn condition_parse_should_handle_an_expression_in_parentheses() {
|
||||||
let result = Condition::parse("(not file(\"Cargo.toml\"))")
|
let result = Condition::parse("(not file(\"Cargo.toml\"))")
|
||||||
.to_result()
|
.unwrap().1;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Condition::Expression(_) => {}
|
Condition::Expression(_) => {}
|
||||||
|
|||||||
Reference in New Issue
Block a user