Files
notion-sql/tests/sql.rs
T
james.maes fb10ae20c3 feat: Implement v1.0.0 release with comprehensive audit fixes
- Fix clippy warnings in test code by adding #[allow(dead_code)]
- Move all unit tests from source files to tests/ directory
- Add integration tests for SQL parsing and schema operations
- Create examples directory with 5 SQL query examples
- Add Windows CI job to ci.yml for cross-platform coverage
- Update Cargo.toml with documentation and readme fields
- Add comprehensive clean room audit documentation

All 39 tests passing, clippy clean, formatting verified
2026-06-02 13:12:50 -05:00

78 lines
2.1 KiB
Rust

//! Tests for parsing supported SQL into the local statement model.
use notion_sql::sql::{parse_statement, SelectColumns, SqlStatement};
#[test]
fn parses_select_statement() {
let parsed = parse_statement(
"SELECT Name, Status FROM Tasks WHERE Status = 'Done' ORDER BY Name DESC LIMIT 5",
)
.unwrap();
match parsed {
SqlStatement::Select {
database,
columns,
sorts,
limit,
..
} => {
assert_eq!(database, "Tasks");
assert_eq!(
columns,
SelectColumns::Columns(vec!["Name".to_string(), "Status".to_string()])
);
assert_eq!(
sorts,
vec![notion_sql::sql::SortSpec {
column: "Name".to_string(),
ascending: false
}]
);
assert_eq!(limit, Some(5));
}
other => panic!("unexpected statement: {other:?}"),
}
}
#[test]
fn parses_insert_values() {
let parsed =
parse_statement("INSERT INTO Tasks (Name, Status) VALUES ('New task', 'To Do')").unwrap();
match parsed {
SqlStatement::Insert {
database,
columns,
rows,
} => {
assert_eq!(database, "Tasks");
assert_eq!(columns, vec!["Name".to_string(), "Status".to_string()]);
assert_eq!(rows.len(), 1);
}
other => panic!("unexpected statement: {other:?}"),
}
}
#[test]
fn parses_count_projection() {
let parsed = parse_statement("SELECT COUNT(*) FROM Tasks WHERE Status = 'Done'").unwrap();
match parsed {
SqlStatement::Select {
database, columns, ..
} => {
assert_eq!(database, "Tasks");
assert_eq!(columns, SelectColumns::Count);
}
other => panic!("unexpected statement: {other:?}"),
}
}
#[test]
fn rejects_unsupported_count_projection() {
let error = parse_statement("SELECT COUNT(Name) FROM Tasks").unwrap_err();
assert!(error.to_string().contains("Only COUNT(*) and COUNT(1)"));
}