Created
October 15, 2010 14:54
-
-
Save Stray/628313 to your computer and use it in GitHub Desktop.
Code implementing an isNot(c:Class):Boolean function on the Object prototype
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
package com.newloop.experiments.isnot { | |
import asunit.framework.TestCase; | |
public class SomeClassATest extends TestCase { | |
private var someClassA:SomeClassA; | |
public function SomeClassATest(methodName:String=null) { | |
super(methodName) | |
} | |
override protected function setUp():void { | |
super.setUp(); | |
// you only need to do this once, before you objects are created | |
Object.prototype.isNot = function(c:Class):Boolean | |
{ | |
return !(this is c); | |
} | |
someClassA = new SomeClassA(); | |
} | |
override protected function tearDown():void { | |
super.tearDown(); | |
someClassA = null; | |
} | |
public function testInstantiated():void { | |
assertTrue("someClassA is SomeClassA", someClassA is SomeClassA); | |
} | |
public function testFailure():void { | |
assertTrue("Failing test", true); | |
} | |
public function test_isNot_whenIsNot_returns_true():void { | |
// requires cast to Object to get round compiler not finding isNot | |
var result:Boolean = Object(someClassA).isNot(String); | |
assertTrue("IsNot returns true correctly", result); | |
} | |
public function test_isNot_whenIs_returns_false():void { | |
// SomeClassA extends SomeClassB | |
// requires cast to Object to get round compiler not finding isNot | |
var result:Boolean = Object(someClassA).isNot(SomeClassB); | |
assertFalse("IsNot returns false correctly", result); | |
} | |
} | |
} |
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
package com.newloop.experiments.isnot { | |
public class SomeClassA extends SomeClassB { | |
public function SomeClassA() { | |
} | |
} | |
} | |
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
package com.newloop.experiments.isnot { | |
public class SomeClassB extends Object { | |
public function SomeClassB() { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment