2019-09-16 13:33:36 -07:00
|
|
|
import 'package:sqlparser/sqlparser.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
2019-09-18 12:36:25 -07:00
|
|
|
import 'utils.dart';
|
|
|
|
|
2019-09-16 13:33:36 -07:00
|
|
|
const content = r'''
|
|
|
|
import 'other.dart';
|
|
|
|
import 'another.moor';
|
|
|
|
|
|
|
|
CREATE TABLE tbl (
|
|
|
|
id INT NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
|
|
-- this is a single-line comment
|
|
|
|
place VARCHAR REFERENCES other(location)
|
2019-09-17 06:23:24 -07:00
|
|
|
) AS RowName
|
2019-09-16 13:33:36 -07:00
|
|
|
|
|
|
|
all: SELECT /* COUNT(*), */ * FROM tbl WHERE $predicate;
|
|
|
|
''';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
test('parses moor files', () {
|
2019-10-27 03:51:09 -07:00
|
|
|
testMoorFile(
|
|
|
|
content,
|
2019-09-16 13:33:36 -07:00
|
|
|
MoorFile([
|
|
|
|
ImportStatement('other.dart'),
|
|
|
|
ImportStatement('another.moor'),
|
|
|
|
CreateTableStatement(
|
|
|
|
tableName: 'tbl',
|
|
|
|
columns: [
|
|
|
|
ColumnDefinition(
|
|
|
|
columnName: 'id',
|
|
|
|
typeName: 'INT',
|
|
|
|
constraints: [
|
|
|
|
NotNull(null),
|
|
|
|
PrimaryKeyColumn(null, autoIncrement: true),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
ColumnDefinition(
|
|
|
|
columnName: 'place',
|
|
|
|
typeName: 'VARCHAR',
|
|
|
|
constraints: [
|
|
|
|
ForeignKeyColumnConstraint(
|
|
|
|
null,
|
|
|
|
ForeignKeyClause(
|
|
|
|
foreignTable: TableReference('other', null),
|
|
|
|
columnNames: [
|
|
|
|
Reference(columnName: 'location'),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
2019-09-17 06:23:24 -07:00
|
|
|
overriddenDataClassName: 'RowName',
|
2019-09-16 13:33:36 -07:00
|
|
|
),
|
|
|
|
DeclaredStatement(
|
|
|
|
'all',
|
|
|
|
SelectStatement(
|
|
|
|
columns: [StarResultColumn(null)],
|
|
|
|
from: [TableReference('tbl', null)],
|
|
|
|
where: DartExpressionPlaceholder(name: 'predicate'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|