mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 10:17:16 +08:00
Fix serializer tests
* Map equality does not exist in Dart - how sucky! * We no longer care about the micro-seconds
This commit is contained in:
@ -28,7 +28,7 @@ class Note implements Comparable {
|
|||||||
if (json.containsKey("created")) {
|
if (json.containsKey("created")) {
|
||||||
var createdStr = json['created'].toString();
|
var createdStr = json['created'].toString();
|
||||||
try {
|
try {
|
||||||
created = DateTime.parse(json['created']);
|
created = DateTime.parse(json['created']).toLocal();
|
||||||
} catch (ex) {}
|
} catch (ex) {}
|
||||||
|
|
||||||
if (created == null) {
|
if (created == null) {
|
||||||
@ -37,7 +37,7 @@ class Note implements Comparable {
|
|||||||
if (regex.hasMatch(createdStr)) {
|
if (regex.hasMatch(createdStr)) {
|
||||||
// FIXME: Handle the timezone!
|
// FIXME: Handle the timezone!
|
||||||
createdStr = createdStr.substring(0, 19);
|
createdStr = createdStr.substring(0, 19);
|
||||||
created = DateTime.parse(json['created']);
|
created = DateTime.parse(createdStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,12 @@ class Note implements Comparable {
|
|||||||
id == other.id &&
|
id == other.id &&
|
||||||
body == other.body &&
|
body == other.body &&
|
||||||
created == other.created &&
|
created == other.created &&
|
||||||
extraProperties == other.extraProperties;
|
_equalMaps(extraProperties, other.extraProperties);
|
||||||
|
|
||||||
|
static bool _equalMaps(Map a, Map b) {
|
||||||
|
if (a.length != b.length) return false;
|
||||||
|
return a.keys.every((key) => b.containsKey(key) && a[key] == b[key]);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
|
@ -3,10 +3,15 @@ import 'package:journal/storage/serializers.dart';
|
|||||||
|
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
DateTime nowWithoutMicro() {
|
||||||
|
var dt = DateTime.now();
|
||||||
|
return DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
group('Serializers', () {
|
group('Serializers', () {
|
||||||
var note =
|
var note =
|
||||||
Note(id: "2", body: "This is the body", created: new DateTime.now());
|
Note(id: "2", body: "This is the body", created: nowWithoutMicro());
|
||||||
|
|
||||||
test('JSON Serializer', () {
|
test('JSON Serializer', () {
|
||||||
var serializer = new JsonNoteSerializer();
|
var serializer = new JsonNoteSerializer();
|
||||||
|
Reference in New Issue
Block a user