Skip to content

Commit

Permalink
Update for null-safety
Browse files Browse the repository at this point in the history
  • Loading branch information
greymouser committed Nov 22, 2020
1 parent 4c2dc47 commit 0eb5aab
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.0

- Update for null-safety support.

## 1.0.3

- Allow user to specify placeholder character for nulla/zero.
Expand Down
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Defines a default set of lint rules enforced for
# projects at Google. For details and rationale,
# see https://github.com/dart-lang/pedantic#enabled-lints.
include: package:pedantic/analysis_options.yaml
include: package:pedantic/analysis_options.1.9.0.yaml

# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
Expand Down
8 changes: 6 additions & 2 deletions lib/src/int_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ final _romanNumbersToLetters = {
};

extension RomanNumeralsInt on int {
/// Check for a valid Roman numeral value -- this is a sanity check, as we
/// don't want 64k worth of M's.
bool get isValidRomanNumeralValue => !(this < 0 || this > 65535);

/// Uses [nulla] as placeholder for zero. [nulla] should be a single, Roman,
/// alphanumeric character.
String toRomanNumeralString({String nulla = 'N'}) {
String? toRomanNumeralString({String nulla = 'N'}) {
// self-imposed maxium value. We don't need >64k worth of M's.
if (this < 0 || this > 65535) {
if (!isValidRomanNumeralValue) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/string_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension RomanNumeralsString on String {
return matches.length == 1;
}

int toRomanNumeralValue() {
int? toRomanNumeralValue() {
// Guard against malformed string sequences, and return early if the string itself is invalid
if (!isValidRomanNumeral()) {
return null;
Expand Down
13 changes: 5 additions & 8 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
name: numerus
description: Dart extensions for translating integers to Roman numerals and Roman numerals strings to integers.
version: 1.0.3
version: 1.1.0
homepage: https://github.com/greymouser/dart-numerus

environment:
sdk: '>=2.7.0 <3.0.0'

#dependencies:
# path: ^1.6.0
sdk: '>=2.12.0-0 <3.0.0'

dev_dependencies:
pedantic: ^1.8.0
test: ^1.6.0
test_coverage: ^0.4.1
pedantic: ^1.9.2
test: ^1.16.0-nullsafety.12
test_coverage: ^0.5.0
6 changes: 3 additions & 3 deletions test/numerus_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ void main() {
test('number to max unsigned long', () {
var n = 65535;
var got = n.toRomanNumeralString();
expect(got.length, 70); // the length of the insanely long string
expect(got[0], 'M');
expect(got.endsWith('MDXXXV'), true);
expect(got?.length, 70); // the length of the insanely long string
expect(got?[0], 'M');
expect(got?.endsWith('MDXXXV'), true);
});

test('number to greater than max unsigned long', () {
Expand Down

0 comments on commit 0eb5aab

Please sign in to comment.