• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

albertms10 / music_notes / 16737221467

05 Aug 2025 12:18AM UTC coverage: 99.551% (-0.4%) from 100.0%
16737221467

push

github

web-flow
refactor: ♻️ rename formatters to `*Notation` (#608)

* refactor: ♻️ rename formatters to `*Notation`

Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>

* refactor: ♻️ rename `system` to `formatter`

Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>

* docs(README): 📖 rename `system` → `formatter`

Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>

* ci(analysis): ❓ attempt to address CI issues

Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>

* ci(analysis): ❓ revert attempt

Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>

* refactor(notation_system): ♻️ rename and split `Formatter`, `Parser` responsibilities

Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>

* feat(notation_system): ✨ add `chain` extension method to `List<Parser<T>>`

Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>

* refactor(accidental): ♻️ move `parse` factory method body to the new parser

Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>

* feat: ✨ add parse and format equivalents

Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>

* refactor(notation_system): ♻️ use `abstract interface class`

Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>

* refactor(mode): ♻️ reuse `_dur` and `_moll` static constants

Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>

* refactor(mode): ♻️ override `matches` method

Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>

* refactor(note): ♻️ override `matches` method

Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>

---------

Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>

274 of 280 new or added lines in 17 files covered. (97.86%)

1 existing line in 1 file now uncovered.

1553 of 1560 relevant lines covered (99.55%)

2.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/lib/src/notation_system.dart
1
// ignore_for_file: one_member_abstracts - Code reusability
2

3
/// An abstract representation of a notation system for parsing
4
/// and formatting [T].
5
///
6
/// The [format] and [parse] methods should be designed to be [inverses](https://en.wikipedia.org/wiki/Inverse_function)
7
/// of each other:
8
/// the output of [format] should be a valid argument for [parse], and
9
/// `parse(format(value))` should return a value equal to the original value.
10
abstract class NotationSystem<T> implements Formatter<T>, Parser<T> {
11
  /// Creates a new formatter.
12
  const NotationSystem();
16✔
13

14
  /// Formats this [T].
15
  ///
16
  /// The output of this method should be accepted by [parse] to reconstruct
17
  /// the original value.
18
  @override
19
  String format(T value);
20

21
  @override
1✔
22
  bool matches(String source) => true;
23

24
  /// Parses [source] as [T].
25
  ///
26
  /// The input [source] should typically be produced by [format], ensuring
27
  /// that `parse(format(value)) == value`.
28
  ///
29
  /// If the [source] string does not contain a valid [T], a [FormatException]
30
  /// should be thrown.
31
  @override
32
  T parse(String source);
33
}
34

35
/// An abstract representation of a formatter for [T].
36
abstract interface class Formatter<T> {
37
  /// Formats this [T].
38
  String format(T value);
39
}
40

41
/// An abstract representation of a parser for [T].
42
abstract interface class Parser<T> {
43
  /// Whether [source] can be parsed with [parse].
NEW
44
  bool matches(String source) => true;
×
45

46
  /// Parses [source] as [T].
47
  T parse(String source);
48
}
49

50
/// A [Parser] chain.
51
extension ParserChain<T> on List<Parser<T>> {
52
  /// Parses [source] from this chain of [Parser]s.
53
  T parse(String source) {
1✔
54
    for (final parser in this) {
2✔
55
      if (parser.matches(source)) return parser.parse(source);
2✔
56
    }
57
    throw FormatException('End of parser chain: invalid $T', source);
2✔
58
  }
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc