2010-01-06 00:36:58 +00:00
|
|
|
EntityDeclarationTest = TestCase('EntityDeclarationTest');
|
|
|
|
|
|
|
|
|
|
EntityDeclarationTest.prototype.testEntityTypeOnly = function(){
|
|
|
|
|
expectAsserts(2);
|
2010-01-25 01:10:58 +00:00
|
|
|
var datastore = {entity:function(name){
|
2010-01-06 00:36:58 +00:00
|
|
|
assertEquals("Person", name);
|
2010-01-25 01:10:58 +00:00
|
|
|
}};
|
|
|
|
|
var scope = new Scope();
|
|
|
|
|
var init = scope.entity("Person", datastore);
|
2010-01-06 00:36:58 +00:00
|
|
|
assertEquals("", init);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
EntityDeclarationTest.prototype.testWithDefaults = function(){
|
|
|
|
|
expectAsserts(4);
|
2010-01-25 01:10:58 +00:00
|
|
|
var datastore = {entity:function(name, init){
|
2010-01-06 00:36:58 +00:00
|
|
|
assertEquals("Person", name);
|
|
|
|
|
assertEquals("=a:", init.a);
|
|
|
|
|
assertEquals(0, init.b.length);
|
2010-01-25 01:10:58 +00:00
|
|
|
}};
|
|
|
|
|
var scope = new Scope();
|
|
|
|
|
var init = scope.entity('Person:{a:"=a:", b:[]}', datastore);
|
2010-01-06 00:36:58 +00:00
|
|
|
assertEquals("", init);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
EntityDeclarationTest.prototype.testWithName = function(){
|
|
|
|
|
expectAsserts(2);
|
2010-01-25 01:10:58 +00:00
|
|
|
var datastore = {entity:function(name, init){
|
2010-01-06 00:36:58 +00:00
|
|
|
assertEquals("Person", name);
|
|
|
|
|
return function (){ return {}; };
|
2010-01-25 01:10:58 +00:00
|
|
|
}};
|
|
|
|
|
var scope = new Scope();
|
|
|
|
|
var init = scope.entity('friend=Person', datastore);
|
2010-01-06 00:36:58 +00:00
|
|
|
assertEquals("$anchor.friend:{friend=Person.load($anchor.friend);friend.$$anchor=\"friend\";};", init);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
EntityDeclarationTest.prototype.testMultipleEntities = function(){
|
|
|
|
|
expectAsserts(3);
|
|
|
|
|
var expect = ['Person', 'Book'];
|
|
|
|
|
var i=0;
|
2010-01-25 01:10:58 +00:00
|
|
|
var datastore = {entity:function(name, init){
|
2010-01-06 00:36:58 +00:00
|
|
|
assertEquals(expect[i], name);
|
|
|
|
|
i++;
|
|
|
|
|
return function (){ return {}; };
|
2010-01-25 01:10:58 +00:00
|
|
|
}};
|
|
|
|
|
var scope = new Scope();
|
|
|
|
|
var init = scope.entity('friend=Person;book=Book;', datastore);
|
2010-01-06 00:36:58 +00:00
|
|
|
assertEquals("$anchor.friend:{friend=Person.load($anchor.friend);friend.$$anchor=\"friend\";};" +
|
|
|
|
|
"$anchor.book:{book=Book.load($anchor.book);book.$$anchor=\"book\";};",
|
|
|
|
|
init);
|
|
|
|
|
};
|