Permalink
Browse files

test toJs toString eval_ and _expand

  • Loading branch information...
marianoguerra committed Jun 29, 2012
1 parent 24daf7b commit ce0080e9c90b7980e59b9949ca7a55abb1abda0f
Showing with 36 additions and 5 deletions.
  1. +36 −5 test/squim.pair.test.js
View
@@ -1,20 +1,20 @@
-/*global define QUnit SquimTypes*/
+/*global define QUnit SquimTypes SquimGround*/
(function (root, factory) {
"use strict";
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
- define(['qunit', 'squim.types'], function (Q, Types) {
+ define(['qunit', 'squim.types', 'squim.ground'], function (Q, Types, Ground) {
// Also create a global in case some scripts
// that are loaded still are looking for
// a global even when an AMD loader is in use.
- return (root.SquimPairTest = factory(Q, Types));
+ return (root.SquimPairTest = factory(Q, Types, Ground));
});
} else {
// Browser globals
- root.SquimPairTest = factory(QUnit, SquimTypes);
+ root.SquimPairTest = factory(QUnit, SquimTypes, SquimGround);
}
-}(this, function (Q, Types) {
+}(this, function (Q, Types, Ground) {
"use strict";
var obj = {}, Pair = Types.Pair;
@@ -42,6 +42,37 @@
Q.test("nil instance representation is '()'", function () {
Q.equal(Pair.nil.toString(), "()");
});
+
+ Q.test("toJs returns a js representation of a pair", function () {
+ Q.deepEqual((new Pair(new Types.Int(1), new Pair(new Types.Int(2), Pair.nil))).toJs(), [1, 2]);
+ });
+
+ Q.test("toStrings returns a readable representation of a pair", function () {
+ Q.deepEqual((new Pair(new Types.Int(1), new Pair(new Types.Int(2), Pair.nil))).toString(), "(1 2)");
+ });
+
+ Q.test("_expand returns a list with the values evaluated in env", function () {
+ var
+ pair = new Pair(new Types.Symbol("foo"), new Pair(new Types.Symbol("bar"), Pair.nil)),
+ env = new Types.Env();
+
+ env.define("foo", new Types.Int(1));
+ env.define("bar", new Types.Int(2));
+
+ Q.deepEqual(pair._expand(env).toString(), "(1 2)");
+ });
+
+ Q.test("eval_ evaluates a pair in env", function () {
+ var
+ // (list foo bar)
+ pair = new Pair(new Types.Symbol("list"), new Pair(new Types.Symbol("foo"), new Pair(new Types.Symbol("bar"), Pair.nil))),
+ env = Ground.makeGround();
+
+ env.define("foo", new Types.Int(1));
+ env.define("bar", new Types.Int(2));
+
+ Q.deepEqual(pair.eval_(env).toString(), "(1 2)");
+ });
};
return obj;

0 comments on commit ce0080e

Please sign in to comment.