123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- QUnit.test("decorator", function (assert) {
- var A = clazz(Object, {
- hello: function () {
- return "A";
- }
- });
- var Decorator = clazz(Object, {
- hello: function () {
- return "B" + this.decorated() + "B";
- }
- });
- var a = new A();
- assert.strictEqual(a.hello(), "A");
- a.decorateWith(new Decorator());
- var value = a.hello();
- assert.strictEqual(value, "BAB");
- });
- QUnit.test("super", function (assert) {
- var A = clazz(Object, {
- hello: function () {
- return "A";
- }
- });
- var B = clazz(A, {
- hello: function () {
- return "B" + this.super() + "B";
- }
- });
- var C = clazz(B, {
- hello: function () {
- return "C" + this.super() + "C";
- }
- });
- var D = clazz(B, {
- hello: function () {
- return "D";
- }
- });
- assert.strictEqual(new C().hello(), "CBABC");
- assert.strictEqual(new D().hello(), "D");
- });
- QUnit.test("super - constructors", function (assert) {
- var A = clazz(Object, {
- construct: function () {
- this.message = "A";
- }
- });
- var B = clazz(A, {
- construct: function () {
- this.super();
- this.message = "B" + this.message + "B";
- }
- });
- var C = clazz(B, {
- construct: function () {
- this.super();
- this.message = "C" + this.message + "C";
- }
- });
- var D = clazz(B, {
- construct: function () {
- this.message = "D";
- }
- });
- assert.strictEqual(new C().message, "CBABC");
- assert.strictEqual(new D().message, "D");
- });
- QUnit.test("inheritance", function (assert) {
- var counter = 0;
- var A = clazz(Object, {
- hello: function () {
- return "A";
- }
- });
- var B = clazz(A, {
- });
- var a = new A(), b = new B();
- assert.ok(a.hello() === "A", "instance of A has hello()");
- assert.ok(b.hello() === "A", "instance of B has hello()");
- assert.ok(b instanceof B, "b is instance of B");
- assert.ok(b instanceof Object, "b is instance of Object");
- assert.ok(b instanceof A, "b is instance of A");
- });
- QUnit.test("initialization", function (assert) {
- var counter = 0;
- var A = clazz(Object, {
- construct: function () {
- counter++;
- }
- });
- var B = clazz(A, {
- });
- assert.strictEqual(counter, 0);
- var a = new A();
- assert.strictEqual(counter, 1);
- var b = new B();
- assert.strictEqual(counter, 2);
- });
|