forked from cerc-io/plugeth
tests && fixes for utils methods
This commit is contained in:
parent
fdcc1af4e2
commit
ddc17196da
2
dist/ethereum.js
vendored
2
dist/ethereum.js
vendored
@ -1269,7 +1269,7 @@ var extractDisplayName = function (name) {
|
||||
var extractTypeName = function (name) {
|
||||
/// TODO: make it invulnerable
|
||||
var length = name.indexOf('(');
|
||||
return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)) : "";
|
||||
return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : "";
|
||||
};
|
||||
|
||||
/// Filters all function from input abi
|
||||
|
2
dist/ethereum.js.map
vendored
2
dist/ethereum.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/ethereum.min.js
vendored
2
dist/ethereum.min.js
vendored
File diff suppressed because one or more lines are too long
@ -84,7 +84,7 @@ var extractDisplayName = function (name) {
|
||||
var extractTypeName = function (name) {
|
||||
/// TODO: make it invulnerable
|
||||
var length = name.indexOf('(');
|
||||
return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)) : "";
|
||||
return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : "";
|
||||
};
|
||||
|
||||
/// Filters all function from input abi
|
||||
|
42
test/utils.extractDisplayName.js
Normal file
42
test/utils.extractDisplayName.js
Normal file
@ -0,0 +1,42 @@
|
||||
var assert = require('assert');
|
||||
var utils = require('../lib/utils.js');
|
||||
|
||||
describe('utils', function () {
|
||||
describe('extractDisplayName', function () {
|
||||
it('should extract display name from method with no params', function () {
|
||||
|
||||
// given
|
||||
var test = 'helloworld()';
|
||||
|
||||
// when
|
||||
var displayName = utils.extractDisplayName(test);
|
||||
|
||||
// then
|
||||
assert.equal(displayName, 'helloworld');
|
||||
});
|
||||
|
||||
it('should extract display name from method with one param' , function () {
|
||||
|
||||
// given
|
||||
var test = 'helloworld1(int)';
|
||||
|
||||
// when
|
||||
var displayName = utils.extractDisplayName(test);
|
||||
|
||||
// then
|
||||
assert.equal(displayName, 'helloworld1');
|
||||
});
|
||||
|
||||
it('should extract display name from method with two params' , function () {
|
||||
|
||||
// given
|
||||
var test = 'helloworld2(int,string)';
|
||||
|
||||
// when
|
||||
var displayName = utils.extractDisplayName(test);
|
||||
|
||||
// then
|
||||
assert.equal(displayName, 'helloworld2');
|
||||
});
|
||||
});
|
||||
});
|
55
test/utils.extractTypeName.js
Normal file
55
test/utils.extractTypeName.js
Normal file
@ -0,0 +1,55 @@
|
||||
var assert = require('assert');
|
||||
var utils = require('../lib/utils.js');
|
||||
|
||||
describe('utils', function () {
|
||||
describe('extractTypeName', function () {
|
||||
it('should extract type name from method with no params', function () {
|
||||
|
||||
// given
|
||||
var test = 'helloworld()';
|
||||
|
||||
// when
|
||||
var typeName = utils.extractTypeName(test);
|
||||
|
||||
// then
|
||||
assert.equal(typeName, '');
|
||||
});
|
||||
|
||||
it('should extract type name from method with one param', function () {
|
||||
|
||||
// given
|
||||
var test = 'helloworld1(int)';
|
||||
|
||||
// when
|
||||
var typeName = utils.extractTypeName(test);
|
||||
|
||||
// then
|
||||
assert.equal(typeName, 'int');
|
||||
});
|
||||
|
||||
it('should extract type name from method with two params', function () {
|
||||
|
||||
// given
|
||||
var test = 'helloworld2(int,string)';
|
||||
|
||||
// when
|
||||
var typeName = utils.extractTypeName(test);
|
||||
|
||||
// then
|
||||
assert.equal(typeName, 'int,string');
|
||||
});
|
||||
|
||||
it('should extract type name from method with spaces between params', function () {
|
||||
|
||||
// given
|
||||
var test = 'helloworld3(int, string)';
|
||||
|
||||
// when
|
||||
var typeName = utils.extractTypeName(test);
|
||||
|
||||
// then
|
||||
assert.equal(typeName, 'int,string');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user