Comparing version 0.0.2 to 0.0.3
@@ -7,189 +7,196 @@ /** | ||
var variable=new Variable; | ||
var variable = new Variable; | ||
describe('Проверка метода type:', function(){ | ||
it('false == boolean', function(){ | ||
expect(Variable.type(true)).toBe('boolean'); | ||
expect(Variable.type(false)).toBe('boolean'); | ||
}); | ||
describe('Проверка метода type:', function () { | ||
it('false == boolean', function () { | ||
expect(Variable.type(true)).toBe('boolean'); | ||
expect(Variable.type(false)).toBe('boolean'); | ||
}); | ||
it('1 == number, 1.2 == number, infinity == number, NaN == number:', function(){ | ||
expect(Variable.type(1)).toBe('number'); | ||
expect(Variable.type(1.2)).toBe('number'); | ||
expect(Variable.type(new Number(1))).toBe('number'); | ||
var infinity_number=1/0; | ||
expect(infinity_number).toBe(Infinity); | ||
expect(Variable.type(infinity_number)).toBe('number'); | ||
var nan_number=0/0; | ||
expect(isNaN(nan_number)).toBe(true); | ||
expect(Variable.type(nan_number)).toBe('number'); | ||
expect(Variable.type(new Number(1))).toBe('number'); | ||
}); | ||
it('1 == number, 1.2 == number, infinity == number, NaN == number:', function () { | ||
expect(Variable.type(1)).toBe('number'); | ||
expect(Variable.type(1.2)).toBe('number'); | ||
expect(Variable.type(new Number(1))).toBe('number'); | ||
var infinity_number = 1 / 0; | ||
expect(infinity_number).toBe(Infinity); | ||
expect(Variable.type(infinity_number)).toBe('number'); | ||
var nan_number = 0 / 0; | ||
expect(isNaN(nan_number)).toBe(true); | ||
expect(Variable.type(nan_number)).toBe('number'); | ||
expect(Variable.type(new Number(1))).toBe('number'); | ||
}); | ||
it('"str" == string', function(){ | ||
expect(Variable.type('str')).toBe('string'); | ||
expect(Variable.type(new String('str'))).toBe('string'); | ||
}); | ||
it('"str" == string', function () { | ||
expect(Variable.type('str')).toBe('string'); | ||
expect(Variable.type(new String('str'))).toBe('string'); | ||
}); | ||
it('[] == array', function(){ | ||
expect(Variable.type([1, 3, 'str'])).toBe('array'); | ||
}); | ||
it('[] == array', function () { | ||
expect(Variable.type([1, 3, 'str'])).toBe('array'); | ||
}); | ||
it('{} == object', function(){ | ||
expect(Variable.type(variable)).toBe('object'); | ||
expect(Variable.type({})).toBe('object'); | ||
}); | ||
it('{} == object', function () { | ||
expect(Variable.type(variable)).toBe('object'); | ||
expect(Variable.type({})).toBe('object'); | ||
}); | ||
it('function(){} == function', function(){ | ||
expect(Variable.type(Variable.type)).toBe('function'); | ||
expect(Variable.type(function(){})).toBe('function'); | ||
}); | ||
it('function(){} == function', function () { | ||
expect(Variable.type(Variable.type)).toBe('function'); | ||
expect(Variable.type(function () { | ||
})).toBe('function'); | ||
}); | ||
it('null == null', function(){ | ||
expect(Variable.type(null)).toBe('null'); | ||
}); | ||
it('null == null', function () { | ||
expect(Variable.type(null)).toBe('null'); | ||
}); | ||
it('undefined == undefined', function(){ | ||
var c; | ||
expect(Variable.type(c)).toBe('undefined'); | ||
}); | ||
it('undefined == undefined', function () { | ||
var c; | ||
expect(Variable.type(c)).toBe('undefined'); | ||
}); | ||
it('new Date == date', function(){ | ||
expect(Variable.type(new Date())).toBe('date'); | ||
}); | ||
it('new Date == date', function () { | ||
expect(Variable.type(new Date())).toBe('date'); | ||
}); | ||
}); | ||
describe('Проверка метода empty:', function(){ | ||
it('', function(){ | ||
expect(Variable.empty(null)).toBe(true); | ||
var c; | ||
expect(Variable.empty(c)).toBe(true); | ||
c=1; | ||
expect(Variable.empty(c)).toBe(false); | ||
expect(Variable.empty('')).toBe(true); | ||
expect(Variable.empty(' ')).toBe(false); | ||
expect(Variable.empty('0')).toBe(false); | ||
expect(Variable.empty(new Number())).toBe(false); | ||
expect(Variable.empty(0)).toBe(false); | ||
expect(Variable.empty(1)).toBe(false); | ||
expect(Variable.empty(0.1)).toBe(false); | ||
expect(Variable.empty(0.0)).toBe(false); | ||
expect(Variable.empty(true)).toBe(false); | ||
expect(Variable.empty(false)).toBe(false); | ||
expect(Variable.empty([])).toBe(true); | ||
expect(Variable.empty([1, 2, 'str'])).toBe(false); | ||
expect(Variable.empty({})).toBe(true); | ||
expect(Variable.empty({var : 3})).toBe(false); | ||
}); | ||
describe('Проверка метода empty:', function () { | ||
it('', function () { | ||
expect(Variable.empty(null)).toBe(true); | ||
var c; | ||
expect(Variable.empty(c)).toBe(true); | ||
c = 1; | ||
expect(Variable.empty(c)).toBe(false); | ||
expect(Variable.empty('')).toBe(true); | ||
expect(Variable.empty(' ')).toBe(false); | ||
expect(Variable.empty('0')).toBe(false); | ||
expect(Variable.empty(new Number())).toBe(false); | ||
expect(Variable.empty(0)).toBe(false); | ||
expect(Variable.empty(1)).toBe(false); | ||
expect(Variable.empty(0.1)).toBe(false); | ||
expect(Variable.empty(0.0)).toBe(false); | ||
expect(Variable.empty(true)).toBe(false); | ||
expect(Variable.empty(false)).toBe(false); | ||
expect(Variable.empty([])).toBe(true); | ||
expect(Variable.empty([1, 2, 'str'])).toBe(false); | ||
expect(Variable.empty({})).toBe(true); | ||
expect(Variable.empty({var: 3})).toBe(false); | ||
}); | ||
}); | ||
describe('Проверка метода objectEqual:', function(){ | ||
it('', function(){ | ||
expect(Variable.objectEqual(1, 1)).toBe(true); | ||
expect(Variable.objectEqual(null, null)).toBe(true); | ||
expect(Variable.objectEqual([], [])).toBe(true); | ||
expect(Variable.objectEqual([null, 1], [null, 1])).toBe(true); | ||
expect(Variable.objectEqual({}, {})).toBe(true); | ||
expect(Variable.objectEqual([3], {0 : 3})).toBe(false); | ||
expect(Variable.objectEqual({first : 1, second : 3}, {first : 1, second : 3})).toBe(true); | ||
expect(Variable.objectEqual({first : 1, second : 3}, {second : 3, first : 1})).toBe(true); | ||
expect(Variable.objectEqual([2, 3], [3, 2])).toBe(false); | ||
expect(Variable.objectEqual(0, false)).toBe(true); | ||
expect(Variable.objectEqual(1, '1')).toBe(true); | ||
expect(Variable.objectEqual(1, new String('1'))).toBe(true); | ||
expect(Variable.objectEqual(1, '1', {strict : true})).toBe(false); | ||
expect(Variable.objectEqual([1], [1, function(){}])).toBe(false); | ||
expect(Variable.objectEqual({property : 1}, {property : 1, method : function(){}})).toBe(true); | ||
expect(Variable.objectEqual([new Date()], [new Date()])).toBe(true); | ||
}); | ||
describe('Проверка метода objectEqual:', function () { | ||
it('', function () { | ||
expect(Variable.objectEqual(1, 1)).toBe(true); | ||
expect(Variable.objectEqual(null, null)).toBe(true); | ||
expect(Variable.objectEqual([], [])).toBe(true); | ||
expect(Variable.objectEqual([null, 1], [null, 1])).toBe(true); | ||
expect(Variable.objectEqual({}, {})).toBe(true); | ||
expect(Variable.objectEqual([3], {0: 3})).toBe(false); | ||
expect(Variable.objectEqual({first: 1, second: 3}, {first: 1, second: 3})).toBe(true); | ||
expect(Variable.objectEqual({first: 1, second: 3}, {second: 3, first: 1})).toBe(true); | ||
expect(Variable.objectEqual([2, 3], [3, 2])).toBe(false); | ||
expect(Variable.objectEqual(0, false)).toBe(true); | ||
expect(Variable.objectEqual(1, '1')).toBe(true); | ||
expect(Variable.objectEqual(1, new String('1'))).toBe(true); | ||
expect(Variable.objectEqual(1, '1', {strict: true})).toBe(false); | ||
expect(Variable.objectEqual([1], [1, function () { | ||
}])).toBe(false); | ||
expect(Variable.objectEqual({property: 1}, { | ||
property: 1, method: function () { | ||
} | ||
})).toBe(true); | ||
expect(Variable.objectEqual([new Date()], [new Date()])).toBe(true); | ||
}); | ||
}); | ||
describe('Проверка метода getRandom:', function(){ | ||
it('', function(){ | ||
expect(Variable.getRandom(4, 5.5)).toBeGreaterThan(3.9999); | ||
expect(Variable.getRandom(4, 5.5)).toBeLessThan(5.50001); | ||
}); | ||
describe('Проверка метода getRandom:', function () { | ||
it('', function () { | ||
expect(Variable.getRandom(4, 5.5)).toBeGreaterThan(3.9999); | ||
expect(Variable.getRandom(4, 5.5)).toBeLessThan(5.50001); | ||
}); | ||
}); | ||
describe('Проверка stringToArray: ', function(){ | ||
it('', function(){ | ||
expect(Variable.stringToArray('a,b,c')).toEqual(['a','b','c']); | ||
expect(Variable.stringToArray('a , b, c')).toEqual(['a','b','c']); | ||
expect(Variable.stringToArray('a ; b; c', ';')).toEqual(['a','b','c']); | ||
}); | ||
describe('Проверка stringToArray: ', function () { | ||
it('', function () { | ||
expect(Variable.stringToArray('a,b,c')).toEqual(['a', 'b', 'c']); | ||
expect(Variable.stringToArray('a , b, c')).toEqual(['a', 'b', 'c']); | ||
expect(Variable.stringToArray('a ; b; c', ';')).toEqual(['a', 'b', 'c']); | ||
}); | ||
}); | ||
describe('Проверка uniqueArrayElements: ', function(){ | ||
it('', function(){ | ||
expect(Variable.uniqueArrayElements([1, 0, 1, 0])).toEqual([0, 1]); | ||
expect(Variable.objectEqual(Variable.uniqueArrayElements([0, 1, 0, '1']), [0, 1])).toBe(true); | ||
expect(Variable.objectEqual(Variable.uniqueArrayElements([1, 0, '0', '0'], {strict: true}), [0, '0', 1], {strict: true})).toBe(true); | ||
expect(Variable.uniqueArrayElements([1, '0'])).toEqual(['0', 1]); | ||
}); | ||
describe('Проверка uniqueArrayElements: ', function () { | ||
it('', function () { | ||
expect(Variable.uniqueArrayElements([1, 0, 1, 0])).toEqual([0, 1]); | ||
expect(Variable.objectEqual(Variable.uniqueArrayElements([0, 1, 0, '1']), [0, 1])).toBe(true); | ||
expect(Variable.objectEqual(Variable.uniqueArrayElements([1, 0, '0', '0'], {strict: true}), [0, '0', 1], {strict: true})).toBe(true); | ||
expect(Variable.uniqueArrayElements([1, '0'])).toEqual(['0', 1]); | ||
}); | ||
}); | ||
describe('Проверка replaceAll: ', function(){ | ||
it('', function(){ | ||
expect(Variable.replaceAll('a df as', {'a': 'b'})).toBe('b df bs'); | ||
expect(Variable.replaceAll('a df as', {'a': 'b', 'f': 'zzz'})).toBe('b dzzz bs'); | ||
expect(Variable.replaceAll('$ df as', {'$': 1})).toBe('1 df as'); | ||
}); | ||
describe('Проверка replaceAll: ', function () { | ||
it('', function () { | ||
expect(Variable.replaceAll('a df as', {'a': 'b'})).toBe('b df bs'); | ||
expect(Variable.replaceAll('a df as', {'a': 'b', 'f': 'zzz'})).toBe('b dzzz bs'); | ||
expect(Variable.replaceAll('$ df as', {'$': 1})).toBe('1 df as'); | ||
}); | ||
}); | ||
describe('getElementByPath', function(){ | ||
it('', function(){ | ||
expect(Variable.getElementByPath('articul', {id: 17, articul:24})).toBe(24); | ||
expect(Variable.getElementByPath('view', {id: 17, articul:24})).toBe(undefined); | ||
expect(Variable.getElementByPath('parameter.value', { | ||
id: 17, | ||
articul:24, | ||
parameter: { | ||
value: 17, | ||
name: 'weight' | ||
} | ||
})).toBe(17); | ||
}) | ||
describe('getElementByPath', function () { | ||
it('', function () { | ||
expect(Variable.getElementByPath('articul', {id: 17, articul: 24})).toBe(24); | ||
expect(Variable.getElementByPath('view', {id: 17, articul: 24})).toBe(undefined); | ||
expect(Variable.getElementByPath('parameter.value', { | ||
id: 17, | ||
articul: 24, | ||
parameter: { | ||
value: 17, | ||
name: 'weight' | ||
} | ||
})).toBe(17); | ||
}) | ||
}); | ||
describe('getSHA1', function(){ | ||
it('', function(){ | ||
var result=true, | ||
value=Variable.getSHA1(), | ||
new_value; | ||
for(var i=0; i<1000; i++){ | ||
new_value=Variable.getSHA1(); | ||
if(Variable.type(new_value)!='string' || new_value.length!=40 || new_value===value){ | ||
result=false; | ||
break; | ||
} | ||
value=new_value; | ||
} | ||
expect(result).toBe(true); | ||
}); | ||
describe('getSHA1', function () { | ||
it('', function () { | ||
var result = true, | ||
value = Variable.getSHA1(), | ||
new_value; | ||
for (var i = 0; i < 1000; i++) { | ||
new_value = Variable.getSHA1(); | ||
if (Variable.type(new_value) != 'string' || new_value.length != 40 || new_value === value) { | ||
result = false; | ||
break; | ||
} | ||
value = new_value; | ||
} | ||
expect(result).toBe(true); | ||
}); | ||
}); | ||
describe('getFirstKey', function(){ | ||
it('', function(){ | ||
expect(Variable.getFirstKey([1,2,3])).toBe('0'); | ||
expect(Variable.getFirstKey([])).toBe(false); | ||
expect(Variable.getFirstKey({})).toBe(false); | ||
expect(Variable.getFirstKey({tr: 34, hh: 25})).toBe('tr'); | ||
expect(Variable.getFirstKey({tr: 34, hh: 25, 0:'ty', 6:'rt'})).toBe('0'); | ||
expect(Variable.getFirstKey('string')).toBe(false); | ||
}); | ||
describe('getFirstKey', function () { | ||
it('', function () { | ||
expect(Variable.getFirstKey([1, 2, 3])).toBe('0'); | ||
expect(Variable.getFirstKey([])).toBe(false); | ||
expect(Variable.getFirstKey({})).toBe(false); | ||
expect(Variable.getFirstKey({tr: 34, hh: 25})).toBe('tr'); | ||
expect(Variable.getFirstKey({tr: 34, hh: 25, 0: 'ty', 6: 'rt'})).toBe('0'); | ||
expect(Variable.getFirstKey('string')).toBe(false); | ||
}); | ||
}); | ||
describe('getFirstValue', function(){ | ||
it('', function(){ | ||
expect(Variable.getFirstValue([1,2,3])).toBe(1); | ||
expect(Variable.getFirstValue([])).toBe(false); | ||
expect(Variable.getFirstValue({})).toBe(false); | ||
expect(Variable.getFirstValue({tr: 34, hh: 25})).toBe(34); | ||
expect(Variable.getFirstValue({tr: 34, hh: 25, 0:'ty', 6:'rt'})).toBe('ty'); | ||
expect(Variable.getFirstValue('string')).toBe(false); | ||
}); | ||
describe('getFirstValue', function () { | ||
it('', function () { | ||
expect(Variable.getFirstValue([1, 2, 3])).toBe(1); | ||
expect(Variable.getFirstValue([])).toBe(false); | ||
expect(Variable.getFirstValue({})).toBe(false); | ||
expect(Variable.getFirstValue({tr: 34, hh: 25})).toBe(34); | ||
expect(Variable.getFirstValue({tr: 34, hh: 25, 0: 'ty', 6: 'rt'})).toBe('ty'); | ||
expect(Variable.getFirstValue('string')).toBe(false); | ||
}); | ||
}); | ||
describe('isInt', function(){ | ||
it('', function(){ | ||
describe('isInt', function () { | ||
it('', function () { | ||
expect(Variable.isInt(0)).toBe(true); | ||
expect(Variable.isInt(-42)).toBe(true); | ||
expect(Variable.isInt(42)).toBe(true); | ||
@@ -196,0 +203,0 @@ expect(Variable.isInt("42")).toBe(false); |
{ | ||
"name": "variable", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description" : "simple variable operations", | ||
@@ -5,0 +5,0 @@ "author": "Maxim Kadochnikov <makc.brain@yandex.ru>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
440
16589