Skip to content

Commit

Permalink
✅ add more Set tests
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse committed Apr 10, 2024
1 parent 1fd3128 commit c517b48
Showing 1 changed file with 212 additions and 0 deletions.
212 changes: 212 additions & 0 deletions test/unit/utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,32 @@ void main() {
Utils.merge(null, [42]),
equals([null, 42]),
);
expect(
Utils.merge(null, [42]),
isA<List>(),
);
});

test('merges null into a set', () {
expect(
Utils.merge(null, {'foo'}),
equals([null, 'foo']),
);
expect(
Utils.merge(null, {'foo'}),
isA<List>(),
);
});

test('merges String into set', () {
expect(
Utils.merge({'foo'}, 'bar'),
equals({'foo', 'bar'}),
);
expect(
Utils.merge({'foo'}, 'bar'),
isA<Set>(),
);
});

test('merges two objects with the same key', () {
Expand All @@ -283,6 +309,14 @@ void main() {
},
),
);
expect(
Utils.merge({'a': 'b'}, {'a': 'c'}),
contains('a'),
);
expect(
Utils.merge({'a': 'b'}, {'a': 'c'})['a'],
isA<List>(),
);
});

test('merges a standalone and an object into an list', () {
Expand Down Expand Up @@ -377,6 +411,17 @@ void main() {
},
),
);
expect(
Utils.merge(
{
'foo': ['baz']
},
{
'foo': ['bar', 'xyzzy']
},
),
contains('foo'),
);
expect(
Utils.merge(
{
Expand Down Expand Up @@ -415,6 +460,17 @@ void main() {
},
),
);
expect(
Utils.merge(
{
'foo': {'baz'}
},
{
'foo': {'bar', 'xyzzy'}
},
),
contains('foo'),
);
expect(
Utils.merge(
{
Expand Down Expand Up @@ -444,6 +500,17 @@ void main() {
},
),
);
expect(
Utils.merge(
{
'foo': ['baz']
},
{
'foo': {'bar'}
},
),
contains('foo'),
);
expect(
Utils.merge(
{
Expand Down Expand Up @@ -473,6 +540,17 @@ void main() {
},
),
);
expect(
Utils.merge(
{
'foo': {'baz'}
},
{
'foo': ['bar']
},
),
contains('foo'),
);
expect(
Utils.merge(
{
Expand Down Expand Up @@ -502,6 +580,17 @@ void main() {
},
),
);
expect(
Utils.merge(
{
'foo': ['baz']
},
{
'foo': {'bar', 'xyzzy'}
},
),
contains('foo'),
);
expect(
Utils.merge(
{
Expand Down Expand Up @@ -531,6 +620,17 @@ void main() {
},
),
);
expect(
Utils.merge(
{
'foo': ['bar']
},
{
'foo': {'baz': 'xyzzy'}
},
),
contains('foo'),
);
expect(
Utils.merge(
{
Expand Down Expand Up @@ -560,6 +660,16 @@ void main() {
},
),
);
expect(
Utils.merge(
{
'foo': {'bar': 'baz'}
},
{
'foo': ['xyzzy']
},
),
contains('foo'));
expect(
Utils.merge(
{
Expand Down Expand Up @@ -591,6 +701,17 @@ void main() {
},
),
);
expect(
Utils.merge(
{
'foo': {'bar'}
},
{
'foo': {undefined, 'baz'}
},
),
contains('foo'),
);
expect(
Utils.merge(
{
Expand Down Expand Up @@ -626,6 +747,97 @@ void main() {
{
'foo': {'baz'}
},
),
contains('foo'),
);
expect(
Utils.merge(
{
'foo': {undefined, 'bar'}
},
{
'foo': {'baz'}
},
)['foo'],
isA<Set>(),
);
});

test('merge set of Maps with another set of Maps', () {
expect(
Utils.merge(
{
{'bar': 'baz'}
},
{
{'baz': 'xyzzy'}
},
),
equals(
{
{'bar': 'baz', 'baz': 'xyzzy'},
},
),
);
expect(
Utils.merge(
{
{'bar': 'baz'}
},
{
{'baz': 'xyzzy'}
},
),
isA<Set>(),
);

expect(
Utils.merge(
{
'foo': {
{'bar': 'baz'}
}
},
{
'foo': {
{'baz': 'xyzzy'}
}
},
),
equals(
{
'foo': {
{'bar': 'baz', 'baz': 'xyzzy'},
},
},
),
);
expect(
Utils.merge(
{
'foo': {
{'bar': 'baz'}
}
},
{
'foo': {
{'baz': 'xyzzy'}
}
},
),
contains('foo'));
expect(
Utils.merge(
{
'foo': {
{'bar': 'baz'}
}
},
{
'foo': {
{'baz': 'xyzzy'}
}
},
)['foo'],
isA<Set>(),
);
Expand Down

0 comments on commit c517b48

Please sign in to comment.