2020-06-29 15:36:01 +00:00
|
|
|
use crate::sql::comment::shouldbespace;
|
|
|
|
use crate::sql::common::take_u64;
|
|
|
|
use nom::bytes::complete::tag_no_case;
|
|
|
|
use nom::combinator::opt;
|
|
|
|
use nom::sequence::tuple;
|
|
|
|
use nom::IResult;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use std::fmt;
|
|
|
|
|
2021-03-29 15:43:37 +00:00
|
|
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
|
2022-01-13 17:36:41 +00:00
|
|
|
pub struct Start(pub u64);
|
2020-06-29 15:36:01 +00:00
|
|
|
|
|
|
|
impl fmt::Display for Start {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2022-01-13 17:36:41 +00:00
|
|
|
write!(f, "START {}", self.0)
|
2020-06-29 15:36:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn start(i: &str) -> IResult<&str, Start> {
|
|
|
|
let (i, _) = tag_no_case("START")(i)?;
|
|
|
|
let (i, _) = opt(tuple((shouldbespace, tag_no_case("AT"))))(i)?;
|
|
|
|
let (i, _) = shouldbespace(i)?;
|
|
|
|
let (i, v) = take_u64(i)?;
|
2022-01-13 17:36:41 +00:00
|
|
|
Ok((i, Start(v)))
|
2020-06-29 15:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn start_statement() {
|
|
|
|
let sql = "START 100";
|
|
|
|
let res = start(sql);
|
|
|
|
assert!(res.is_ok());
|
|
|
|
let out = res.unwrap().1;
|
2022-01-13 17:36:41 +00:00
|
|
|
assert_eq!(out, Start(100));
|
2020-06-29 15:36:01 +00:00
|
|
|
assert_eq!("START 100", format!("{}", out));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn start_statement_at() {
|
|
|
|
let sql = "START AT 100";
|
|
|
|
let res = start(sql);
|
|
|
|
assert!(res.is_ok());
|
|
|
|
let out = res.unwrap().1;
|
2022-01-13 17:36:41 +00:00
|
|
|
assert_eq!(out, Start(100));
|
2020-06-29 15:36:01 +00:00
|
|
|
assert_eq!("START 100", format!("{}", out));
|
|
|
|
}
|
|
|
|
}
|