51 lines
1.4 KiB
Dart
51 lines
1.4 KiB
Dart
|
|
import 'package:flutter_test/flutter_test.dart';
|
||
|
|
import 'package:halkyon_app/halkyon_app.dart';
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
test('reads an address as people type it, HTTPS unless they say not', () {
|
||
|
|
for (final address in [
|
||
|
|
'learn.example.org',
|
||
|
|
'https://learn.example.org',
|
||
|
|
' HTTPS://Learn.Example.org/ ',
|
||
|
|
]) {
|
||
|
|
expect(
|
||
|
|
Instance.parse(address)?.url,
|
||
|
|
Uri.parse('https://learn.example.org/'),
|
||
|
|
reason: address,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
expect(
|
||
|
|
Instance.parse('http://localhost:8080')?.url,
|
||
|
|
Uri.parse('http://localhost:8080/'),
|
||
|
|
);
|
||
|
|
expect(
|
||
|
|
Instance.parse('example.org/learn?x=1#top')?.url,
|
||
|
|
Uri.parse('https://example.org/learn/'),
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('refuses what is no address', () {
|
||
|
|
for (final address in [
|
||
|
|
'',
|
||
|
|
' ',
|
||
|
|
'learn example org',
|
||
|
|
'ftp://example.org',
|
||
|
|
'https://',
|
||
|
|
'https://someone@example.org',
|
||
|
|
]) {
|
||
|
|
expect(Instance.parse(address), isNull, reason: address);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('is named by its host, and its port if it has one', () {
|
||
|
|
expect(Instance.parse('learn.halkyon.eu')!.name, 'learn.halkyon.eu');
|
||
|
|
expect(Instance.parse('localhost:8080')!.name, 'localhost:8080');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('is the same instance however its address was written', () {
|
||
|
|
expect(
|
||
|
|
Instance.parse('learn.example.org'),
|
||
|
|
Instance.parse('https://LEARN.example.org/'),
|
||
|
|
);
|
||
|
|
});
|
||
|
|
}
|