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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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