Skip to content

Commit

Permalink
test getVersionSemVer and fix bug in it
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Jun 4, 2024
1 parent 419a0d2 commit 383b044
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Frontend/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ Version getVersionSemVer(String input) {
if (split.length > 1 && int.tryParse(split[1]) != null) {
minor = split[1];
}
if (split.length > 2 && int.tryParse(split[2]) != null) {
patch = split[2].replaceAll(RegExp(r"\D"), "");
if (split.length > 2 && int.tryParse(split[2].replaceAll(RegExp(r'[^0-9]'), '')) != null) {
patch = split[2].replaceAll(RegExp(r'[^0-9]'), '');
}
return Version(int.parse(major), int.parse(minor), int.parse(patch));
}
Expand Down
10 changes: 10 additions & 0 deletions test/Frontend/utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:tail_app/Frontend/utils.dart';
import 'package:tail_app/constants.dart';
import 'package:test/test.dart';
Expand Down Expand Up @@ -34,4 +35,13 @@ void main() {
color = getTextColor(Color(appColorDefault));
expect(color, Typography.material2021().white.labelLarge!.color!);
});

test('Get version from string', () {
Version version = getVersionSemVer("");
expect(version, Version(0, 0, 0));
version = getVersionSemVer("5.1.3b");
expect(version, Version(5, 1, 3));
version = getVersionSemVer("VER 5.2.5");
expect(version, Version(5, 2, 5));
});
}

0 comments on commit 383b044

Please sign in to comment.