Skip to content

Commit

Permalink
[TIMOB-15031] Added mocha unit tests for cloning and moved old unit t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
nebrius committed Sep 4, 2013
1 parent 5af3ea2 commit fad5a6b
Show file tree
Hide file tree
Showing 385 changed files with 244 additions and 3 deletions.
144 changes: 142 additions & 2 deletions lib/Base.js
Expand Up @@ -201,7 +201,36 @@ function isType(value, types) {
*/
exports.cloneValue = cloneValue;
function cloneValue(source) {
throw new Error('Not Implemented');
switch(source.className) {
case 'Undefined':
return cloneUndefined(source);
case 'Null':
return cloneNull(source);
case 'String':
return cloneString(source);
case 'Number':
return cloneNumber(source);
case 'Boolean':
return cloneBoolean(source);
case 'Object':
return cloneObject(source);
case 'Function':
return cloneFunction(source);
case 'Array':
return cloneArray(source);
case 'RegExp':
return cloneRegExp(source);
case 'Date':
return cloneDate(source);
case 'Error':
return cloneError(source);
case 'Reference':
return cloneReference(source);
case 'Unknown':
return cloneUnknown(source);
default:
throw new Error('Internal Error: Cannot clone value of unknown class type "' + source.className + '"');
}
}

// ******** Base Type Class ********
Expand Down Expand Up @@ -328,6 +357,17 @@ BaseType
*
*****************************************/

/**
* Clones an unknown value
*
* @method
* @param {module:Base.UnknownType} source The unknown value to clone
*/
exports.cloneUnknown = cloneUnknown;
function cloneUnknown(source) {
throw new Error('Not Implemented');
}

/**
* @classdesc Represents an unknown type. Types are considered to be 'unknown' if their value cannot be determined at
* compile time and are unique to this implementation. There is no equivalent in the ECMA-262 spec.
Expand Down Expand Up @@ -360,6 +400,17 @@ BaseType
*
*****************************************/

/**
* Clones an undefined value
*
* @method
* @param {module:Base.UndefinedType} source The undefined value to clone
*/
exports.cloneUndefined = cloneUndefined;
function cloneUndefined() {
return new UndefinedType();
}

/**
* @classdesc An undefined type.
*
Expand Down Expand Up @@ -387,6 +438,17 @@ BaseType
*
*****************************************/

/**
* Clones an null value
*
* @method
* @param {module:Base.NullType} source The null value to clone
*/
exports.cloneNull = cloneNull;
function cloneNull() {
return new NullType();
}

/**
* @classdesc A null type.
*
Expand Down Expand Up @@ -417,6 +479,17 @@ prototypes
*
*****************************************/

/**
* Clones a number value
*
* @method
* @param {module:Base.NumberType} source The number value to clone
*/
exports.cloneNumber = cloneNumber;
function cloneNumber(source) {
return new NumberType(source.value);
}

/**
* @classdesc A number type.
*
Expand Down Expand Up @@ -463,6 +536,17 @@ isUndefined
*
*****************************************/

/**
* Clones a boolean value
*
* @method
* @param {module:Base.BooleanType} source The boolean value to clone
*/
exports.cloneBoolean = cloneBoolean;
function cloneBoolean(source) {
return new BooleanType(source.value);
}

/**
* @classdesc A boolean type.
*
Expand Down Expand Up @@ -511,6 +595,17 @@ BaseType
*
*****************************************/

/**
* Clones a string value
*
* @method
* @param {module:Base.StringType} source The string value to clone
*/
exports.cloneString = cloneString;
function cloneString(source) {
return new StringType(source.value);
}

/**
* @classdesc A string type.
*
Expand Down Expand Up @@ -1316,6 +1411,17 @@ positiveIntegerRegEx
*
*****************************************/

/**
* Clones an array
*
* @method
* @param {module:Base.ArrayType} source The array to clone
*/
exports.cloneArray = cloneArray;
function cloneArray(source) {
throw new Error('Not Implemented');
}

/**
* @classdesc An array type.
*
Expand Down Expand Up @@ -1403,6 +1509,17 @@ StringType
*
*****************************************/

/**
* Clones a regexp
*
* @method
* @param {module:Base.RegExpType} source The regexp to clone
*/
exports.cloneRegExp = cloneRegExp;
function cloneRegExp(source) {
throw new Error('Not Implemented');
}

// ******** RegExp Type Class ********

/**
Expand Down Expand Up @@ -1500,6 +1617,17 @@ getModuleContext
*
*****************************************/

/**
* Clones a function
*
* @method
* @param {module:Base.FunctionType} source The function to clone
*/
exports.cloneFunction = cloneFunction;
function cloneFunction(source) {
throw new Error('Not Implemented');
}

// ******** Function Type Base Class ********

/**
Expand Down Expand Up @@ -1785,7 +1913,8 @@ UndefinedType,
isDataDescriptor,
throwNativeException,
isAccessorDescriptor,
globalObject
globalObject,
cloneValue
*/

/*****************************************
Expand All @@ -1794,6 +1923,17 @@ globalObject
*
*****************************************/

/**
* Clones a reference
*
* @method
* @param {module:Base.ReferenceType} source The reference to clone
*/
exports.cloneReference = cloneReference;
function cloneReference(source) {
return new ReferenceType(cloneValue(source.value), source.referencedName, source.strictReference);
}

/**
* @classdesc ECMA-262 Spec: <em>The Reference type is used to explain the behaviour of such operators as delete, typeof,
* and the assignment operators. For example, the left-hand operand of an assignment is expected to produce a reference.
Expand Down
2 changes: 2 additions & 0 deletions lib/base/base.js
Expand Up @@ -208,6 +208,8 @@ function cloneValue(source) {
return cloneString(source);
case 'Number':
return cloneNumber(source);
case 'Boolean':
return cloneBoolean(source);
case 'Object':
return cloneObject(source);
case 'Function':
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -26,7 +26,8 @@
},
"devDependencies": {
"commander": "1.2.x",
"dnode": "1.0.x"
"dnode": "1.0.x",
"should": "1.2.x"
},
"engine": {
"node": ">=0.8"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit fad5a6b

Please sign in to comment.