"use strict";

var Class = my.Class;

describe("Classy classes", function() {
  it("creates simple classes", function() {
    var Car = Class({
      constructor: function(color) {
        this.color = color || "red";
      }
    });

    var redCar = new Car();
    expect(redCar.color).toBe("red");

    var blueCar = new Car("blue");
    expect(blueCar.color).toBe("blue");
  });

  it("creates classes with prototypical methods", function() {
    var Car = Class({
      constructor: function(color) {
        this.color = color || "red";
      },

      tellMyColor: function() {
        return "My color is " + this.color;
      }
    });

    var car = new Car();

    expect(car.tellMyColor()).toBe("My color is red");
    expect(car.tellMyColor).toBe(Car.prototype.tellMyColor);
  });

  it("crates inherited classes", function() {
    var Vehicle = Class({
      constructor: function(color) {
        this.color = color || "red";
      },

      vehicleFun: function() {
        return "I'm a vehicle";
      }
    });

    var RoadVehicle = Class(Vehicle, {
      constructor: function(color, numWheels) {
        RoadVehicle.Super.call(this, color);

        this.numWheels = numWheels;
      },

      roadFun: function() {
        return "I'm a road vehicle";
      }
    });

    var bike = new RoadVehicle("blue", 2);
    expect(bike.color).toBe("blue");
    expect(bike.numWheels).toBe(2);
    expect(bike.vehicleFun()).toBe("I'm a vehicle");
    expect(bike.roadFun()).toBe("I'm a road vehicle");
  });

  it("inherits constructors by default", function() {
    var A = Class({
      constructor: function() {
        this.foo = "bar";
      }
    });

    var B = Class(A, {
      getFoo: function() {
        return this.foo;
      }
    });

    var b = new B();
    expect(b.foo).toEqual("bar")
    expect(b.getFoo()).toEqual("bar")
  });
});

@@ -1854,13 +1854,561 @@
 %22)%0A  %7D);
+%0A%0A  it(%22works with instanceof%22, function() %7B%0A    var A = Class(%7B%7D);%0A%0A    var a = new A();%0A%0A    expect(a instanceof A).toEqual(true);%0A  %7D);%0A%0A  it(%22works with instanceof and new%22, function() %7B%0A    var A = new Class(%7B%7D);%0A%0A    var a = new A();%0A%0A    expect(a instanceof A).toEqual(true);%0A  %7D);%0A%0A  it(%22works with instanceof and constructors%22, function() %7B%0A    var A = Class(%7B%0A      constructor: function() %7B%0A        this.foo = %22bar%22;%0A      %7D%0A    %7D);%0A%0A    var a = new A();%0A    expect(a.foo).toEqual(%22bar%22);%0A%0A    expect(a instanceof A).toEqual(true);%0A  %7D);
 %0A%7D);%0A

Test instanceof