refactor: port some simple tests to nullsafety

This commit is contained in:
Nicolas Werner 2021-10-28 02:05:28 +02:00
parent 6abd9e7e22
commit 2fd4425099
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
9 changed files with 29 additions and 40 deletions

View File

@ -1,4 +1,3 @@
// @dart=2.9
/*
* Famedly Matrix SDK
* Copyright (C) 2021 Famedly GmbH
@ -23,9 +22,9 @@ import 'fake_client.dart';
void main() {
group('Image Pack', () {
Client client;
Room room;
Room room2;
late Client client;
late Room room;
late Room room2;
test('setupClient', () async {
client = await getClient();
@ -36,7 +35,7 @@ void main() {
content: {},
room: room,
stateKey: '',
senderId: client.userID,
senderId: client.userID!,
eventId: '\$fakeid1:fakeServer.notExisting',
originServerTs: DateTime.now(),
));
@ -54,7 +53,7 @@ void main() {
content: {},
room: room,
stateKey: '',
senderId: client.userID,
senderId: client.userID!,
eventId: '\$fakeid3:fakeServer.notExisting',
originServerTs: DateTime.now(),
));
@ -87,8 +86,8 @@ void main() {
));
final packs = room.getImagePacks();
expect(packs.length, 1);
expect(packs['room'].images.length, 1);
expect(packs['room'].images['room_plain'].url.toString(),
expect(packs['room']?.images.length, 1);
expect(packs['room']?.images['room_plain']?.url.toString(),
'mxc://room_plain');
var packsFlat = room.getImagePacksFlat();
expect(packsFlat, {

View File

@ -1,4 +1,3 @@
// @dart=2.9
/*
* Famedly Matrix SDK
* Copyright (C) 2019, 2020 Famedly GmbH

View File

@ -1,4 +1,3 @@
// @dart=2.9
/*
* Famedly Matrix SDK
* Copyright (C) 2019, 2020 Famedly GmbH

View File

@ -1,4 +1,3 @@
// @dart=2.9
/*
* Famedly Matrix SDK
* Copyright (C) 2019, 2020 Famedly GmbH
@ -48,77 +47,73 @@ void main() {
expect('@user:domain:8448'.domain, 'domain:8448');
});
test('parseIdentifierIntoParts', () {
var res = '#alias:beep'.parseIdentifierIntoParts();
var res = '#alias:beep'.parseIdentifierIntoParts()!;
expect(res.primaryIdentifier, '#alias:beep');
expect(res.secondaryIdentifier, null);
expect(res.queryString, null);
res = 'blha'.parseIdentifierIntoParts();
expect(res, null);
res = '#alias:beep/\$event'.parseIdentifierIntoParts();
expect('blha'.parseIdentifierIntoParts(), null);
res = '#alias:beep/\$event'.parseIdentifierIntoParts()!;
expect(res.primaryIdentifier, '#alias:beep');
expect(res.secondaryIdentifier, '\$event');
expect(res.queryString, null);
res = '#alias:beep?blubb'.parseIdentifierIntoParts();
res = '#alias:beep?blubb'.parseIdentifierIntoParts()!;
expect(res.primaryIdentifier, '#alias:beep');
expect(res.secondaryIdentifier, null);
expect(res.queryString, 'blubb');
res = '#alias:beep/\$event?blubb'.parseIdentifierIntoParts();
res = '#alias:beep/\$event?blubb'.parseIdentifierIntoParts()!;
expect(res.primaryIdentifier, '#alias:beep');
expect(res.secondaryIdentifier, '\$event');
expect(res.queryString, 'blubb');
res = '#/\$?:beep/\$event?blubb?b'.parseIdentifierIntoParts();
res = '#/\$?:beep/\$event?blubb?b'.parseIdentifierIntoParts()!;
expect(res.primaryIdentifier, '#/\$?:beep');
expect(res.secondaryIdentifier, '\$event');
expect(res.queryString, 'blubb?b');
res = 'https://matrix.to/#/#alias:beep'.parseIdentifierIntoParts();
res = 'https://matrix.to/#/#alias:beep'.parseIdentifierIntoParts()!;
expect(res.primaryIdentifier, '#alias:beep');
expect(res.secondaryIdentifier, null);
expect(res.queryString, null);
res = 'https://matrix.to/#/#🦊:beep'.parseIdentifierIntoParts();
res = 'https://matrix.to/#/#🦊:beep'.parseIdentifierIntoParts()!;
expect(res.primaryIdentifier, '#🦊:beep');
expect(res.secondaryIdentifier, null);
expect(res.queryString, null);
res = 'https://matrix.to/#/%23alias%3abeep'.parseIdentifierIntoParts();
res = 'https://matrix.to/#/%23alias%3abeep'.parseIdentifierIntoParts()!;
expect(res.primaryIdentifier, '#alias:beep');
expect(res.secondaryIdentifier, null);
expect(res.queryString, null);
res = 'https://matrix.to/#/%23alias%3abeep?boop%F0%9F%A7%A1%F0%9F%A6%8A'
.parseIdentifierIntoParts();
.parseIdentifierIntoParts()!;
expect(res.primaryIdentifier, '#alias:beep');
expect(res.secondaryIdentifier, null);
expect(res.queryString, 'boop%F0%9F%A7%A1%F0%9F%A6%8A');
res = 'https://matrix.to/#/#alias:beep?via=fox.com&via=fox.org'
.parseIdentifierIntoParts();
.parseIdentifierIntoParts()!;
expect(res.via, <String>{'fox.com', 'fox.org'});
res = 'matrix:u/her:example.org'.parseIdentifierIntoParts();
res = 'matrix:u/her:example.org'.parseIdentifierIntoParts()!;
expect(res.primaryIdentifier, '@her:example.org');
expect(res.secondaryIdentifier, null);
res = 'matrix:u/bad'.parseIdentifierIntoParts();
expect(res, null);
res = 'matrix:roomid/rid:example.org'.parseIdentifierIntoParts();
expect('matrix:u/bad'.parseIdentifierIntoParts(), null);
res = 'matrix:roomid/rid:example.org'.parseIdentifierIntoParts()!;
expect(res.primaryIdentifier, '!rid:example.org');
expect(res.secondaryIdentifier, null);
expect(res.action, null);
res = 'matrix:r/us:example.org?action=chat'.parseIdentifierIntoParts();
res = 'matrix:r/us:example.org?action=chat'.parseIdentifierIntoParts()!;
expect(res.primaryIdentifier, '#us:example.org');
expect(res.secondaryIdentifier, null);
expect(res.action, 'chat');
res = 'matrix:r/us:example.org/e/lol823y4bcp3qo4'
.parseIdentifierIntoParts();
.parseIdentifierIntoParts()!;
expect(res.primaryIdentifier, '#us:example.org');
expect(res.secondaryIdentifier, '\$lol823y4bcp3qo4');
res = 'matrix:roomid/rid:example.org?via=fox.com&via=fox.org'
.parseIdentifierIntoParts();
.parseIdentifierIntoParts()!;
expect(res.primaryIdentifier, '!rid:example.org');
expect(res.secondaryIdentifier, null);
expect(res.via, <String>{'fox.com', 'fox.org'});
res = 'matrix:beep/boop:example.org'.parseIdentifierIntoParts();
expect(res, null);
res = 'matrix:boop'.parseIdentifierIntoParts();
expect(res, null);
expect('matrix:beep/boop:example.org'.parseIdentifierIntoParts(), null);
expect('matrix:boop'.parseIdentifierIntoParts(), null);
});
});
}

View File

@ -1,4 +1,3 @@
// @dart=2.9
/*
* Famedly Matrix SDK
* Copyright (C) 2021 Famedly GmbH

View File

@ -1,4 +1,3 @@
// @dart=2.9
/*
* Famedly Matrix SDK
* Copyright (C) 2019, 2020 Famedly GmbH

View File

@ -1,4 +1,3 @@
// @dart=2.9
/*
* Famedly Matrix SDK
* Copyright (C) 2020 Famedly GmbH
@ -119,6 +118,7 @@ const updates = {
'events': [
{
'type': 'beep',
'sender': '@example:localhost',
'content': {
'blah': 'blubb',
},

View File

@ -1,4 +1,3 @@
// @dart=2.9
/*
* Famedly Matrix SDK
* Copyright (C) 2020 Famedly GmbH

View File

@ -1,4 +1,3 @@
// @dart=2.9
/*
* Famedly Matrix SDK
* Copyright (C) 2019, 2020 Famedly GmbH
@ -123,6 +122,7 @@ void main() {
});
test('getPresence', () async {
await client.handleSync(SyncUpdate.fromJson({
'next_batch': 'fake',
'presence': {
'events': [
{
@ -133,7 +133,7 @@ void main() {
]
}
}));
expect(user1.presence.presence.presence, PresenceType.online);
expect(user1.presence?.presence.presence, PresenceType.online);
});
test('canBan', () async {
expect(user1.canBan, false);