Skip to content

Commit

Permalink
toFormattedString and meta constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
daegalus committed Jan 10, 2024
1 parent 8e9c07c commit aeed565
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/uuid_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,17 @@ class UuidValue {
return UuidParsing.parseAsByteList(uuid, validate: validate);
}

// toString() returns the String representation of the UUID
// toString() returns the String representation of the UUID, without reformatting it.
@override
String toString() {
return uuid;
}

String toFormattedString({bool validate = false}) {
return UuidParsing.unparse(UuidParsing.parse(uuid,
validate: validate, noDashes: !uuid.contains('-')));
}

// equals() compares to UuidValue objects' uuids.
bool equals(UuidValue other) {
return uuid == other.uuid;
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: uuid
version: 4.3.1
version: 4.3.2
description: >
RFC4122 (v1, v4, v5, v6, v7, v8) UUID Generator and Parser for Dart
documentation: https://daegalus.github.io/dart-uuid/index.html
Expand All @@ -9,7 +9,7 @@ environment:
dependencies:
crypto: ^3.0.0
sprintf: ^7.0.0
meta: ^1.11.0
meta: ^1.10.0
dev_dependencies:
lints: ^3.0.0
test: ^1.24.9
Expand Down
22 changes: 22 additions & 0 deletions test/uuid_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,28 @@ void main() {
true);
expect(Uuid.isValidUUID(fromString: validNoDashesUUID), false);
});

test('No Dashes UUIDValue Formatted string', () {
const validNoDashesUUID = '87cd4eb3cb88449ba1dae468fd829310';
expect(Uuid.isValidUUID(fromString: validNoDashesUUID, noDashes: true),
true);
expect(Uuid.isValidUUID(fromString: validNoDashesUUID), false);

var uuidval = UuidValue.fromString(validNoDashesUUID);
expect(
uuidval.toFormattedString(), "87cd4eb3-cb88-449b-a1da-e468fd829310");
});

test('No Dashes UUIDValue Formatted string validate', () {
const validNoDashesUUID = '87cd4eb3cb88449ba1dae468fd829310';
expect(Uuid.isValidUUID(fromString: validNoDashesUUID, noDashes: true),
true);
expect(Uuid.isValidUUID(fromString: validNoDashesUUID), false);

var uuidval = UuidValue.fromString(validNoDashesUUID);
expect(uuidval.toFormattedString(validate: true),
"87cd4eb3-cb88-449b-a1da-e468fd829310");
});
});

group('[Test Vectors]', () {
Expand Down

0 comments on commit aeed565

Please sign in to comment.