Ejemplo n.º 1
0
 public void ClassWithSuperclass()
 {
     IClass super = new BaseClass("Object", null);
     IClass klass = new BaseClass("Rectangle", super);
     Assert.AreEqual("Rectangle", klass.Name);
     Assert.AreEqual(super, klass.Super);
 }
Ejemplo n.º 2
0
 public void DefineVariable()
 {
     IClass type = new BaseClass("int", null);
     IClass klass = new BaseClass("MyClass", null);
     klass.DefineVariable("age", type);
     var result = klass.GetVariableType("age");
     Assert.IsNotNull(result);
     Assert.AreEqual(type, result);
 }
Ejemplo n.º 3
0
 public void DefineVariableAndGetVariableFromSuper()
 {
     IClass type = new BaseClass("int", null);
     IClass super = new BaseClass("MySuperclass", null);
     IClass klass = new BaseClass("MyClass", super);
     super.DefineVariable("age", type);
     var result = klass.GetVariableType("age");
     Assert.IsNotNull(result);
     Assert.AreEqual(type, result);
 }
Ejemplo n.º 4
0
 public void DefineMethod()
 {
     IClass type = new BaseClass("String", null);
     IClass klass = new BaseClass("MyClass", null);
     IMethod getname = new FuncMethod(type, (obj, context, arguments) => ((IObject)obj).GetValue("name"));
     klass.DefineMethod("getName", getname);
     var result = klass.GetMethod("getName");
     Assert.IsNotNull(result);
     Assert.AreEqual(type, result.Type);
 }
Ejemplo n.º 5
0
        public void CreateNewInstance()
        {
            IClass klass = new BaseClass("MyClass", null);
            var result = klass.NewInstance(null);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(BaseObject));

            BaseObject obj = (BaseObject)result;
            Assert.AreEqual(klass, obj.Type);
        }
Ejemplo n.º 6
0
 public void Setup()
 {
     IClass type = new BaseClass("String", null);
     this.type = new BaseClass("MyClass", null);
     IMethod getname = new FuncMethod(null, (obj, context, arguments) => ((IObject)obj).GetValue("name"));
     this.type.DefineVariable("name", type);
     this.type.DefineMethod("getName", getname);
 }
Ejemplo n.º 7
0
 public void RaiseIfMethodIsAlreadyDefined()
 {
     IClass type = new BaseClass("String", null);
     IClass klass = new BaseClass("MyClass", null);
     IMethod getname = new FuncMethod(type, (obj, context, arguments) => ((IObject)obj).GetValue("name"));
     klass.DefineMethod("getName", getname);
     klass.DefineMethod("getName", getname);
 }
Ejemplo n.º 8
0
 public void ClassWithoutSuperclass()
 {
     IClass klass = new BaseClass("Object", null);
     Assert.AreEqual("Object", klass.Name);
     Assert.IsNull(klass.Super);
 }
Ejemplo n.º 9
0
 public void UnknowVariableAsNullType()
 {
     IClass klass = new BaseClass("Object", null);
     Assert.IsNull(klass.GetVariableType("a"));
 }
Ejemplo n.º 10
0
 public void RaiseIfVariableIsAlreadyDefined()
 {
     IClass type = new BaseClass("int", null);
     IClass klass = new BaseClass("MyClass", null);
     klass.DefineVariable("age", type);
     klass.DefineVariable("age", type);
 }
Ejemplo n.º 11
0
 public object Execute(Context context)
 {
     IType type = new BaseClass(this.name, (IClass)context.GetValue("Object"));
     context.SetValue(this.name, type);
     return null;
 }