Add basic dbtests for space DDL

next
Sayan Nandan 10 months ago
parent 5c62a842b4
commit d090e5ce37
No known key found for this signature in database
GPG Key ID: 42EEDF4AE9D96B54

@ -106,11 +106,11 @@ impl<'a, Qd: QueryData<'a>> State<'a, Qd> {
}
pub fn try_entity_ref(&mut self) -> Option<EntityIDRef<'a>> {
let self_has_full = Self::_entity_signature_match_self_full(
&self.t[self.round_cursor()],
&self.t[self.round_cursor_up(1)],
&self.t[self.round_cursor_up(2)],
self.offset_current_r(0),
self.offset_current_r(1),
self.offset_current_r(2),
);
let self_has_pre_full = self._entity_signature_match_cs(&self.t[self.round_cursor()]);
let self_has_pre_full = self._entity_signature_match_cs(self.offset_current_r(0));
if self_has_full {
unsafe {
// UNSAFE(@ohsayan): +branch condition
@ -190,6 +190,10 @@ impl<'a, Qd: QueryData<'a>> State<'a, Qd> {
&self.t[self.i..]
}
#[inline(always)]
pub fn offset_current_r(&self, offset: usize) -> &Token<'a> {
&self.t[self.round_cursor_up(offset)]
}
#[inline(always)]
/// Returns a count of the number of consumable tokens remaining
pub fn remaining(&self) -> usize {
self.t.len() - self.i
@ -267,16 +271,16 @@ impl<'a, Qd: QueryData<'a>> State<'a, Qd> {
}
#[inline(always)]
pub(crate) fn cursor_has_ident_rounded(&self) -> bool {
self.t[self.round_cursor()].is_ident() && self.not_exhausted()
self.offset_current_r(0).is_ident() && self.not_exhausted()
}
#[inline(always)]
/// Check if the current token stream matches the signature of an arity(0) fn; rounded
///
/// NOTE: Consider using a direct comparison without rounding
pub(crate) fn cursor_signature_match_fn_arity0_rounded(&self) -> bool {
(self.t[self.round_cursor()].is_ident())
& (self.t[self.round_cursor_up(1)] == Token![() open])
& (self.t[self.round_cursor_up(2)] == Token![() close])
(self.offset_current_r(0).is_ident())
& (Token![() open].eq(self.offset_current_r(1)))
& (Token![() close].eq(self.offset_current_r(2)))
& self.has_remaining(3)
}
#[inline(always)]
@ -319,7 +323,7 @@ impl<'a, Qd: QueryData<'a>> State<'a, Qd> {
}
}
pub fn ensure_minimum_for_blocking_stmt(&self) -> QueryResult<()> {
if self.remaining() < 2 {
if self.exhausted() {
return Err(QueryError::QLExpectedStatement);
} else {
Ok(())

@ -39,7 +39,7 @@ use {
/// A lazily intialized, or _call by need_ value
#[derive(Debug)]
pub struct Lazy<T, F> {
pub struct Lazy<T, F = fn() -> T> {
/// the value (null at first)
value: AtomicPtr<T>,
/// the function that will init the value
@ -48,6 +48,12 @@ pub struct Lazy<T, F> {
init_state: AtomicBool,
}
impl<T: Default> Default for Lazy<T> {
fn default() -> Self {
Self::new(T::default)
}
}
impl<T, F> Lazy<T, F> {
pub const fn new(init_func: F) -> Self {
Self {

@ -0,0 +1,65 @@
/*
* Created on Wed Nov 29 2023
*
* This file is a part of Skytable
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
* NoSQL database written by Sayan Nandan ("the Author") with the
* vision to provide flexibility in data modelling without compromising
* on performance, queryability or scalability.
*
* Copyright (c) 2023, Sayan Nandan <ohsayan@outlook.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
use skytable::error::Error;
use {crate::engine::error::QueryError, sky_macros::dbtest, skytable::query};
const INVALID_SYNTAX_ERR: u16 = QueryError::QLInvalidSyntax.value_u8() as u16;
#[dbtest]
fn ensure_create_space_end_of_tokens() {
let mut con = db!();
assert_err_eq!(
con.query_parse::<()>(&query!("create space myspace with {} this_should_fail")),
Error::ServerError(INVALID_SYNTAX_ERR)
);
assert_err_eq!(
con.query_parse::<()>(&query!("create space myspace this_should_fail")),
Error::ServerError(INVALID_SYNTAX_ERR)
);
}
#[dbtest]
fn ensure_alter_space_end_of_tokens() {
let mut con = db!();
assert_err_eq!(
con.query_parse::<()>(&query!("alter space myspace with {} this_should_fail")),
Error::ServerError(INVALID_SYNTAX_ERR)
);
}
#[dbtest]
fn ensure_drop_space_end_of_tokens() {
let mut con = db!();
assert_err_eq!(
con.query_parse::<()>(&query!("drop space myspace this_should_fail")),
Error::ServerError(INVALID_SYNTAX_ERR)
);
assert_err_eq!(
con.query_parse::<()>(&query!("drop space myspace force this_should_fail")),
Error::ServerError(INVALID_SYNTAX_ERR)
);
}

@ -24,4 +24,5 @@
*
*/
mod ddl;
mod sysctl;

@ -0,0 +1,40 @@
/*
* Created on Wed Nov 29 2023
*
* This file is a part of Skytable
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
* NoSQL database written by Sayan Nandan ("the Author") with the
* vision to provide flexibility in data modelling without compromising
* on performance, queryability or scalability.
*
* Copyright (c) 2023, Sayan Nandan <ohsayan@outlook.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
macro_rules! assert_err_eq {
($me:expr, $target:pat) => {
match ::core::result::Result::unwrap_err($me) {
$target => {}
other => panic!(
"expected error `{}` but got {:?} at {}:{}",
stringify!($target),
other,
file!(),
line!()
),
}
};
}

@ -24,5 +24,7 @@
*
*/
#[macro_use]
mod macros;
mod cfg;
mod client;

@ -87,6 +87,7 @@ enum TestStrategy {
Standard,
Relogin { username: String, password: String },
}
impl TestStrategy {
fn is_relogin(&self) -> bool {
matches!(self, TestStrategy::Relogin { .. })

Loading…
Cancel
Save