Skip to content

Commit

Permalink
Merge pull request #31 from mohayonao/console-post
Browse files Browse the repository at this point in the history
add String#post
  • Loading branch information
mohayonao committed May 12, 2014
2 parents 1fa871e + 82730c5 commit fdea54d
Show file tree
Hide file tree
Showing 16 changed files with 379 additions and 35 deletions.
103 changes: 94 additions & 9 deletions build/scscript.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function(global) {
"use strict";

var sc = { VERSION: "0.0.21" };
var sc = { VERSION: "0.0.22" };

// src/sc/sc.js
(function(sc) {
Expand All @@ -18,6 +18,16 @@ var sc = { VERSION: "0.0.21" };
installer(sc);
};

// istanbul ignore next
SCScript.stdout = function(msg) {
console.log(msg);
};

// istanbul ignore next
SCScript.stderr = function(msg) {
console.error(msg);
};

SCScript.VERSION = sc.VERSION;

global.SCScript = sc.SCScript = SCScript;
Expand Down Expand Up @@ -3975,6 +3985,29 @@ var sc = { VERSION: "0.0.21" };

})(sc);

// src/sc/lang/io.js
(function(sc) {

var io = {};

var SCScript = sc.SCScript;
var buffer = "";

io.post = function(msg) {
var items;

items = (buffer + msg).split("\n");
buffer = items.pop();

items.forEach(function(msg) {
SCScript.stdout(msg);
});
};

sc.lang.io = io;

})(sc);

// src/sc/lang/dollarSC.js
(function(sc) {

Expand Down Expand Up @@ -4233,6 +4266,7 @@ var sc = { VERSION: "0.0.21" };
newClass._Spec = constructor;
constructor.prototype.__class = newClass;
constructor.prototype.__Spec = constructor;
constructor.prototype.__className = className;

metaClass._Spec = constructor;
metaClass._isMetaClass = true;
Expand Down Expand Up @@ -5009,10 +5043,27 @@ var sc = { VERSION: "0.0.21" };
};

// TODO: implements dump
// TODO: implements post
// TODO: implements postln
// TODO: implements postc
// TODO: implements postcln

spec.post = function() {
this.asString().post();
return this;
};

spec.postln = function() {
this.asString().postln();
return this;
};

spec.postc = function() {
this.asString().postc();
return this;
};

spec.postcln = function() {
this.asString().postcln();
return this;
};

// TODO: implements postcs
// TODO: implements totalFree
// TODO: implements largestFreeBlock
Expand Down Expand Up @@ -9932,6 +9983,17 @@ var sc = { VERSION: "0.0.21" };
// TODO: implements writeInputSpec
// TODO: implements case
// TODO: implements makeEnvirValPairs

spec.asString = function() {
var items = [];
this.do($SC.Function(function($elem) {
items.push($elem.__str__());
}));

return $SC.String(
this.__className + "[ " + items.join(", ") + " ]"
);
};
});

})(sc);
Expand Down Expand Up @@ -12288,6 +12350,12 @@ var sc = { VERSION: "0.0.21" };
spec.includes = function($item) {
return $SC.Boolean(this._.indexOf($item) !== -1);
};

spec.asString = function() {
return $SC.String("[ " + this._.map(function(elem) {
return elem.__str__();
}).join(", ") + " ]");
};
});

sc.lang.klass.refine("RawArray", function(spec, utils) {
Expand All @@ -12307,6 +12375,7 @@ var sc = { VERSION: "0.0.21" };
(function(sc) {

var fn = sc.lang.fn;
var io = sc.lang.io;
var $SC = sc.lang.$SC;

sc.lang.klass.refine("String", function(spec, utils) {
Expand Down Expand Up @@ -12476,10 +12545,26 @@ var sc = { VERSION: "0.0.21" };
return $SC("String");
};

// TODO: implements postln
// TODO: implements post
// TODO: implements postcln
// TODO: implements postc
spec.postln = function() {
io.post(this.__str__() + "\n");
return this;
};

spec.post = function() {
io.post(this.__str__());
return this;
};

spec.postcln = function() {
io.post("// " + this.__str__() + "\n");
return this;
};

spec.postc = function() {
io.post("// " + this.__str__());
return this;
};

// TODO: implements postf
// TODO: implements format
// TODO: implements matchRegexp
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scscript",
"version": "0.0.21",
"version": "0.0.22",
"author": "Nao Yonamine <mohayonao@gmail.com>",
"homepage": "http://mohayonao.github.io/SCScript/",
"bugs": "https://github.com/mohayonao/SCScript/issues",
Expand Down
1 change: 1 addition & 0 deletions src/sc/lang/classlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require("./klass");
require("./iterator");
require("./fn");
require("./io");
require("../libs/random");
require("../libs/mathlib");

Expand Down
6 changes: 6 additions & 0 deletions src/sc/lang/classlib/Collections/ArrayedCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,12 @@
spec.includes = function($item) {
return $SC.Boolean(this._.indexOf($item) !== -1);
};

spec.asString = function() {
return $SC.String("[ " + this._.map(function(elem) {
return elem.__str__();
}).join(", ") + " ]");
};
});

sc.lang.klass.refine("RawArray", function(spec, utils) {
Expand Down
8 changes: 8 additions & 0 deletions src/sc/lang/classlib/Collections/ArrayedCollection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,14 @@
},
]);
});
it("#asString", function() {
var instance, test;

instance = this.createInstance([ 1, 2, 3 ]);

test = instance.asString();
expect(test).to.be.a("SCString").that.equals("[ 1, 2, 3 ]");
});
});

