make app ids more unique (#6113)

* make app ids more unique

* in-line the uuid class
This commit is contained in:
Devon Carew
2016-09-28 11:18:05 -07:00
committed by GitHub
parent 6469872abd
commit d9bbd2fb53
3 changed files with 100 additions and 3 deletions

View File

@@ -18,4 +18,65 @@ baz=qux
expect(file.values, hasLength(2));
});
});
group('uuid', () {
// xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
test('simple', () {
Uuid uuid = new Uuid();
String result = uuid.generateV4();
expect(result.length, 36);
expect(result[8], '-');
expect(result[13], '-');
expect(result[18], '-');
expect(result[23], '-');
});
test('can parse', () {
Uuid uuid = new Uuid();
String result = uuid.generateV4();
expect(int.parse(result.substring(0, 8), radix: 16), isNotNull);
expect(int.parse(result.substring(9, 13), radix: 16), isNotNull);
expect(int.parse(result.substring(14, 18), radix: 16), isNotNull);
expect(int.parse(result.substring(19, 23), radix: 16), isNotNull);
expect(int.parse(result.substring(24, 36), radix: 16), isNotNull);
});
test('special bits', () {
Uuid uuid = new Uuid();
String result = uuid.generateV4();
expect(result[14], '4');
expect(result[19].toLowerCase(), isIn('89ab'));
result = uuid.generateV4();
expect(result[19].toLowerCase(), isIn('89ab'));
result = uuid.generateV4();
expect(result[19].toLowerCase(), isIn('89ab'));
});
test('is pretty random', () {
Set<String> set = new Set<String>();
Uuid uuid = new Uuid();
for (int i = 0; i < 64; i++) {
String val = uuid.generateV4();
expect(set, isNot(contains(val)));
set.add(val);
}
uuid = new Uuid();
for (int i = 0; i < 64; i++) {
String val = uuid.generateV4();
expect(set, isNot(contains(val)));
set.add(val);
}
uuid = new Uuid();
for (int i = 0; i < 64; i++) {
String val = uuid.generateV4();
expect(set, isNot(contains(val)));
set.add(val);
}
});
});
}