Browse Source

neon: test HexColor

pull/422/head
Nikolas Rimikis 2 years ago
parent
commit
38bbbc7360
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 14
      packages/neon/neon/lib/src/utils/hex_color.dart
  2. 31
      packages/neon/neon/test/hex_color_test.dart

14
packages/neon/neon/lib/src/utils/hex_color.dart

@ -1,11 +1,11 @@
part of '../../neon.dart';
class HexColor extends Color {
HexColor(final String hexColor)
: super(
int.parse(
hexColor.toUpperCase().replaceAll('#', '').padLeft(8, 'F'),
radix: 16,
),
);
HexColor(final String hexColor) : super(_parse(hexColor));
static int _parse(final String hexColor) {
final formated = hexColor.toUpperCase().replaceAll('#', '').padLeft(8, 'F');
return int.parse(formated, radix: 16);
}
}

31
packages/neon/neon/test/hex_color_test.dart

@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'package:neon/neon.dart';
import 'package:test/test.dart';
void main() {
group('HexColor', () {
test('White', () {
final color = HexColor('#ffffffff');
expect(color.value, equals(Colors.white.value));
});
test('Without alpha', () {
final color = HexColor('#ffffff');
expect(color.value, equals(Colors.white.value));
});
test('Without #', () {
final color = HexColor('ffffffff');
expect(color.value, equals(Colors.white.value));
});
test('Uppercase', () {
final color = HexColor('#FFFFFFFF');
expect(color.value, equals(Colors.white.value));
});
});
}
Loading…
Cancel
Save