describe("SCRawArray", function() {
Expand Down
11 changes: 11 additions & 0 deletions src/sc/lang/classlib/Collections/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,17 @@
// TODO: implements writeInputSpec
// TODO: implements case
// TODO: implements makeEnvirValPairs

spec.asString = function() {
var items = [];
this.do($SC.Function(function($elem) {
items.push($elem.__str__());
}));

return $SC.String(
this.__className + "[ " + items.join(", ") + " ]"
);
};
});

})(sc);
8 changes: 8 additions & 0 deletions src/sc/lang/classlib/Collections/Collection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1208,5 +1208,13 @@
});
it.skip("#makeEnvirValPairs", function() {
});
it("#asString", function() {
var instance, test;

instance = this.createInstance([ 1, 2, 3 ]);

test = instance.asString();
expect(test).to.be.a("SCString").that.equals("Array[ 1, 2, 3 ]");
});
});
})();
25 changes: 21 additions & 4 deletions src/sc/lang/classlib/Collections/String.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require("./ArrayedCollection");

var fn = sc.lang.fn;
var io = sc.lang.io;
var $SC = sc.lang.$SC;

sc.lang.klass.refine("String", function(spec, utils) {
Expand Down Expand Up @@ -173,10 +174,26 @@
return $SC("String");
};

// TODO: implements postln
// TODO: implements post
// TODO: implements postcln
// TODO: implements postc
spec.postln = function() {
io.post(this.__str__() + "\n");
return this;
};

spec.post = function() {
io.post(this.__str__());
return this;
};

spec.postcln = function() {
io.post("// " + this.__str__() + "\n");
return this;
};

spec.postc = function() {
io.post("// " + this.__str__());
return this;
};

// TODO: implements postf
// TODO: implements format
// TODO: implements matchRegexp
Expand Down
52 changes: 44 additions & 8 deletions src/sc/lang/classlib/Collections/String_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,50 @@
test = instance.species();
expect(test).to.equal(SCString);
});
it.skip("#postln", function() {
});
it.skip("#post", function() {
});
it.skip("#postcln", function() {
});
it.skip("#postc", function() {
});
it("#postln", sinon.test(function() {
var instance, test;

this.stub(sc.lang.io, "post");

instance = this.createInstance("post");

test = instance.postln();
expect(test).to.equal(instance);
expect(sc.lang.io.post).to.be.calledWith("post\n");
}));
it("#post", sinon.test(function() {
var instance, test;

this.stub(sc.lang.io, "post");

instance = this.createInstance("post");

test = instance.post();
expect(test).to.equal(instance);
expect(sc.lang.io.post).to.be.calledWith("post");
}));
it("#postcln", sinon.test(function() {
var instance, test;

this.stub(sc.lang.io, "post");

instance = this.createInstance("post");

test = instance.postcln();
expect(test).to.equal(instance);
expect(sc.lang.io.post).to.be.calledWith("// post\n");
}));
it("#postc", sinon.test(function() {
var instance, test;

this.stub(sc.lang.io, "post");

instance = this.createInstance("post");

test = instance.postc();
expect(test).to.equal(instance);
expect(sc.lang.io.post).to.be.calledWith("// post");
}));
it.skip("#postf", function() {
});
it.skip("#format", function() {
Expand Down
44 changes: 43 additions & 1 deletion src/sc/lang/classlib/Core/Kernel_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,50 @@

require("./Kernel");

describe("class Kernel", function() {
var $SC = sc.lang.$SC;

describe("SCKernel", function() {
it.skip("write later", function() {
});
});

describe("SCInterpreter", function() {
var SCInterpreter, $interpreter;
before(function() {
SCInterpreter = $SC("Interpreter");
$interpreter = sc.lang.klass.$interpreter;
});
it(".new", function() {
expect(function() {
SCInterpreter.new();
}).to.throw("Interpreter.new is illegal.");
});
it("#<>a..z / #clearAll", function() {
var instance;

instance = $interpreter;

"abcdefghijklmnopqrstuvwxyz".split("").forEach(function(ch) {
var test, $value;

$value = sc.test.object();

test = instance[ch]();
expect(test).to.be.a("SCNil");

test = instance[ch + "_"]($value);
expect(test).to.equal(instance);

test = instance[ch]();
expect(test).to.equal($value);
});

instance.clearAll();

"abcdefghijklmnopqrstuvwxyz".split("").forEach(function(ch) {
var test = instance[ch]();
expect(test).to.be.a("SCNil");
});
});
});
})();
Loading

0 comments on commit fdea54d

Please sign in to comment.