Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kemo committed Mar 17, 2017
1 parent 11536b9 commit 4b91394
Show file tree
Hide file tree
Showing 10 changed files with 701 additions and 945 deletions.
178 changes: 38 additions & 140 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,92 +17,56 @@ class Simple {
}
}

class SimpleWithSimple {
int id;
Simple simple;
}

class Test {
@Property(name: "_id")
int id;

@Property(name: "_lol??")
String value;

bool real;
@d.Entity()
class Test6 {
List<Simple> simple;

double tellme;
Test6();

@override
String toString() {
return "$id: $value, $real, $tellme";
return simple.fold("Test6: \n", (a, b) => a + b.toString() + "\n");
}
}

class Test1 {
SimpleWithSimple simple1;
class AnnotationSample2 {
int id;

@override
String toString() {
return "Test1: ${simple1.id} ${simple1.simple.toString()}";
}
}
@Property(name: "test1")
String text;

class Test2 {
Test test;
List<String> strings;
AnnotationSample2();

@override
String toString() {
return "Test2: ${test.toString()} $strings";
}
AnnotationSample2.withValues(this.id, this.text);
}

class Test3 extends Test {
String text2;
class MapComplex {
Map<String, Person> persons;
}

class Test4 extends Test3 {
String text3;

@override
String toString() {
return "$id: $value, $real, $tellme, $text2, $text3";
}
class MapSimple {
Map<String, String> persons;
}

class Test5 {
String text2;
Simple simple;

@override
String toString() {
return "${simple.id}: ${simple.text}, $text2";
}
class Person {
String name;
}

@d.Entity()
class Test6 {
List<Simple> simple;

Test6();

@override
String toString() {
return simple.fold("Test6: \n", (a, b) => a + b.toString() + "\n");
}
class Male {
Person person;
String test;
}

void test<T>(Test t, Type i) {
final Type d = T;
print(d);
print("${d == i}");
if (t.runtimeType == d) {
print("is ${t.runtimeType}");
} else {
print("is not ${t.runtimeType}");
}
}
// void test<T>(Test t, Type i) {
// final Type d = T;
// print(d);
// print("${d == i}");
// if (t.runtimeType == d) {
// print("is ${t.runtimeType}");
// } else {
// print("is not ${t.runtimeType}");
// }
// }

// {: [123]
// }: [125]
Expand Down Expand Up @@ -388,42 +352,29 @@ void main() {
Logger.root.onRecord.listen((LogRecord rec) {
print('${rec.level.name}: ${rec.time}: ${rec.message}');
});
//test<Test>(new Test(), Test);
//printChars();

// test12();
// test13();

// String json = '{"id": 2, "text":"lol"}';
// print(decodeTest<Simple>(json, Simple));
final json =
'{"person1": {"name": "name"},"person2": {"name": "name2"},"person3": {"name": "name3"}}';
final sample = decodeTest<MapComplex>(json, MapComplex);

//print(decodeTest<List<Test6>>(list, new List<Test6>().runtimeType));
int its = 2000;
Stopwatch w = new Stopwatch();
// int its = 2000;
// Stopwatch w = new Stopwatch();
// w.start();
// for (int i = 0; i < its; i++) {
// var b = JSON.decode(list);
// }
// w.stop();
// print("JSON.decode took: ${w.elapsedMilliseconds}");

// w.reset();
w.start();
for (int i = 0; i < its; i++) {
var b = decodeTest<List<Test6>>(list, new List<Test6>().runtimeType);
//print(b.length);
}
w.stop();
print("decodeTest took: ${w.elapsedMilliseconds}");

// w.reset();
// w.start();
// for (int i = 0; i < its; i++) {
// var b = decodeMap(JSON.decode(list), new List<Test6>().runtimeType);
// var b = decodeTest<List<Test6>>(list, new List<Test6>().runtimeType);
// //print(b.length);
// }
// w.stop();
// print("decodeMap took: ${w.elapsedMilliseconds}");
// print("decode 3rd version took: ${w.elapsedMilliseconds}");

// w.reset();
// w.start();
Expand All @@ -432,7 +383,7 @@ void main() {
// //print(b.length);
// }
// w.stop();
// print("decode took: ${w.elapsedMilliseconds}");
// print("decode 1st version took: ${w.elapsedMilliseconds}");

// w.reset();
// w.start();
Expand All @@ -452,57 +403,4 @@ void main() {
// }
// w.stop();
// print("dartson took: ${w.elapsedMilliseconds}");

// w.reset();

// String json = '{"id": 2, "text":"lol"}';
// print(json);
// var b = decodeTest<Simple>(json, Simple);
// print(b);
// print("");

// json = '["a", "b","c" , "d" , "a", "", " "]';
// print(json);
// var c = decodeTest<List<String>>(json, new List<String>().runtimeType);
// print(c);
// print("");

// print('{"_id":1000, "_lol??": "wat", "real": true, "tellme": 2.20}');
// var d = decodeTest<Test>(
// '{"_id":1000, "_lol??": "wat", "real": true, "tellme": 2.20}', Test);
// print(d);
// print("");

// print(
// '{"_id":0, "_lol??": "wat", "real": true, "tellme": 0.1001, "text2": "lol", "test3":"lol2"}');
// var g = decodeTest<Test4>(
// '{"_id":0, "_lol??": "wat", "real": true, "tellme": 0.1001, "text2": "lol", "test3":"lol2"}',
// Test4);
// print(g);
// print("");

// json = '{"simple1": {"id" : 2, "simple": {"id": 1, "text": "2"}}}';
// print(json);
// var e = decodeTest<Test1>(json, Test1);
// print(e);
// print("");

// var json = '{"text2": "test", "simple": { "id": 23, "text": "test text" }}';
// print(json);
// var f = decodeTest<Test5>(
// '{"text2": "test", "simple": { "id": 23, "text": "test text" }}', Test5);
// print(f);
// print("");

// json =
// '{"simple": [{ "id": 23, "text": "test text" }, { "id": 25, "text": "test text" }, { "id": 26, "text": "test text" }]}';
// print(json);
// var h = decodeTest<Test6>(json, Test6);
// print(h);
// print("");

// var json = '{"test": 2, "lol": "lol"}';
// print(json);
// var b = decode(json, Map);
// print(b);
}
2 changes: 1 addition & 1 deletion lib/src/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ class Property {
this.name = name;

bool get ignore => _ignore == null ? false : _ignore;
String toString() => "DartsonProperty: Name: ${name} , Ignore: ${ignore}";
bool get hasName => (name == null) ? false : (name.isEmpty) ? false : true;
}
Empty file added lib/src/deserialize.dart
Empty file.
Loading

0 comments on commit 4b91394

Please sign in to comment.