Skip to content

Commit

Permalink
Merge pull request #41 from mohayonao/implements-SCDictionary
Browse files Browse the repository at this point in the history
implements SCDictionary
  • Loading branch information
mohayonao committed May 17, 2014
2 parents 67712c9 + bcc791a commit 6f6a4a9
Show file tree
Hide file tree
Showing 14 changed files with 1,910 additions and 228 deletions.
677 changes: 610 additions & 67 deletions build/scscript-classlib.js

Large diffs are not rendered by default.

11 changes: 8 additions & 3 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.31" };
var sc = { VERSION: "0.0.32" };

// src/sc/sc.js
(function(sc) {
Expand Down Expand Up @@ -822,6 +822,11 @@ var sc = { VERSION: "0.0.31" };
// basic classes
function SCObject() {
this._ = this;
Object.defineProperties(this, {
_immutable: {
value: false, writable: true
}
});
}

function SCClass() {
Expand Down Expand Up @@ -1112,10 +1117,10 @@ var sc = { VERSION: "0.0.31" };
return instance;
};

$SC.String = function(value, immutable) {
$SC.String = function(value) {
var instance = new SCString();
instance._ = String(value).split("").map($SC.Char);
instance._immutable = !!immutable;
instance._immutable = true;
return instance;
};

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.31",
"version": "0.0.32",
"author": "Nao Yonamine <mohayonao@gmail.com>",
"homepage": "http://mohayonao.github.io/SCScript/",
"bugs": "https://github.com/mohayonao/SCScript/issues",
Expand Down
10 changes: 9 additions & 1 deletion src/sc/classlib/Collections/ArrayedCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ SCScript.install(function(sc) {

this._ThrowIfImmutable();

if ($aCollection.isSequenceableCollection().valueOf()) {
if (BOOL($aCollection.isCollection())) {
$aCollection.do($SC.Function(function($item) {
$this._.push($this.__elem__($item));
}));
Expand Down Expand Up @@ -760,6 +760,14 @@ SCScript.install(function(sc) {
return $elem.asString().__str__();
}).join(", ") + " ]");
};

// istanbul ignore next
spec._sort = function($function) {
this._ThrowIfImmutable();
this._.sort(function($a, $b) {
return BOOL($function.value($a, $b)) ? -1 : 1;
});
};
});

sc.lang.klass.refine("RawArray", function(spec, utils) {
Expand Down
60 changes: 60 additions & 0 deletions src/sc/classlib/Collections/Association.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
SCScript.install(function(sc) {
"use strict";

require("../Math/Magnitude");

var $SC = sc.lang.$SC;

function SCAssociation(args) {
this.__initializeWith__("Magnitude");
this._key = args.shift() || $SC.Nil();
this._value = args.shift() || $SC.Nil();
}

sc.lang.klass.define(SCAssociation, "Association : Magnitude", function(spec, utils) {
var $nil = utils.$nil;
var $false = utils.$false;

spec.valueOf = function() {
return this._key.valueOf();
};

spec.key = function() {
return this._key;
};

spec.key_ = function($value) {
this._key = $value || /* istanbul ignore next */ $nil;
return this;
};

spec.value = function() {
return this._value;
};

spec.value_ = function($value) {
this._value = $value || /* istanbul ignore next */ $nil;
return this;
};

spec["=="] = function($anAssociation) {
if ($anAssociation.key) {
return this._key ["=="] ($anAssociation.key());
}
return $false;
};

// TODO: implements hash

spec["<"] = function($anAssociation) {
return this._key ["<"] ($anAssociation.key());
};

// TODO: implements printOn
// TODO: implements storeOn
// TODO: implements embedInStream
// TODO: implements transformEvent

});

});
95 changes: 95 additions & 0 deletions src/sc/classlib/Collections/Association_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
(function() {
"use strict";

require("./Association");

var $SC = sc.lang.$SC;

describe("SCAssociation", function() {
var SCAssociation;
before(function() {
SCAssociation = $SC("Association");
this.createInstance = function($key, $value) {
return SCAssociation.new($key, $value);
};
});
it("#valueOf", function() {
var instance, test;

instance = this.createInstance($SC.Integer(1), $SC.Integer(2));

test = instance.valueOf();
expect(test).to.be.a("JSNumber").that.equals(1);
});
it("<>value", function() {
var instance, test;
var $value;

$value = sc.test.object();

instance = this.createInstance();

test = instance.value_($value);
expect(test).to.equal(instance);

test = instance.value();
expect(test).to.equal($value);
});
it("<>key", function() {
var instance, test;
var $key;

$key = sc.test.object();

instance = this.createInstance();

test = instance.key_($key);
expect(test).to.equal(instance);

test = instance.key();
expect(test).to.equal($key);
});
it("#==", function() {
var instance, test;
var $anAssociation;

instance = this.createInstance($SC.Integer(1), $SC.Integer(2));

$anAssociation = $SC.Nil();
test = instance ["=="] ($anAssociation);
expect(test).to.be.a("SCBoolean").that.is.false;

$anAssociation = SCAssociation.new();
test = instance ["=="] ($anAssociation);
expect(test).to.be.a("SCBoolean").that.is.false;

$anAssociation = SCAssociation.new($SC.Integer(1), $SC.Integer(3));
test = instance ["=="] ($anAssociation);
expect(test).to.be.a("SCBoolean").that.is.true;
});
it.skip("#hash", function() {
});
it("#<", function() {
var instance, test;
var $anAssociation;

instance = this.createInstance($SC.Integer(1), $SC.Integer(2));

$anAssociation = SCAssociation.new($SC.Integer(2), $SC.Integer(3));
test = instance ["<"] ($anAssociation);
expect(test).to.be.a("SCBoolean").that.is.true;

$anAssociation = SCAssociation.new($SC.Integer(0), $SC.Integer(3));
test = instance ["<"] ($anAssociation);
expect(test).to.be.a("SCBoolean").that.is.false;
});
it.skip("#printOn", function() {
});
it.skip("#storeOn", function() {
});
it.skip("#embedInStream", function() {
});
it.skip("#transformEvent", function() {
});
});
})();
Loading

0 comments on commit 6f6a4a9

Please sign in to comment.