forked from Joose/Joose
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- tested correctness of mutability of builder class
- Loading branch information
1 parent
75c698c
commit 964e17d
Showing
9 changed files
with
195 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
StartTest(function (t) { | ||
|
||
t.plan(7) | ||
|
||
//================================================================================================================================================================================== | ||
t.diag("Sanity") | ||
|
||
t.ok(Joose.Managed.Class, "Joose.Managed.Class is here") | ||
|
||
|
||
//================================================================================================================================================================================== | ||
t.diag("Inheritance of builder class") | ||
|
||
var BaseMetaClass = new Joose.Managed.Class('BaseMetaClass', { | ||
isa : Joose.Managed.Class, | ||
|
||
builder : { | ||
methods : { | ||
testBuilder : function (meta, props) { | ||
var name = props.name | ||
var value = props.value | ||
|
||
meta.addMethod(name, function () { | ||
return value | ||
}) | ||
} | ||
} | ||
} | ||
|
||
}).c | ||
|
||
|
||
var TestClass1 = new BaseMetaClass('TestClass1', { | ||
|
||
testBuilder : { | ||
name : 'result', | ||
value : 'TestClass1' | ||
} | ||
|
||
}).c | ||
|
||
var testClass1 = new TestClass1() | ||
|
||
t.ok(TestClass1.meta.hasOwnMethod('result') && testClass1.result() == 'TestClass1', "Builder was extened and works correctly #1") | ||
|
||
t.ok(BaseMetaClass.meta.getAttributedClass('builderClass').meta.hasMethod('testBuilder'), "BaseMetaClass extended its builder class") | ||
|
||
|
||
|
||
var SuperMetaClass = new Joose.Managed.Class('SuperMetaClass', { | ||
|
||
isa : BaseMetaClass, | ||
|
||
builder : { | ||
methods : { | ||
testBuilder2 : function (meta, props) { | ||
var name = props.name | ||
var value = props.value | ||
|
||
meta.addMethod(name, function () { | ||
return name | ||
}) | ||
} | ||
} | ||
} | ||
}).c | ||
|
||
|
||
t.ok(SuperMetaClass.meta.getAttributedClass('builderClass').meta.hasMethod('testBuilder'), "'SuperMetaClass' inherited 'testBuilder'") | ||
t.ok(SuperMetaClass.meta.getAttributedClass('builderClass').meta.hasMethod('testBuilder2'), "'SuperMetaClass' received 'testBuilder2'") | ||
|
||
|
||
|
||
var TestClass2 = new SuperMetaClass('TestClass2', { | ||
|
||
testBuilder : { | ||
name : 'result', | ||
value : 'TestClass2' | ||
}, | ||
|
||
testBuilder2 : { | ||
name : 'result2', | ||
value : 'TestClass2' | ||
} | ||
|
||
}).c | ||
|
||
var testClass2 = new TestClass2() | ||
|
||
t.ok(TestClass2.meta.hasOwnMethod('result') && testClass2.result() == 'TestClass2', "Builder was inherited #1") | ||
t.ok(TestClass2.meta.hasOwnMethod('result2') && testClass2.result2() == 'result2', "Builder was extened and works correctly #2") | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
StartTest(function (t) { | ||
|
||
t.plan(5) | ||
|
||
//================================================================================================================================================================================== | ||
t.diag("Sanity") | ||
|
||
t.ok(Joose.Managed.Class, "Joose.Managed.Class is here") | ||
|
||
|
||
//================================================================================================================================================================================== | ||
t.diag("Defining a metaclass with unmodified builder class") | ||
|
||
var BaseMetaClass = new Joose.Managed.Class('BaseMetaClass', { | ||
isa : Joose.Managed.Class | ||
}).c | ||
|
||
|
||
|
||
var SuperMetaClass = new Joose.Managed.Class('SuperMetaClass', { | ||
|
||
isa : BaseMetaClass, | ||
|
||
builder : { | ||
methods : { | ||
testBuilder2 : function (meta, props) { | ||
var name = props.name | ||
var value = props.value | ||
|
||
meta.addMethod(name, function () { | ||
return name | ||
}) | ||
} | ||
} | ||
} | ||
}).c | ||
|
||
|
||
t.ok(SuperMetaClass.meta.getAttributedClass('builderClass').meta.hasMethod('testBuilder2'), "'SuperMetaClass' received 'testBuilder2'") | ||
t.ok(!BaseMetaClass.meta.getAttributedClass('builderClass').meta.hasMethod('testBuilder2'), "BaseMetaClass don't received 'testBuilder2'") | ||
|
||
//================================================================================================================================================================================== | ||
t.diag("Mutation of builder class") | ||
|
||
|
||
BaseMetaClass.meta.extend({ | ||
builder : { | ||
methods : { | ||
testBuilder : function (meta, props) { | ||
var name = props.name | ||
var value = props.value | ||
|
||
meta.addMethod(name, function () { | ||
return value | ||
}) | ||
} | ||
} | ||
} | ||
}) | ||
|
||
t.ok(BaseMetaClass.meta.getAttributedClass('builderClass').meta.hasMethod('testBuilder'), "BaseMetaClass extended its builder class") | ||
|
||
t.ok(SuperMetaClass.meta.getAttributedClass('builderClass').meta.hasMethod('testBuilder2'), "and it reflected in sub-meta-classes") | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters