-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #66
- Loading branch information
Showing
9 changed files
with
206 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crate::sql::error::IResult; | ||
use crate::sql::id::{id, Id}; | ||
use crate::sql::ident::ident_raw; | ||
use nom::character::complete::char; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)] | ||
pub struct Range { | ||
pub tb: String, | ||
pub beg: Id, | ||
pub end: Id, | ||
} | ||
|
||
impl fmt::Display for Range { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}:{}..{}", self.tb, self.beg, self.end) | ||
} | ||
} | ||
|
||
pub fn range(i: &str) -> IResult<&str, Range> { | ||
let (i, tb) = ident_raw(i)?; | ||
let (i, _) = char(':')(i)?; | ||
let (i, beg) = id(i)?; | ||
let (i, _) = char('.')(i)?; | ||
let (i, _) = char('.')(i)?; | ||
let (i, end) = id(i)?; | ||
Ok(( | ||
i, | ||
Range { | ||
tb, | ||
beg, | ||
end, | ||
}, | ||
)) | ||
} | ||
#[cfg(test)] | ||
mod tests { | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn range_array() { | ||
let sql = "person:['USA', 10]..['USA', 100]"; | ||
let res = range(sql); | ||
assert!(res.is_ok()); | ||
let out = res.unwrap().1; | ||
assert_eq!(r#"person:["USA", 10]..["USA", 100]"#, format!("{}", out)); | ||
} | ||
|
||
#[test] | ||
fn range_object() { | ||
let sql = "person:{ country: 'USA', position: 10 }..{ country: 'USA', position: 100 }"; | ||
let res = range(sql); | ||
assert!(res.is_ok()); | ||
let out = res.unwrap().1; | ||
assert_eq!( | ||
r#"person:{ country: "USA", position: 10 }..{ country: "USA", position: 100 }"#, | ||
format!("{}", out) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters