예제 #1
0
        public void CompareToOtherVariables()
        {
            Machine machine = new Machine();
            machine.CreateNamespace("foo");
            machine.CreateNamespace("bar");

            Variable variableBar = Variable.Intern(machine, "bar", "bar");
            Variable variableFooBar = Variable.Intern(machine, "foo", "bar");
            Variable variableBarFoo = Variable.Intern(machine, "bar", "foo");

            Assert.AreEqual(0, variableBar.CompareTo(variableBar));
            Assert.AreEqual(0, variableFooBar.CompareTo(variableFooBar));

            Assert.AreEqual(-1, variableBar.CompareTo(variableFooBar));
            Assert.AreEqual(1, variableFooBar.CompareTo(variableBar));

            Assert.AreEqual(1, variableFooBar.CompareTo(variableBarFoo));
            Assert.AreEqual(-1, variableBarFoo.CompareTo(variableFooBar));
        }
예제 #2
0
        public void BeNotEqualToVariableWithOtherName()
        {
            Machine machine = new Machine();
            machine.CreateNamespace("foo");

            Variable variable = Variable.Intern(machine, "foo/bar");
            Variable variable2 = Variable.Intern(machine, "foo/bar2");

            Assert.AreNotEqual(variable, variable2);
        }
예제 #3
0
        public void BeEqualToVariableWithSameNameAndNamespace()
        {
            Machine machine = new Machine();
            machine.CreateNamespace("foo");

            Variable variable = Variable.Intern(machine, "foo", "bar");
            Variable variable2 = Variable.Intern(machine, "foo", "bar");

            Assert.AreEqual(variable, variable2);
            Assert.AreEqual(variable.GetHashCode(), variable2.GetHashCode());
        }
예제 #4
0
        public void BeEquals()
        {
            Machine machine = new Machine();
            machine.CreateNamespace("foo");

            Variable var1 = Variable.Intern(machine, "foo", "bar");
            Variable var2 = Variable.Intern(machine, "foo", "bar");
            Variable var3 = Variable.Intern(machine, "foo/bar");

            Assert.IsTrue(var1.Equals(var2));
            Assert.IsTrue(var2.Equals(var1));
            Assert.IsTrue(var1.Equals(var3));
            Assert.IsTrue(var3.Equals(var1));
            Assert.IsTrue(var2.Equals(var3));
            Assert.IsTrue(var3.Equals(var2));
        }
예제 #5
0
        public void CreateAVariable()
        {
            Machine machine = new Machine();
            machine.CreateNamespace("foo");

            Variable var = Variable.Intern(machine, "foo", "bar");

            Assert.IsNotNull(var);
            Assert.AreEqual("foo", var.Namespace);
            Assert.AreEqual("bar", var.Name);
            Assert.AreEqual(Utilities.GetFullName("foo", "bar"), var.FullName);

            Variable var2 = Variable.Intern(machine, "foo", "bar");

            Assert.IsNotNull(var2);
            Assert.IsTrue(var.Equals(var2));
        }
예제 #6
0
        public void SetMacroOnDefinedMultiFunction()
        {
            Machine machine = new Machine();
            machine.CreateNamespace("ns");
            FnStarPrimitive fnprim = new FnStarPrimitive();
            Parser parser = new Parser("([x] (+ x 1)) ([x y] (+ x y 1))");

            object[] parameters = new object[2];
            parameters[0] = parser.ParseForm();
            parameters[1] = parser.ParseForm();

            object result = fnprim.Apply(machine, machine.Environment, parameters);
            DefinedMultiFunction multifn = (DefinedMultiFunction)result;

            Variable variable = Variable.Intern(machine, "ns/func");

            machine.SetVariableValue(variable, multifn);

            variable.SetMacro(machine);

            object mresult = machine.GetVariableValue(variable);

            Assert.IsNotNull(mresult);
            Assert.IsInstanceOfType(mresult, typeof(DefinedMultiMacro));
        }
예제 #7
0
        public void SetMacroOnDefinedFunction()
        {
            Machine machine = new Machine();
            machine.CreateNamespace("ns");

            Variable variable = Variable.Intern(machine, "ns/func");

            Parser parser = new Parser("[x y] (list x y) 1 2");
            object argumentNames = parser.ParseForm();
            object body = parser.ParseForm();

            DefinedFunction func = new DefinedFunction("simple-list", (ICollection)argumentNames, Utilities.ToExpression(body));

            machine.SetVariableValue(variable, func);

            variable.SetMacro(machine);

            object result = machine.GetVariableValue(variable);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(DefinedMacro));
        }
예제 #8
0
        public void ResetVariableMetadata()
        {
            Machine machine = new Machine();
            machine.CreateNamespace("foo");

            Variable variable = Variable.Intern(machine, "foo/bar");

            variable.ResetMetadata(FakePersistentMap.Instance);

            Assert.IsNotNull(variable.Metadata);
            Assert.IsTrue(variable.Metadata == FakePersistentMap.Instance);
        }
예제 #9
0
        public void CreateWithNameAndNamespace()
        {
            Machine machine = new Machine();
            machine.CreateNamespace("foo");

            Variable variable = Variable.Intern(machine, "foo", "bar");

            Assert.IsNotNull(variable);
            Assert.AreEqual("foo", variable.Namespace);
            Assert.AreEqual("bar", variable.Name);
            Assert.AreEqual("foo/bar", variable.FullName);
        }
예제 #10
0
        public void CreateVariableWithNullMetadata()
        {
            Machine machine = new Machine();
            machine.CreateNamespace("foo");

            Variable variable = Variable.Intern(machine, "foo/bar");
            IObject iobj = variable.WithMetadata(null);

            Assert.IsNotNull(iobj);
            Assert.IsTrue(variable == iobj);
        }
예제 #11
0
        public void CreateVariableWithMetadata()
        {
            Machine machine = new Machine();
            machine.CreateNamespace("foo");

            Variable variable = Variable.Intern(machine, "foo/bar");

            IObject iobj = variable.WithMetadata(FakePersistentMap.Instance);

            Assert.IsNotNull(iobj);
            Assert.IsTrue(variable != iobj);
            Assert.IsNotNull(iobj.Metadata);
            Assert.IsTrue(iobj.Metadata == FakePersistentMap.Instance);
        }