Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kevin Malakoff
committed
Sep 18, 2012
1 parent
44f5497
commit 0aad41b
Showing
16 changed files
with
1,144 additions
and
8 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,32 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>Mixin.js Test Suite Auto Memory (AMD)</title> | ||
<link rel="stylesheet" href="../vendor/qunit/qunit.css" type="text/css" media="screen" /> | ||
<script type="text/javascript" src="../vendor/qunit/jquery.js"></script> | ||
<script type="text/javascript" src="../vendor/qunit/qunit.js"></script> | ||
<script type="text/javascript" src="../vendor/qunit/jslitmus.js"></script> | ||
|
||
<script src="../vendor/require.js"></script> | ||
<script type="text/javascript"> | ||
require.config({ | ||
paths: { | ||
'underscore': "../../vendor/underscore-1.3.3", | ||
'mixin-js-core': "../../mixin-js-core", | ||
'mixin-js-auto-memory': "../../lib/mixin-js-auto-memory" | ||
} | ||
}); | ||
</script> | ||
|
||
<script type="text/javascript" src="build/test-amd.js"></script> | ||
</head> | ||
<body> | ||
<div> | ||
<h1 id="qunit-header">Mixin.js Test Suite Auto Memory (AMD)</h1> | ||
<h2 id="qunit-banner"></h2> | ||
<h2 id="qunit-userAgent"></h2> | ||
<ol id="qunit-tests"></ol> | ||
</div> | ||
<script type="text/javascript">QUnit.done = function(failures, total) {if (!total) { $('#qunit-banner').removeClass('qunit-pass').addClass('qunit-fail'); throw 'Warning: no tests run'}}</script> | ||
</body> | ||
</html> |
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,89 @@ | ||
$(-> | ||
module("mixin-js-amd.js") | ||
|
||
# library and dependencies | ||
require(['mixin-js-core', 'mixin-js-flags'], (_Mixin, Mixin) -> | ||
Mixin.DEBUG = true | ||
|
||
test("TEST DEPENDENCY MISSING", -> | ||
ok(!!Mixin); ok(!!Mixin.Flags) | ||
) | ||
|
||
test("Use case: no initialization flags and basic usage", -> | ||
class ClassWithFlags | ||
constructor: -> | ||
Mixin.in(this, 'Flags') | ||
|
||
instance = new ClassWithFlags() | ||
equal(instance.flags(), 0, 'default is flags 0') | ||
|
||
flags = instance.flags(1<<0|1<<1) | ||
equal(flags, 1<<0|1<<1, 'flags are now 1<<0|1<<1') | ||
equal(instance.flags(), 1<<0|1<<1, 'flags are now 1<<0|1<<1') | ||
equal(instance.hasFlags(1<<0), true, 'flags bit 1<<0') | ||
equal(instance.hasFlags(1<<1), true, 'flags bit 1<<1') | ||
equal(instance.hasFlags(1<<2), false, 'flags bit 1<<2') | ||
|
||
flags = instance.resetFlags(1<<0) | ||
equal(flags, 1<<1, 'flags are now 1<<1') | ||
equal(instance.flags(), 1<<1, 'flags are now 1<<1') | ||
equal(instance.hasFlags(1<<0), false, 'flags bit 1<<0') | ||
equal(instance.hasFlags(1<<1), true, 'flags bit 1<<1') | ||
equal(instance.hasFlags(1<<2), false, 'flags bit 1<<2') | ||
|
||
flags = instance.setFlags(1<<3|1<<4) | ||
equal(flags, 1<<1|1<<3|1<<4, 'flags are now 1<<1|1<<3|1<<4') | ||
equal(instance.flags(), 1<<1|1<<3|1<<4, 'flags are now 1<<1|1<<3|1<<4') | ||
equal(instance.hasFlags(1<<0), false, 'flags bit 1<<0') | ||
equal(instance.hasFlags(1<<1), true, 'flags bit 1<<1') | ||
equal(instance.hasFlags(1<<2), false, 'flags bit 1<<2') | ||
equal(instance.hasFlags(1<<3), true, 'flags bit 1<<3') | ||
equal(instance.hasFlags(1<<4), true, 'flags bit 1<<4') | ||
) | ||
|
||
test("Use case: initialization flags", -> | ||
class ClassWithInitialzationFlags | ||
constructor: -> | ||
Mixin.in(this, 'Flags', 3) | ||
|
||
instance = new ClassWithInitialzationFlags() | ||
equal(instance.flags(), 3, 'flags are initialized with 3') | ||
) | ||
|
||
test("Use case: flags and change callback", -> | ||
class ClassWithFlagsAndCallback | ||
constructor: -> | ||
@change_count = 0 | ||
Mixin.in(this, 'Flags', 0, => @change_count++) | ||
|
||
instance = new ClassWithFlagsAndCallback() | ||
equal(instance.change_count, 0, 'no changes yet') | ||
instance.flags(0) | ||
equal(instance.change_count, 0, 'no changes yet') | ||
|
||
instance.flags(1<<1|1<<2) | ||
equal(instance.flags(), 1<<1|1<<2, 'flags are now 1<<1|1<<2') | ||
equal(instance.change_count, 1, '1 change') | ||
instance.flags(1<<1|1<<2) | ||
equal(instance.flags(), 1<<1|1<<2, 'flags are 1<<1|1<<2 still') | ||
equal(instance.change_count, 1, '1 change still') | ||
|
||
instance.setFlags(1<<3) | ||
equal(instance.flags(), 1<<1|1<<2|1<<3, 'flags are now 1<<1|1<<2|1<<3') | ||
equal(instance.change_count, 2, '2 changes') | ||
instance.setFlags(1<<2) | ||
equal(instance.flags(), 1<<1|1<<2|1<<3, 'flags are 1<<1|1<<2|1<<3 still') | ||
equal(instance.change_count, 2, '2 changes still') | ||
|
||
instance.resetFlags(1<<4) | ||
equal(instance.flags(), 1<<1|1<<2|1<<3, 'flags are 1<<1|1<<2|1<<3 still') | ||
equal(instance.change_count, 2, '2 changes still') | ||
instance.resetFlags(1<<1) | ||
equal(instance.flags(), 1<<2|1<<3, 'flags are 1<<2|1<<3') | ||
equal(instance.change_count, 3, '3 changes') | ||
instance.resetFlags(1<<1) | ||
equal(instance.flags(), 1<<2|1<<3, 'flags are 1<<2|1<<3 still') | ||
equal(instance.change_count, 3, '3 changes still') | ||
) | ||
) | ||
) |
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,31 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>Mixin.js Test Suite Flags (AMD)</title> | ||
<link rel="stylesheet" href="../vendor/qunit/qunit.css" type="text/css" media="screen" /> | ||
<script type="text/javascript" src="../vendor/qunit/jquery.js"></script> | ||
<script type="text/javascript" src="../vendor/qunit/qunit.js"></script> | ||
<script type="text/javascript" src="../vendor/qunit/jslitmus.js"></script> | ||
|
||
<script src="../vendor/require.js"></script> | ||
<script type="text/javascript"> | ||
require.config({ | ||
paths: { | ||
'mixin-js-core': "../../mixin-js-core", | ||
'mixin-js-flags': "../../lib/mixin-js-flags" | ||
} | ||
}); | ||
</script> | ||
|
||
<script type="text/javascript" src="build/test-amd.js"></script> | ||
</head> | ||
<body> | ||
<div> | ||
<h1 id="qunit-header">Mixin.js Test Suite Flags (AMD)</h1> | ||
<h2 id="qunit-banner"></h2> | ||
<h2 id="qunit-userAgent"></h2> | ||
<ol id="qunit-tests"></ol> | ||
</div> | ||
<script type="text/javascript">QUnit.done = function(failures, total) {if (!total) { $('#qunit-banner').removeClass('qunit-pass').addClass('qunit-fail'); throw 'Warning: no tests run'}}</script> | ||
</body> | ||
</html> |
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,70 @@ | ||
$(-> | ||
module("mixin-js-amd.js") | ||
|
||
# library and dependencies | ||
require(['mixin-js-core', 'mixin-js-ref-count'], (_Mixin, Mixin) -> | ||
Mixin.DEBUG = true | ||
|
||
test("TEST DEPENDENCY MISSING", -> | ||
ok(!!Mixin); ok(!!Mixin.RefCount) | ||
) | ||
|
||
test("Use case: adding ref counting to a class", -> | ||
class SomeClass | ||
constructor: -> | ||
Mixin.in(this, 'RefCount') | ||
destroy: -> | ||
Mixin.out(this, 'RefCount') | ||
|
||
# expected scenario | ||
instance = new SomeClass() | ||
equal(instance.refCount(), 1, 'refcount is started at 1') | ||
instance.retain() | ||
equal(instance.refCount(), 2, 'retain: ref count is now 2') | ||
instance.release() | ||
equal(instance.refCount(), 1, 'release: ref count is now 1') | ||
instance.release() | ||
equal(instance.refCount(), 0, 'release: ref count is now 0') | ||
|
||
# right into the danger zone | ||
raises(instance.retain, Error, 'Mixin.RefCount: ref_count is corrupt: 0') | ||
equal(instance.refCount(), 0, 'release: ref count is still 0') | ||
raises(instance.release, Error, 'Mixin.RefCount: ref_count is corrupt: 0') | ||
equal(instance.refCount(), 0, 'release: ref count is still 0') | ||
|
||
# cleanup to avoid memory leaks | ||
instance.destroy() | ||
) | ||
|
||
test("Use case: adding ref counting to a class with auto destroy", -> | ||
class ClassWithAutoDestroy | ||
constructor: -> | ||
Mixin.in(this, 'RefCount', => @destroy()) | ||
@is_destroyed = false | ||
destroy: -> | ||
throw new Error('already destroyed') if @is_destroyed | ||
@is_destroyed = true | ||
|
||
# expected scenario | ||
instance = new ClassWithAutoDestroy() | ||
equal(instance.refCount(), 1, 'refcount is started at 1') | ||
instance.retain() | ||
equal(instance.refCount(), 2, 'retain: ref count is now 2') | ||
instance.release() | ||
equal(instance.refCount(), 1, 'release: ref count is now 1') | ||
equal(instance.is_destroyed, false, 'release: not destroyed') | ||
instance.release() | ||
equal(instance.refCount(), 0, 'release: ref count is now 0') | ||
equal(instance.is_destroyed, true, 'release: now destroyed') | ||
|
||
# highway to the danger zone | ||
raises(instance.retain, Error, 'Mixin.RefCount: ref_count is corrupt: 0') | ||
equal(instance.refCount(), 0, 'release: ref count is still 0') | ||
raises(instance.release, Error, 'Mixin.RefCount: ref_count is corrupt: 0') | ||
equal(instance.refCount(), 0, 'release: ref count is still 0') | ||
|
||
# cleanup to avoid memory leaks | ||
Mixin.out(instance, 'RefCount') | ||
) | ||
) | ||
) |
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,31 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>Mixin.js Test Suite Ref Count (AMD)</title> | ||
<link rel="stylesheet" href="../vendor/qunit/qunit.css" type="text/css" media="screen" /> | ||
<script type="text/javascript" src="../vendor/qunit/jquery.js"></script> | ||
<script type="text/javascript" src="../vendor/qunit/qunit.js"></script> | ||
<script type="text/javascript" src="../vendor/qunit/jslitmus.js"></script> | ||
|
||
<script src="../vendor/require.js"></script> | ||
<script type="text/javascript"> | ||
require.config({ | ||
paths: { | ||
'mixin-js-core': "../../mixin-js-core", | ||
'mixin-js-ref-count': "../../lib/mixin-js-ref-count" | ||
} | ||
}); | ||
</script> | ||
|
||
<script type="text/javascript" src="build/test-amd.js"></script> | ||
</head> | ||
<body> | ||
<div> | ||
<h1 id="qunit-header">Mixin.js Test Suite Ref Count (AMD)</h1> | ||
<h2 id="qunit-banner"></h2> | ||
<h2 id="qunit-userAgent"></h2> | ||
<ol id="qunit-tests"></ol> | ||
</div> | ||
<script type="text/javascript">QUnit.done = function(failures, total) {if (!total) { $('#qunit-banner').removeClass('qunit-pass').addClass('qunit-fail'); throw 'Warning: no tests run'}}</script> | ||
</body> | ||
</html> |
Oops, something went wrong.