mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-03 13:58:15 +00:00
Introduce tests/test_utils/mod.rs and use it consistently
To share helper macros between various tests/* we added a new module (tests/macros/mod.rs). This made the prologue to be used in tests quite long and a little weird: ``` #[macro_use] #[path = "macros/mod.rs"] mod macros; use sqlparser::test_utils::*; ``` This simplifies it to: ``` #[macro_use] mod test_utils; use test_utils::*; ``` - and switches all existing tests to the new prologue simultaneously... ...while fixing a few other inconsistencies and adding a few comments about the way `test_utils` work.
This commit is contained in:
parent
99fb633221
commit
4128dfe1db
10 changed files with 48 additions and 12 deletions
|
@ -19,14 +19,13 @@
|
|||
//! dialect-specific parsing rules).
|
||||
|
||||
#[macro_use]
|
||||
#[path = "macros/mod.rs"]
|
||||
mod macros;
|
||||
mod test_utils;
|
||||
use test_utils::{all_dialects, expr_from_projection, join, number, only, table};
|
||||
|
||||
use matches::assert_matches;
|
||||
use sqlparser::ast::*;
|
||||
use sqlparser::dialect::keywords::ALL_KEYWORDS;
|
||||
use sqlparser::parser::ParserError;
|
||||
use sqlparser::test_utils::{all_dialects, expr_from_projection, join, number, only, table};
|
||||
|
||||
#[test]
|
||||
fn parse_insert_values() {
|
||||
|
|
|
@ -14,9 +14,12 @@
|
|||
//! Test SQL syntax specific to Microsoft's T-SQL. The parser based on the
|
||||
//! generic dialect is also tested (on the inputs it can handle).
|
||||
|
||||
#[macro_use]
|
||||
mod test_utils;
|
||||
use test_utils::*;
|
||||
|
||||
use sqlparser::ast::*;
|
||||
use sqlparser::dialect::{GenericDialect, MsSqlDialect};
|
||||
use sqlparser::test_utils::*;
|
||||
|
||||
#[test]
|
||||
fn parse_mssql_identifiers() {
|
||||
|
|
|
@ -11,13 +11,15 @@
|
|||
// limitations under the License.
|
||||
|
||||
#![warn(clippy::all)]
|
||||
|
||||
//! Test SQL syntax specific to MySQL. The parser based on the generic dialect
|
||||
//! is also tested (on the inputs it can handle).
|
||||
|
||||
#[macro_use]
|
||||
mod test_utils;
|
||||
use test_utils::*;
|
||||
|
||||
use sqlparser::ast::*;
|
||||
use sqlparser::dialect::{GenericDialect, MySqlDialect};
|
||||
use sqlparser::test_utils::*;
|
||||
use sqlparser::tokenizer::Token;
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -14,10 +14,13 @@
|
|||
//! Test SQL syntax specific to PostgreSQL. The parser based on the
|
||||
//! generic dialect is also tested (on the inputs it can handle).
|
||||
|
||||
#[macro_use]
|
||||
mod test_utils;
|
||||
use test_utils::*;
|
||||
|
||||
use sqlparser::ast::*;
|
||||
use sqlparser::dialect::{GenericDialect, PostgreSqlDialect};
|
||||
use sqlparser::parser::ParserError;
|
||||
use sqlparser::test_utils::*;
|
||||
|
||||
#[test]
|
||||
fn parse_create_table_with_defaults() {
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![warn(clippy::all)]
|
||||
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
use sqlparser::parser::Parser;
|
||||
|
||||
|
|
|
@ -10,11 +10,14 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#[macro_use]
|
||||
#[path = "macros/mod.rs"]
|
||||
mod macros;
|
||||
#![warn(clippy::all)]
|
||||
//! Test SQL syntax specific to Snowflake. The parser based on the
|
||||
//! generic dialect is also tested (on the inputs it can handle).
|
||||
|
||||
#[macro_use]
|
||||
mod test_utils;
|
||||
use test_utils::*;
|
||||
|
||||
use sqlparser::test_utils::*;
|
||||
use sqlparser::ast::*;
|
||||
use sqlparser::dialect::{GenericDialect, SnowflakeDialect};
|
||||
use sqlparser::tokenizer::*;
|
||||
|
|
|
@ -14,9 +14,12 @@
|
|||
//! Test SQL syntax specific to SQLite. The parser based on the
|
||||
//! generic dialect is also tested (on the inputs it can handle).
|
||||
|
||||
#[macro_use]
|
||||
mod test_utils;
|
||||
use test_utils::*;
|
||||
|
||||
use sqlparser::ast::*;
|
||||
use sqlparser::dialect::{GenericDialect, SQLiteDialect};
|
||||
use sqlparser::test_utils::*;
|
||||
use sqlparser::tokenizer::Token;
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -10,6 +10,20 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Re-export everything from `src/test_utils.rs`.
|
||||
pub use sqlparser::test_utils::*;
|
||||
|
||||
// For the test-only macros we take a different approach of keeping them here
|
||||
// rather than in the library crate.
|
||||
//
|
||||
// This is because we don't need any of them to be shared between the
|
||||
// integration tests (i.e. `tests/*`) and the unit tests (i.e. `src/*`),
|
||||
// but also because Rust doesn't scope macros to a particular module
|
||||
// (and while we export internal helpers as sqlparser::test_utils::<...>,
|
||||
// expecting our users to abstain from relying on them, exporting internal
|
||||
// macros at the top level, like `sqlparser::nest` was deemed too confusing).
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! nest {
|
||||
($base:expr $(, $join:expr)*) => {
|
||||
TableFactor::NestedJoin(Box::new(TableWithJoins {
|
Loading…
Add table
Add a link
Reference in a new issue