Add tests

This commit is contained in:
Simon Binder 2022-07-04 19:57:04 +02:00
parent 8c46388563
commit 1826311ec2
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 19 additions and 13 deletions

View File

@ -3,7 +3,7 @@ import 'package:test/test.dart';
import '../../test_utils/test_utils.dart';
typedef _Extractor = Expression<int?> Function(Expression<DateTime?> d);
typedef _Extractor = Expression Function(Expression<DateTime?> d);
void main() {
const column =
@ -17,15 +17,14 @@ void main() {
(d) => d.hour: "CAST(strftime('%H', val, 'unixepoch') AS INTEGER)",
(d) => d.minute: "CAST(strftime('%M', val, 'unixepoch') AS INTEGER)",
(d) => d.second: "CAST(strftime('%S', val, 'unixepoch') AS INTEGER)",
(d) => d.date: "DATE(val, 'unixepoch')",
(d) => d.datetime: "DATETIME(val, 'unixepoch')",
(d) => d.time: "TIME(val, 'unixepoch')",
};
expectedResults.forEach((key, value) {
test('should extract field', () {
final ctx = GenerationContext(SqlTypeSystem.defaultInstance, null);
key(column).writeInto(ctx);
expect(ctx.sql, value);
expect(key(column), generates(value));
expectEquals(key(column), key(column));
});
});

View File

@ -37,11 +37,19 @@ void main() {
const Duration(days: 1).inSeconds);
});
test('datetime.date format', () {
final expr = Variable.withDateTime(DateTime(2020, 09, 04, 8, 55));
final asDate = expr.date;
test('extracting values from datetime', () {
final expr = Variable.withDateTime(DateTime.utc(2020, 09, 04, 8, 55));
expect(eval(asDate), completion('2020-09-04'));
expect(eval(expr.year), completion(2020));
expect(eval(expr.month), completion(9));
expect(eval(expr.day), completion(4));
expect(eval(expr.hour), completion(8));
expect(eval(expr.minute), completion(55));
expect(eval(expr.second), completion(0));
expect(eval(expr.date), completion('2020-09-04'));
expect(eval(expr.time), completion('08:55:00'));
expect(eval(expr.datetime), completion('2020-09-04 08:55:00'));
});
test('rowid', () {

View File

@ -13,9 +13,8 @@ void expectNotEquals(dynamic a, dynamic expected) {
/// Matcher for [Component]-subclasses. Expect that a component generates the
/// matching [sql] and, optionally, the matching [variables].
Matcher generates(dynamic sql, [dynamic variables]) {
final variablesMatcher = variables != null ? wrapMatcher(variables) : isEmpty;
return _GeneratesSqlMatcher(wrapMatcher(sql), variablesMatcher);
Matcher generates(dynamic sql, [dynamic variables = isEmpty]) {
return _GeneratesSqlMatcher(wrapMatcher(sql), wrapMatcher(variables));
}
class _GeneratesSqlMatcher extends Matcher {