diff --git a/CHANGELOG.md b/CHANGELOG.md index cc8cb95..99ed870 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.0 + + - Update for null-safety support. + ## 1.0.3 - Allow user to specify placeholder character for nulla/zero. diff --git a/analysis_options.yaml b/analysis_options.yaml index a686c1b..c8b13e2 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -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. diff --git a/lib/src/int_extension.dart b/lib/src/int_extension.dart index c2d570c..c17e3f4 100644 --- a/lib/src/int_extension.dart +++ b/lib/src/int_extension.dart @@ -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; } diff --git a/lib/src/string_extension.dart b/lib/src/string_extension.dart index a5feed9..259bb91 100644 --- a/lib/src/string_extension.dart +++ b/lib/src/string_extension.dart @@ -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; diff --git a/pubspec.yaml b/pubspec.yaml index 5cd9012..a90b943 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 diff --git a/test/numerus_test.dart b/test/numerus_test.dart index cf04156..cf9edd7 100644 --- a/test/numerus_test.dart +++ b/test/numerus_test.dart @@ -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', () {