2020-11-29 20:07:46 +00:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
|
2021-08-18 09:36:40 +00:00
|
|
|
import 'package:selfprivacy/utils/password_generator.dart';
|
2020-11-29 20:07:46 +00:00
|
|
|
|
|
|
|
void main() {
|
2021-08-18 09:36:40 +00:00
|
|
|
group('StringGenerators', () {
|
|
|
|
group('Basic', () {
|
|
|
|
test('assert chart empty', () {
|
|
|
|
expect(() {
|
|
|
|
StringGenerators.getRandomString(8);
|
2022-06-05 19:36:32 +00:00
|
|
|
}, throwsAssertionError,);
|
2021-08-18 09:36:40 +00:00
|
|
|
});
|
2020-11-29 20:07:46 +00:00
|
|
|
|
2021-08-18 09:36:40 +00:00
|
|
|
test('only lowercase string', () {
|
2022-06-05 19:36:32 +00:00
|
|
|
const int length = 8;
|
|
|
|
final String generatedString =
|
2021-08-18 09:36:40 +00:00
|
|
|
StringGenerators.getRandomString(length, hasLowercaseLetters: true);
|
2020-11-29 20:07:46 +00:00
|
|
|
|
2021-08-18 09:36:40 +00:00
|
|
|
expect(generatedString, isNot(matches(regExpNewLines)));
|
|
|
|
expect(generatedString, isNot(matches(regExpWhiteSpaces)));
|
|
|
|
expect(generatedString, isNot(matches(regExpNumbers)));
|
|
|
|
expect(generatedString, isNot(matches(regExpUppercaseLetters)));
|
|
|
|
expect(generatedString, isNot(matches(regExpSymbols)));
|
|
|
|
expect(generatedString.length, equals(length));
|
|
|
|
expect(generatedString, matches(regExpLowercaseLetters));
|
|
|
|
});
|
2020-11-29 20:07:46 +00:00
|
|
|
|
2021-08-18 09:36:40 +00:00
|
|
|
test('only uppercase string', () {
|
2022-06-05 19:36:32 +00:00
|
|
|
const int length = 8;
|
|
|
|
final String generatedString = StringGenerators.getRandomString(length,
|
|
|
|
hasLowercaseLetters: false, hasUppercaseLetters: true,);
|
2021-08-18 09:36:40 +00:00
|
|
|
|
|
|
|
expect(generatedString, isNot(matches(regExpNewLines)));
|
|
|
|
expect(generatedString, isNot(matches(regExpWhiteSpaces)));
|
|
|
|
expect(generatedString, isNot(matches(regExpNumbers)));
|
|
|
|
expect(generatedString, isNot(matches(regExpLowercaseLetters)));
|
|
|
|
expect(generatedString, isNot(matches(regExpSymbols)));
|
|
|
|
expect(generatedString.length, equals(length));
|
|
|
|
expect(generatedString, matches(regExpUppercaseLetters));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('only numbers string', () {
|
2022-06-05 19:36:32 +00:00
|
|
|
const int length = 8;
|
|
|
|
final String generatedString = StringGenerators.getRandomString(length,
|
2021-08-18 09:36:40 +00:00
|
|
|
hasLowercaseLetters: false,
|
|
|
|
hasUppercaseLetters: false,
|
2022-06-05 19:36:32 +00:00
|
|
|
hasNumbers: true,);
|
2021-08-18 09:36:40 +00:00
|
|
|
|
|
|
|
expect(generatedString, isNot(matches(regExpNewLines)));
|
|
|
|
expect(generatedString, isNot(matches(regExpWhiteSpaces)));
|
|
|
|
expect(generatedString, isNot(matches(regExpUppercaseLetters)));
|
|
|
|
expect(generatedString, isNot(matches(regExpLowercaseLetters)));
|
|
|
|
expect(generatedString, isNot(matches(regExpSymbols)));
|
|
|
|
expect(generatedString.length, equals(length));
|
|
|
|
expect(generatedString, matches(regExpNumbers));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('only symbols string', () {
|
2022-06-05 19:36:32 +00:00
|
|
|
const int length = 8;
|
|
|
|
final String generatedString = StringGenerators.getRandomString(
|
2021-08-18 09:36:40 +00:00
|
|
|
length,
|
|
|
|
hasLowercaseLetters: false,
|
|
|
|
hasUppercaseLetters: false,
|
|
|
|
hasNumbers: false,
|
|
|
|
hasSymbols: true,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(generatedString, isNot(matches(regExpNewLines)));
|
|
|
|
expect(generatedString, isNot(matches(regExpWhiteSpaces)));
|
|
|
|
expect(generatedString, isNot(matches(regExpUppercaseLetters)));
|
|
|
|
expect(generatedString, isNot(matches(regExpLowercaseLetters)));
|
|
|
|
expect(generatedString, isNot(matches(regExpNumbers)));
|
|
|
|
expect(generatedString.length, equals(length));
|
|
|
|
expect(generatedString, matches(regExpSymbols));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
group('Strict mode', () {
|
|
|
|
test('All', () {
|
2022-06-05 19:36:32 +00:00
|
|
|
const int length = 5;
|
|
|
|
final String generatedString = StringGenerators.getRandomString(length,
|
2021-08-18 09:36:40 +00:00
|
|
|
hasLowercaseLetters: true,
|
|
|
|
hasUppercaseLetters: true,
|
|
|
|
hasNumbers: true,
|
|
|
|
hasSymbols: true,
|
2022-06-05 19:36:32 +00:00
|
|
|
isStrict: true,);
|
2021-08-18 09:36:40 +00:00
|
|
|
|
|
|
|
expect(generatedString, isNot(matches(regExpNewLines)));
|
|
|
|
expect(generatedString, isNot(matches(regExpWhiteSpaces)));
|
|
|
|
expect(generatedString, matches(regExpLowercaseLetters));
|
|
|
|
expect(generatedString, matches(regExpUppercaseLetters));
|
|
|
|
expect(generatedString, matches(regExpNumbers));
|
|
|
|
expect(generatedString, matches(regExpSymbols));
|
|
|
|
expect(generatedString.length, equals(length));
|
|
|
|
});
|
|
|
|
test('Lowercase letters and numbers', () {
|
2022-06-05 19:36:32 +00:00
|
|
|
const int length = 3;
|
|
|
|
final String generatedString = StringGenerators.getRandomString(length,
|
2021-08-18 09:36:40 +00:00
|
|
|
hasLowercaseLetters: true,
|
|
|
|
hasUppercaseLetters: false,
|
|
|
|
hasNumbers: true,
|
|
|
|
hasSymbols: false,
|
2022-06-05 19:36:32 +00:00
|
|
|
isStrict: true,);
|
2021-08-18 09:36:40 +00:00
|
|
|
|
|
|
|
expect(generatedString, isNot(matches(regExpNewLines)));
|
|
|
|
expect(generatedString, isNot(matches(regExpWhiteSpaces)));
|
|
|
|
expect(generatedString, isNot(matches(regExpUppercaseLetters)));
|
|
|
|
expect(generatedString, isNot(matches(regExpSymbols)));
|
|
|
|
expect(generatedString, matches(regExpLowercaseLetters));
|
|
|
|
expect(generatedString, matches(regExpNumbers));
|
|
|
|
expect(generatedString.length, equals(length));
|
|
|
|
});
|
|
|
|
});
|
2020-11-29 20:07:46 +00:00
|
|
|
});
|
|
|
|
}
|
2021-08-18 09:36:40 +00:00
|
|
|
|
2022-06-05 19:36:32 +00:00
|
|
|
RegExp regExpNewLines = RegExp(r'[\n\r]+');
|
|
|
|
RegExp regExpWhiteSpaces = RegExp(r'[\s]+');
|
|
|
|
RegExp regExpUppercaseLetters = RegExp(r'[A-Z]');
|
|
|
|
RegExp regExpLowercaseLetters = RegExp(r'[a-z]');
|
|
|
|
RegExp regExpNumbers = RegExp(r'[0-9]');
|
|
|
|
RegExp regExpSymbols = RegExp(r'(?:_|[^\w\s])+');
|