Skip to content

Commit

Permalink
Condition match tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmpassos committed Oct 3, 2021
1 parent 27e4535 commit bcb8ffe
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions test/bones_api_condition_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,97 @@ void main() {
}
});
});

group('Condition match', () {
test('KeyConditionEQ', () {
expect(
KeyConditionEQ([ConditionKeyField('foo')], 123)
.matchesEntity({'foo': 123}),
isTrue);

expect(
KeyConditionEQ([ConditionKeyField('foo')], 123)
.matchesEntity({'foo': 456}),
isFalse);
});

test('KeyConditionNotEQ', () {
expect(
KeyConditionNotEQ([ConditionKeyField('foo')], 123)
.matchesEntity({'foo': 123}),
isFalse);

expect(
KeyConditionNotEQ([ConditionKeyField('foo')], 123)
.matchesEntity({'foo': 456}),
isTrue);
});

test('KeyConditionIN', () {
var conditionIN = KeyConditionIN([ConditionKeyField('foo')], [1, 2, 3]);

expect(conditionIN.matchesEntity({'foo': 1}), isTrue);
expect(conditionIN.matchesEntity({'foo': 2}), isTrue);
expect(conditionIN.matchesEntity({'foo': 3}), isTrue);
expect(conditionIN.matchesEntity({'foo': 4}), isFalse);
});

test('KeyConditionNotIN', () {
var conditionIN =
KeyConditionNotIN([ConditionKeyField('foo')], [1, 2, 3]);

expect(conditionIN.matchesEntity({'foo': 1}), isFalse);
expect(conditionIN.matchesEntity({'foo': 2}), isFalse);
expect(conditionIN.matchesEntity({'foo': 3}), isFalse);
expect(conditionIN.matchesEntity({'foo': 4}), isTrue);
});

test('GroupConditionAND', () {
expect(
GroupConditionAND([
KeyConditionEQ([ConditionKeyField('foo')], 123),
KeyConditionEQ([ConditionKeyField('bar')], 456),
]).matchesEntity({'foo': 123, 'bar': 456}),
isTrue);

expect(
GroupConditionAND([
KeyConditionEQ([ConditionKeyField('foo')], 123),
KeyConditionEQ([ConditionKeyField('bar')], 456),
]).matchesEntity({'foo': 123, 'bar': 654}),
isFalse);

expect(
GroupConditionAND([
KeyConditionEQ([ConditionKeyField('foo')], 123),
KeyConditionEQ([ConditionKeyField('bar')], 456),
]).matchesEntity({'foo': 321, 'bar': 654}),
isFalse);
});

test('GroupConditionOR', () {
expect(
GroupConditionOR([
KeyConditionEQ([ConditionKeyField('foo')], 123),
KeyConditionEQ([ConditionKeyField('bar')], 456),
]).matchesEntity({'foo': 123, 'bar': 456}),
isTrue);

expect(
GroupConditionOR([
KeyConditionEQ([ConditionKeyField('foo')], 123),
KeyConditionEQ([ConditionKeyField('bar')], 456),
]).matchesEntity({'foo': 123, 'bar': 654}),
isTrue);

expect(
GroupConditionOR([
KeyConditionEQ([ConditionKeyField('foo')], 123),
KeyConditionEQ([ConditionKeyField('bar')], 456),
]).matchesEntity({'foo': 321, 'bar': 654}),
isFalse);
});
});
}

class _TestSchemeProvider extends SchemeProvider {
Expand Down

0 comments on commit bcb8ffe

Please sign in to comment.