2024-03-27 10:33:25 +08:00
|
|
|
import { MySQL } from 'src/parser/mysql';
|
2024-01-19 21:10:00 +08:00
|
|
|
import { readSQL } from 'test/helper';
|
2023-11-27 15:25:40 +08:00
|
|
|
|
2024-03-27 10:33:25 +08:00
|
|
|
const mysql = new MySQL();
|
2023-11-27 15:25:40 +08:00
|
|
|
|
|
|
|
const features = {
|
|
|
|
alterDatabase: readSQL(__dirname, 'alterDatabase.sql'),
|
|
|
|
alterEvent: readSQL(__dirname, 'alterEvent.sql'),
|
|
|
|
alterFunction: readSQL(__dirname, 'alterFunction.sql'),
|
|
|
|
alterInstance: readSQL(__dirname, 'alterInstance.sql'),
|
|
|
|
alterLogFileGroup: readSQL(__dirname, 'alterLogFileGroup.sql'),
|
|
|
|
alterProcedure: readSQL(__dirname, 'alterProcedure.sql'),
|
|
|
|
alterServer: readSQL(__dirname, 'alterServer.sql'),
|
|
|
|
alterTable: readSQL(__dirname, 'alterTable.sql'),
|
|
|
|
alterTableAndGeneratedColumns: readSQL(__dirname, 'alterTableAndGeneratedColumns.sql'),
|
|
|
|
alterTablePartition: readSQL(__dirname, 'alterTablePartition.sql'),
|
|
|
|
alterTableSpace: readSQL(__dirname, 'alterTableSpace.sql'),
|
|
|
|
alterView: readSQL(__dirname, 'alterView.sql'),
|
|
|
|
createDatabase: readSQL(__dirname, 'createDatabase.sql'),
|
|
|
|
createEvent: readSQL(__dirname, 'createEvent.sql'),
|
|
|
|
createFunction: readSQL(__dirname, 'createFunction.sql'),
|
|
|
|
createIndex: readSQL(__dirname, 'createIndex.sql'),
|
|
|
|
createLogFileGroup: readSQL(__dirname, 'createLogFileGroup.sql'),
|
|
|
|
createProcedure: readSQL(__dirname, 'createProcedure.sql'),
|
|
|
|
createServer: readSQL(__dirname, 'createServer.sql'),
|
|
|
|
createTable: readSQL(__dirname, 'createTable.sql'),
|
|
|
|
createTableSpace: readSQL(__dirname, 'createTableSpace.sql'),
|
|
|
|
createTrigger: readSQL(__dirname, 'createTrigger.sql'),
|
|
|
|
createView: readSQL(__dirname, 'createView.sql'),
|
|
|
|
dropDatabase: readSQL(__dirname, 'dropDatabase.sql'),
|
|
|
|
dropEvent: readSQL(__dirname, 'dropEvent.sql'),
|
|
|
|
dropFunction: readSQL(__dirname, 'dropFunction.sql'),
|
|
|
|
dropIndex: readSQL(__dirname, 'dropIndex.sql'),
|
|
|
|
dropLogFileGroup: readSQL(__dirname, 'dropLogFileGroup.sql'),
|
|
|
|
dropProcedure: readSQL(__dirname, 'dropProcedure.sql'),
|
|
|
|
dropServer: readSQL(__dirname, 'dropServer.sql'),
|
|
|
|
dropSpatialReferenceSystem: readSQL(__dirname, 'dropSpatialReferenceSystem.sql'),
|
|
|
|
dropTable: readSQL(__dirname, 'dropTable.sql'),
|
|
|
|
dropTableSpace: readSQL(__dirname, 'dropTableSpace.sql'),
|
|
|
|
dropTrigger: readSQL(__dirname, 'dropTrigger.sql'),
|
|
|
|
dropView: readSQL(__dirname, 'dropView.sql'),
|
|
|
|
renameTable: readSQL(__dirname, 'renameTable.sql'),
|
|
|
|
truncateTable: readSQL(__dirname, 'truncateTable.sql'),
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('MySQL DDL Syntax Tests', () => {
|
|
|
|
Object.keys(features).forEach((key) => {
|
|
|
|
features[key].forEach((sql) => {
|
|
|
|
it(sql, () => {
|
2024-03-27 10:33:25 +08:00
|
|
|
const result = mysql.validate(sql);
|
2023-11-27 15:25:40 +08:00
|
|
|
if (result.length) {
|
2024-02-26 20:25:09 +08:00
|
|
|
console.error(result, `\nPlease check sql: ${sql}`);
|
2023-11-27 15:25:40 +08:00
|
|
|
}
|
|
|
|
expect(result.length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|