-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from mohayonao/classlib
add basic classes, but almost methods haven't been implemented yet.
- Loading branch information
Showing
63 changed files
with
1,705 additions
and
60 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(function(sc) { | ||
"use strict"; | ||
|
||
require("./ArrayedCollection"); | ||
|
||
var $SC = sc.lang.$SC; | ||
|
||
function Array(value) { | ||
this.__initializeWith__("ArrayedCollection"); | ||
this._class = $SC.Class("Array"); | ||
this._raw = value || []; | ||
} | ||
|
||
sc.lang.klass.define("Array", "ArrayedCollection", { | ||
constructor: Array | ||
}); | ||
|
||
$SC.Array = function(value) { | ||
return new Array(value); | ||
}; | ||
|
||
})(sc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use strict"; | ||
|
||
require("./Array"); | ||
|
||
var $SC = sc.lang.$SC; | ||
|
||
describe("class Array", function() { | ||
var Array; | ||
before(function() { | ||
Array = $SC.Class("Array"); | ||
}); | ||
describe("$SC.Array", function() { | ||
it("should return instance of Array", function() { | ||
var instance = $SC.Array(); | ||
expect(String(instance)).to.be.equal("instance of Array"); | ||
}); | ||
}); | ||
describe(".new", function() { | ||
it("should return empty Array", function() { | ||
var test = Array.new("gremlin").js(); | ||
expect(test).to.be.deep.equal([]); | ||
}); | ||
}); | ||
describe("#js", function() { | ||
it("should return JavaScript array", function() { | ||
var list = [ "freq", 440 ]; | ||
var test = $SC.Array(list).js(); | ||
expect(test).to.be.equal(list); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(function(sc) { | ||
"use strict"; | ||
|
||
require("./SequenceableCollection"); | ||
|
||
sc.lang.klass.define("ArrayedCollection", "SequenceableCollection"); | ||
|
||
sc.lang.klass.define("RawArray", "ArrayedCollection"); | ||
|
||
})(sc); |
13 changes: 13 additions & 0 deletions
13
src/sc/lang/classlib/Collections/ArrayedCollection_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"use strict"; | ||
|
||
require("./ArrayedCollection"); | ||
|
||
describe("class ArrayedCollection", function() { | ||
it.skip("write later", function() { | ||
}); | ||
}); | ||
|
||
describe("class RawArray", function() { | ||
it.skip("write later", function() { | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(function(sc) { | ||
"use strict"; | ||
|
||
require("../Core/Object"); | ||
|
||
sc.lang.klass.define("Collection", "Object"); | ||
|
||
})(sc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"use strict"; | ||
|
||
require("./Collection"); | ||
|
||
describe("class Collection", function() { | ||
it.skip("write later", function() { | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
(function(sc) { | ||
"use strict"; | ||
|
||
require("./Set"); | ||
|
||
var $SC = sc.lang.$SC; | ||
|
||
function Dictionary(value) { | ||
this.__initializeWith__("Set"); | ||
this._class = $SC.Class("Dictionary"); | ||
this._raw = value || {}; | ||
} | ||
|
||
sc.lang.klass.define("Dictionary", "Set", { | ||
constructor: Dictionary | ||
}); | ||
|
||
sc.lang.klass.define("IdentityDictionary", "Dictionary"); | ||
|
||
$SC.Dictionary = function(value) { | ||
return new Dictionary(value); | ||
}; | ||
|
||
})(sc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"use strict"; | ||
|
||
require("./Dictionary"); | ||
|
||
var $SC = sc.lang.$SC; | ||
|
||
describe("class Dictionary", function() { | ||
var Dictionary; | ||
before(function() { | ||
Dictionary = $SC.Class("Dictionary"); | ||
}); | ||
describe("$SC.Dictionary", function() { | ||
it("should return instance of Dictionary", function() { | ||
var instance = $SC.Dictionary(); | ||
expect(String(instance)).to.be.equal("instance of Dictionary"); | ||
}); | ||
}); | ||
describe(".new", function() { | ||
it("should return empty Dictionary", function() { | ||
var test = Dictionary.new("gremlin").js(); | ||
expect(test).to.be.deep.equal({}); | ||
}); | ||
}); | ||
describe("#js", function() { | ||
it("should return JavaScript object", function() { | ||
var dict = { freq: 440 }; | ||
var test = $SC.Dictionary(dict).js(); | ||
expect(test).to.be.equal(dict); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("class IdentityDictionary", function() { | ||
it.skip("write later", function() { | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(function(sc) { | ||
"use strict"; | ||
|
||
require("./Dictionary"); | ||
|
||
sc.lang.klass.define("Environment", "IdentityDictionary"); | ||
|
||
})(sc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"use strict"; | ||
|
||
require("./Environment"); | ||
|
||
describe("class Environment", function() { | ||
it.skip("write later", function() { | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(function(sc) { | ||
"use strict"; | ||
|
||
require("./Environment"); | ||
|
||
sc.lang.klass.define("Event", "Environment"); | ||
|
||
})(sc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"use strict"; | ||
|
||
require("./Event"); | ||
|
||
describe("class Event", function() { | ||
it.skip("write later", function() { | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(function(sc) { | ||
"use strict"; | ||
|
||
require("./Collection"); | ||
|
||
sc.lang.klass.define("SequenceableCollection", "Collection"); | ||
|
||
})(sc); |
8 changes: 8 additions & 0 deletions
8
src/sc/lang/classlib/Collections/SequenceableCollection_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"use strict"; | ||
|
||
require("./SequenceableCollection"); | ||
|
||
describe("class SequenceableCollection", function() { | ||
it.skip("write later", function() { | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(function(sc) { | ||
"use strict"; | ||
|
||
require("./Collection"); | ||
|
||
sc.lang.klass.define("Set", "Collection"); | ||
|
||
})(sc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"use strict"; | ||
|
||
require("./Set"); | ||
|
||
describe("class Set", function() { | ||
it.skip("write later", function() { | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
(function(sc) { | ||
"use strict"; | ||
|
||
require("./ArrayedCollection"); | ||
|
||
var jsString = global.String; | ||
var $SC = sc.lang.$SC; | ||
|
||
var instances = {}; | ||
|
||
function String(value) { | ||
if (instances[value]) { | ||
return instances[value]; | ||
} | ||
// TODO: array? | ||
this.__initializeWith__("RawArray"); | ||
this._class = $SC.Class("String"); | ||
this._raw = value; | ||
instances[value] = this; | ||
} | ||
|
||
sc.lang.klass.define("String", "RawArray", { | ||
constructor: String, | ||
$new: function() { | ||
throw new Error("String.new is illegal, should use literal."); | ||
}, | ||
__str__: function() { | ||
return this._raw; | ||
} | ||
}); | ||
|
||
$SC.String = function(value) { | ||
return new String(jsString(value)); // jshint ignore: line | ||
}; | ||
|
||
})(sc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"use strict"; | ||
|
||
require("./String"); | ||
|
||
var $SC = sc.lang.$SC; | ||
|
||
describe("class String", function() { | ||
describe("$SC.String", function() { | ||
it("should return instance of String", function() { | ||
var instance = $SC.String("str"); | ||
expect(String(instance)).to.be.equal("instance of String"); | ||
}); | ||
}); | ||
describe("instance", function() { | ||
it("should be shared", function() { | ||
var a = $SC.String("str0"); | ||
var b = $SC.String("str0"); | ||
var c = $SC.String("str1"); | ||
expect(a).to.be.equal(b); | ||
expect(b).to.be.not.equal(c); | ||
}); | ||
}); | ||
describe(".new", function() { | ||
it("should throw error", function() { | ||
expect(function() { | ||
$SC.Class("String").new(); | ||
}).to.throw("String.new is illegal"); | ||
}); | ||
}); | ||
describe("#js", function() { | ||
it("should return JavaScript string", function() { | ||
var test = $SC.String("str").js(); | ||
expect(test).to.be.equal("str"); | ||
}); | ||
}); | ||
describe("#__str__", function() { | ||
it("should return JavaScript string", function() { | ||
var test = $SC.String("str").__str__(); | ||
expect(test).to.be.equal("str"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require("./Array"); | ||
require("./ArrayedCollection"); | ||
require("./Collection"); | ||
require("./Dictionary"); | ||
require("./Environment"); | ||
require("./Event"); | ||
require("./SequenceableCollection"); | ||
require("./Set"); | ||
require("./String"); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(function(sc) { | ||
"use strict"; | ||
|
||
require("./Object"); | ||
|
||
sc.lang.klass.define("AbstractFunction", "Object"); | ||
|
||
})(sc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"use strict"; | ||
|
||
require("./AbstractFunction"); | ||
|
||
describe("class AbstractFunction", function() { | ||
it.skip("write later", function() { | ||
}); | ||
}); |
Oops, something went wrong.