Fix errors in parsing crate

This commit is contained in:
Yuriy Dupyn 2024-02-01 14:45:29 +01:00
parent 339686f5c5
commit fbd7bf1f72
2 changed files with 34 additions and 36 deletions

View file

@ -105,7 +105,7 @@ fn validate_table_schema(raw_table_schema: RawTableSchema) -> Result<TableSchema
} in raw_table_schema.columns
{
if is_primary {
primary_keys.push((column_name.clone(), type_))
primary_keys.push((column_name.clone(), type_.clone()))
}
columns.push(column_name);
types.push(type_);
@ -355,9 +355,7 @@ mod tests {
use minisql::type_system::{IndexableValue, Value};
use Condition::*;
use IndexableValue::*;
use RawQuerySyntax::*;
use Value::*;
fn users_schema() -> TableSchema {
TableSchema::new(
@ -567,7 +565,7 @@ mod tests {
let syntax: RawQuerySyntax = Select(
"users".to_string(),
ColumnSelection::All,
Some(Eq("age".to_string(), Indexable(Int(25)))),
Some(Eq("age".to_string(), Value::Int(25))),
);
let result = validate_operation(syntax, &db_schema);
assert!(matches!(result, Ok(Operation::Select(_, _, _))));
@ -579,7 +577,7 @@ mod tests {
assert!(table_position == users_position);
assert!(column_selection == vec![id, name, age]);
assert!(condition == Some(operation::Condition::Eq(age, Indexable(Int(25)))));
assert!(condition == Some(operation::Condition::Eq(age, Value::Int(25))));
}
#[test]
@ -634,7 +632,7 @@ mod tests {
let syntax: RawQuerySyntax = Select(
"users".to_string(),
ColumnSelection::All,
Some(Eq("does_not_exist".to_string(), Indexable(Int(25)))),
Some(Eq("does_not_exist".to_string(), Value::Int(25))),
);
let result = validate_operation(syntax, &db_schema);
assert!(matches!(result, Err(ValidationError::ColumnsDoNotExist(_))));
@ -648,7 +646,7 @@ mod tests {
let syntax: RawQuerySyntax = Select(
"users".to_string(),
ColumnSelection::All,
Some(Eq("age".to_string(), Indexable(String("25".to_string())))),
Some(Eq("age".to_string(), Value::String("25".to_string()))),
);
let result = validate_operation(syntax, &db_schema);
assert!(matches!(result, Err(ValidationError::TypeMismatch { .. })));
@ -665,9 +663,9 @@ mod tests {
let syntax: RawQuerySyntax = Insert(
"users".to_string(),
vec![
("name".to_string(), Indexable(String("Alice".to_string()))),
("id".to_string(), Indexable(Uuid(0))),
("age".to_string(), Indexable(Int(25))),
("name".to_string(), Value::String("Alice".to_string())),
("id".to_string(), Value::Uuid(0)),
("age".to_string(), Value::Int(25)),
],
);
let result = validate_operation(syntax, &db_schema);
@ -685,9 +683,9 @@ mod tests {
assert!(
values
== vec![
Indexable(Uuid(0)),
Indexable(String("Alice".to_string())),
Indexable(Int(25))
Value::Uuid(0),
Value::String("Alice".to_string()),
Value::Int(25)
]
);
}
@ -700,10 +698,10 @@ mod tests {
let syntax: RawQuerySyntax = Insert(
"users".to_string(),
vec![
("name".to_string(), Indexable(String("Alice".to_string()))),
("id".to_string(), Indexable(Uuid(0))),
("age".to_string(), Indexable(Int(25))),
("does_not_exist".to_string(), Indexable(Int(25))),
("name".to_string(), Value::String("Alice".to_string())),
("id".to_string(), Value::Uuid(0)),
("age".to_string(), Value::Int(25)),
("does_not_exist".to_string(), Value::Int(25)),
],
);
let result = validate_operation(syntax, &db_schema);
@ -718,9 +716,9 @@ mod tests {
let syntax: RawQuerySyntax = Insert(
"users".to_string(),
vec![
("name".to_string(), Indexable(String("Alice".to_string()))),
("id".to_string(), Indexable(Uuid(0))),
("age".to_string(), Number(25.0)),
("name".to_string(), Value::String("Alice".to_string())),
("id".to_string(), Value::Uuid(0)),
("age".to_string(), Value::Number(25.0)),
],
);
let result = validate_operation(syntax, &db_schema);
@ -756,7 +754,7 @@ mod tests {
let syntax: RawQuerySyntax = Delete(
"users".to_string(),
Some(Eq("age".to_string(), Indexable(Int(25)))),
Some(Eq("age".to_string(), Value::Int(25))),
);
let result = validate_operation(syntax, &db_schema);
assert!(matches!(
@ -772,7 +770,7 @@ mod tests {
assert!(table_position == users_position);
assert!(column == age);
assert!(value == Indexable(Int(25)));
assert!(value == Value::Int(25));
}
// ====CreateIndex====