Skip to content

Commit

Permalink
feat(priority): Adds the full range of priorities from A to Z #48
Browse files Browse the repository at this point in the history
  • Loading branch information
tmaegel committed May 2, 2024
1 parent e2839a9 commit d731848
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
32 changes: 30 additions & 2 deletions lib/domain/todo/todo_model.dart
Expand Up @@ -3,7 +3,35 @@ import 'dart:math';
import 'package:equatable/equatable.dart';
import 'package:ntodotxt/exceptions/exceptions.dart';

enum Priority { none, A, B, C, D, E, F }
enum Priority {
none,
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z
}

extension Priorities on Priority {
static Set<Priority> get priorities => {
Expand Down Expand Up @@ -71,7 +99,7 @@ extension Priorities on Priority {
class Todo extends Equatable {
static final RegExp patternWord = RegExp(r'^\S+$');
// Limit priorities from A-F.
static final RegExp patternPriority = RegExp(r'^\((?<priority>[A-F])\)$');
static final RegExp patternPriority = RegExp(r'^\((?<priority>[A-Z])\)$');
static final RegExp patternDate = RegExp(r'^\d{4}-\d{2}-\d{2}$');
static final RegExp patternProject = RegExp(r'^\+\S+$');
static final RegExp patternContext = RegExp(r'^\@\S+$');
Expand Down
8 changes: 8 additions & 0 deletions test/domain/todo/todo_model_test.dart
Expand Up @@ -309,6 +309,10 @@ void main() {
);
expect(todo.priority, Priority.A);
});
test('incompleted todo with very low priority', () {
final todo = Todo.fromString(value: '(Z) Todo');
expect(todo.priority, Priority.Z);
});
test('completed short todo (RangeError)', () {
final todo = Todo.fromString(value: 'x 2022-11-16 (A) Todo');
expect(todo.priority, Priority.A);
Expand All @@ -325,6 +329,10 @@ void main() {
);
expect(todo.priority, Priority.A);
});
test('completed todo with very low priority', () {
final todo = Todo.fromString(value: 'x 2022-11-16 (Z) Todo');
expect(todo.priority, Priority.Z);
});
});
group('without priority', () {
test('incompleted short todo (RangeError)', () {
Expand Down

0 comments on commit d731848

Please sign in to comment.