Best JavaScript code snippet using playwright-internal
types.js
Source:types.js
...20 fromObject: function fromObject(object) {21 v.require_range(0, 0xFF, object, 'uint8 ' + object);22 return object;23 },24 toObject: function toObject(object) {25 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};26 if (debug.use_default && object === undefined) {27 return 0;28 }29 v.require_range(0, 0xFF, object, 'uint8 ' + object);30 return parseInt(object);31 }32};33Types.uint16 = {34 fromByteBuffer: function fromByteBuffer(b) {35 return b.readUint16();36 },37 appendByteBuffer: function appendByteBuffer(b, object) {38 v.require_range(0, 0xFFFF, object, 'uint16 ' + object);39 b.writeUint16(object);40 return;41 },42 fromObject: function fromObject(object) {43 v.require_range(0, 0xFFFF, object, 'uint16 ' + object);44 return object;45 },46 toObject: function toObject(object) {47 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};48 if (debug.use_default && object === undefined) {49 return 0;50 }51 v.require_range(0, 0xFFFF, object, 'uint16 ' + object);52 return parseInt(object);53 }54};55Types.uint32 = {56 fromByteBuffer: function fromByteBuffer(b) {57 return b.readUint32();58 },59 appendByteBuffer: function appendByteBuffer(b, object) {60 v.require_range(0, 0xFFFFFFFF, object, 'uint32 ' + object);61 b.writeUint32(object);62 return;63 },64 fromObject: function fromObject(object) {65 v.require_range(0, 0xFFFFFFFF, object, 'uint32 ' + object);66 return object;67 },68 toObject: function toObject(object) {69 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};70 if (debug.use_default && object === undefined) {71 return 0;72 }73 v.require_range(0, 0xFFFFFFFF, object, 'uint32 ' + object);74 return parseInt(object);75 }76};77var MIN_SIGNED_32 = -1 * Math.pow(2, 31);78var MAX_SIGNED_32 = Math.pow(2, 31) - 1;79Types.varint32 = {80 fromByteBuffer: function fromByteBuffer(b) {81 return b.readVarint32();82 },83 appendByteBuffer: function appendByteBuffer(b, object) {84 v.require_range(MIN_SIGNED_32, MAX_SIGNED_32, object, 'uint32 ' + object);85 b.writeVarint32(object);86 return;87 },88 fromObject: function fromObject(object) {89 v.require_range(MIN_SIGNED_32, MAX_SIGNED_32, object, 'uint32 ' + object);90 return object;91 },92 toObject: function toObject(object) {93 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};94 if (debug.use_default && object === undefined) {95 return 0;96 }97 v.require_range(MIN_SIGNED_32, MAX_SIGNED_32, object, 'uint32 ' + object);98 return parseInt(object);99 }100};101Types.int64 = {102 fromByteBuffer: function fromByteBuffer(b) {103 return b.readInt64();104 },105 appendByteBuffer: function appendByteBuffer(b, object) {106 v.required(object);107 b.writeInt64(v.to_long(object));108 return;109 },110 fromObject: function fromObject(object) {111 v.required(object);112 return v.to_long(object);113 },114 toObject: function toObject(object) {115 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};116 if (debug.use_default && object === undefined) {117 return "0";118 }119 v.required(object);120 return v.to_long(object).toString();121 }122};123Types.uint64 = {124 fromByteBuffer: function fromByteBuffer(b) {125 return b.readUint64();126 },127 appendByteBuffer: function appendByteBuffer(b, object) {128 b.writeUint64(v.to_long(v.unsigned(object)));129 return;130 },131 fromObject: function fromObject(object) {132 return v.to_long(v.unsigned(object));133 },134 toObject: function toObject(object) {135 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};136 if (debug.use_default && object === undefined) {137 return "0";138 }139 return v.to_long(object).toString();140 }141};142Types.string = {143 fromByteBuffer: function fromByteBuffer(b) {144 var b_copy;145 var len = b.readVarint32();146 b_copy = b.copy(b.offset, b.offset + len), b.skip(len);147 return new Buffer(b_copy.toBinary(), 'binary');148 },149 appendByteBuffer: function appendByteBuffer(b, object) {150 v.required(object);151 b.writeVarint32(object.length);152 b.append(object.toString('binary'), 'binary');153 return;154 },155 fromObject: function fromObject(object) {156 v.required(object);157 return new Buffer(object);158 },159 toObject: function toObject(object) {160 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};161 if (debug.use_default && object === undefined) {162 return "";163 }164 return object.toString();165 }166};167Types.bytes = function (size) {168 return {169 fromByteBuffer: function fromByteBuffer(b) {170 if (size === undefined) {171 var b_copy;172 var len = b.readVarint32();173 b_copy = b.copy(b.offset, b.offset + len), b.skip(len);174 return new Buffer(b_copy.toBinary(), 'binary');175 } else {176 b_copy = b.copy(b.offset, b.offset + size), b.skip(size);177 return new Buffer(b_copy.toBinary(), 'binary');178 }179 },180 appendByteBuffer: function appendByteBuffer(b, object) {181 v.required(object);182 if (typeof object === "string") object = new Buffer(object, "hex");183 if (size === undefined) {184 b.writeVarint32(object.length);185 }186 b.append(object.toString('binary'), 'binary');187 return;188 },189 fromObject: function fromObject(object) {190 v.required(object);191 if (Buffer.isBuffer(object)) return object;192 return new Buffer(object, 'hex');193 },194 toObject: function toObject(object) {195 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};196 if (debug.use_default && object === undefined) {197 var zeros = function zeros(num) {198 return new Array(num).join("00");199 };200 return zeros(size);201 }202 v.required(object);203 return object.toString('hex');204 }205 };206};207Types.bool = {208 fromByteBuffer: function fromByteBuffer(b) {209 return b.readUint8() === 1;210 },211 appendByteBuffer: function appendByteBuffer(b, object) {212 // supports boolean or integer213 b.writeUint8(JSON.parse(object) ? 1 : 0);214 return;215 },216 fromObject: function fromObject(object) {217 return JSON.parse(object) ? true : false;218 },219 toObject: function toObject(object) {220 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};221 if (debug.use_default && object === undefined) {222 return false;223 }224 return JSON.parse(object) ? true : false;225 }226};227Types.void = {228 fromByteBuffer: function fromByteBuffer(b) {229 throw new Error("(void) undefined type");230 },231 appendByteBuffer: function appendByteBuffer(b, object) {232 throw new Error("(void) undefined type");233 },234 fromObject: function fromObject(object) {235 throw new Error("(void) undefined type");236 },237 toObject: function toObject(object) {238 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};239 if (debug.use_default && object === undefined) {240 return undefined;241 }242 throw new Error("(void) undefined type");243 }244};245Types.array = function (st_operation) {246 return {247 fromByteBuffer: function fromByteBuffer(b) {248 var size = b.readVarint32();249 if (HEX_DUMP) {250 console.log("varint32 size = " + size.toString(16));251 }252 var result = [];253 for (var i = 0; 0 < size ? i < size : i > size; 0 < size ? i++ : i++) {254 result.push(st_operation.fromByteBuffer(b));255 }256 return sortOperation(result, st_operation);257 },258 appendByteBuffer: function appendByteBuffer(b, object) {259 v.required(object);260 object = sortOperation(object, st_operation);261 b.writeVarint32(object.length);262 for (var i = 0, o; i < object.length; i++) {263 o = object[i];264 st_operation.appendByteBuffer(b, o);265 }266 },267 fromObject: function fromObject(object) {268 v.required(object);269 object = sortOperation(object, st_operation);270 var result = [];271 for (var i = 0, o; i < object.length; i++) {272 o = object[i];273 result.push(st_operation.fromObject(o));274 }275 return result;276 },277 toObject: function toObject(object) {278 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};279 if (debug.use_default && object === undefined) {280 return [st_operation.toObject(object, debug)];281 }282 v.required(object);283 object = sortOperation(object, st_operation);284 var result = [];285 for (var i = 0, o; i < object.length; i++) {286 o = object[i];287 result.push(st_operation.toObject(o, debug));288 }289 return result;290 }291 };292};293Types.time_point_sec = {294 fromByteBuffer: function fromByteBuffer(b) {295 return b.readUint32();296 },297 appendByteBuffer: function appendByteBuffer(b, object) {298 if (typeof object !== "number") object = Types.time_point_sec.fromObject(object);299 b.writeUint32(object);300 return;301 },302 fromObject: function fromObject(object) {303 v.required(object);304 if (typeof object === "number") return object;305 if (object.getTime) return Math.floor(object.getTime() / 1000);306 if (typeof object !== "string") throw new Error("Unknown date type: " + object);307 // if(typeof object === "string" && !/Z$/.test(object))308 // object = object + "Z"309 return Math.floor(new Date(object).getTime() / 1000);310 },311 toObject: function toObject(object) {312 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};313 if (debug.use_default && object === undefined) return new Date(0).toISOString().split('.')[0];314 v.required(object);315 if (typeof object === "string") return object;316 if (object.getTime) return object.toISOString().split('.')[0];317 var int = parseInt(object);318 v.require_range(0, 0xFFFFFFFF, int, 'uint32 ' + object);319 return new Date(int * 1000).toISOString().split('.')[0];320 }321};322Types.set = function (st_operation) {323 return {324 validate: function validate(array) {325 var dup_map = {};326 for (var i = 0, o; i < array.length; i++) {327 o = array[i];328 var ref;329 if (ref = typeof o === 'undefined' ? 'undefined' : _typeof(o), ['string', 'number'].indexOf(ref) >= 0) {330 if (dup_map[o] !== undefined) {331 throw new Error("duplicate (set)");332 }333 dup_map[o] = true;334 }335 }336 return sortOperation(array, st_operation);337 },338 fromByteBuffer: function fromByteBuffer(b) {339 var size = b.readVarint32();340 if (HEX_DUMP) {341 console.log("varint32 size = " + size.toString(16));342 }343 return this.validate(function () {344 var result = [];345 for (var i = 0; 0 < size ? i < size : i > size; 0 < size ? i++ : i++) {346 result.push(st_operation.fromByteBuffer(b));347 }348 return result;349 }());350 },351 appendByteBuffer: function appendByteBuffer(b, object) {352 if (!object) {353 object = [];354 }355 b.writeVarint32(object.length);356 var iterable = this.validate(object);357 for (var i = 0, o; i < iterable.length; i++) {358 o = iterable[i];359 st_operation.appendByteBuffer(b, o);360 }361 return;362 },363 fromObject: function fromObject(object) {364 if (!object) {365 object = [];366 }367 return this.validate(function () {368 var result = [];369 for (var i = 0, o; i < object.length; i++) {370 o = object[i];371 result.push(st_operation.fromObject(o));372 }373 return result;374 }());375 },376 toObject: function toObject(object) {377 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};378 if (debug.use_default && object === undefined) {379 return [st_operation.toObject(object, debug)];380 }381 if (!object) {382 object = [];383 }384 return this.validate(function () {385 var result = [];386 for (var i = 0, o; i < object.length; i++) {387 o = object[i];388 result.push(st_operation.toObject(o, debug));389 }390 return result;391 }());392 }393 };394};395// global_parameters_update_operation current_fees396Types.fixed_array = function (count, st_operation) {397 return {398 fromByteBuffer: function fromByteBuffer(b) {399 var i, j, ref, results;400 results = [];401 for (i = j = 0, ref = count; j < ref; i = j += 1) {402 results.push(st_operation.fromByteBuffer(b));403 }404 return sortOperation(results, st_operation);405 },406 appendByteBuffer: function appendByteBuffer(b, object) {407 var i, j, ref;408 if (count !== 0) {409 v.required(object);410 object = sortOperation(object, st_operation);411 }412 for (i = j = 0, ref = count; j < ref; i = j += 1) {413 st_operation.appendByteBuffer(b, object[i]);414 }415 },416 fromObject: function fromObject(object) {417 var i, j, ref, results;418 if (count !== 0) {419 v.required(object);420 }421 results = [];422 for (i = j = 0, ref = count; j < ref; i = j += 1) {423 results.push(st_operation.fromObject(object[i]));424 }425 return results;426 },427 toObject: function toObject(object, debug) {428 var i, j, k, ref, ref1, results, results1;429 if (debug == null) {430 debug = {};431 }432 if (debug.use_default && object === void 0) {433 results = [];434 for (i = j = 0, ref = count; j < ref; i = j += 1) {435 results.push(st_operation.toObject(void 0, debug));436 }437 return results;438 }439 if (count !== 0) {440 v.required(object);441 }442 results1 = [];443 for (i = k = 0, ref1 = count; k < ref1; i = k += 1) {444 results1.push(st_operation.toObject(object[i], debug));445 }446 return results1;447 }448 };449};450/* Supports instance numbers (11) or object types (1.2.11). Object type451Validation is enforced when an object type is used. */452var id_type = function id_type(reserved_spaces, object_type) {453 v.required(reserved_spaces, "reserved_spaces");454 v.required(object_type, "object_type");455 return {456 fromByteBuffer: function fromByteBuffer(b) {457 return b.readVarint32();458 },459 appendByteBuffer: function appendByteBuffer(b, object) {460 v.required(object);461 if (object.resolve !== undefined) {462 object = object.resolve;463 }464 // convert 1.2.n into just n465 if (/^[0-9]+\.[0-9]+\.[0-9]+$/.test(object)) {466 object = v.get_instance(reserved_spaces, object_type, object);467 }468 b.writeVarint32(v.to_number(object));469 return;470 },471 fromObject: function fromObject(object) {472 v.required(object);473 if (object.resolve !== undefined) {474 object = object.resolve;475 }476 if (v.is_digits(object)) {477 return v.to_number(object);478 }479 return v.get_instance(reserved_spaces, object_type, object);480 },481 toObject: function toObject(object) {482 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};483 var object_type_id = ChainTypes.object_type[object_type];484 if (debug.use_default && object === undefined) {485 return reserved_spaces + '.' + object_type_id + '.0';486 }487 v.required(object);488 if (object.resolve !== undefined) {489 object = object.resolve;490 }491 if (/^[0-9]+\.[0-9]+\.[0-9]+$/.test(object)) {492 object = v.get_instance(reserved_spaces, object_type, object);493 }494 return reserved_spaces + '.' + object_type_id + '.' + object;495 }496 };497};498Types.protocol_id_type = function (name) {499 v.required(name, "name");500 return id_type(ChainTypes.reserved_spaces.protocol_ids, name);501};502Types.object_id_type = {503 fromByteBuffer: function fromByteBuffer(b) {504 return ObjectId.fromByteBuffer(b);505 },506 appendByteBuffer: function appendByteBuffer(b, object) {507 v.required(object);508 if (object.resolve !== undefined) {509 object = object.resolve;510 }511 object = ObjectId.fromString(object);512 object.appendByteBuffer(b);513 return;514 },515 fromObject: function fromObject(object) {516 v.required(object);517 if (object.resolve !== undefined) {518 object = object.resolve;519 }520 return ObjectId.fromString(object);521 },522 toObject: function toObject(object) {523 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};524 if (debug.use_default && object === undefined) {525 return "0.0.0";526 }527 v.required(object);528 if (object.resolve !== undefined) {529 object = object.resolve;530 }531 object = ObjectId.fromString(object);532 return object.toString();533 }534};535Types.vote_id = { TYPE: 0x000000FF,536 ID: 0xFFFFFF00,537 fromByteBuffer: function fromByteBuffer(b) {538 var value = b.readUint32();539 return {540 type: value & this.TYPE,541 id: value & this.ID542 };543 },544 appendByteBuffer: function appendByteBuffer(b, object) {545 v.required(object);546 if (object === "string") object = Types.vote_id.fromObject(object);547 var value = object.id << 8 | object.type;548 b.writeUint32(value);549 return;550 },551 fromObject: function fromObject(object) {552 v.required(object, "(type vote_id)");553 if ((typeof object === 'undefined' ? 'undefined' : _typeof(object)) === "object") {554 v.required(object.type, "type");555 v.required(object.id, "id");556 return object;557 }558 v.require_test(/^[0-9]+:[0-9]+$/, object, 'vote_id format ' + object);559 var _object$split = object.split(':'),560 type = _object$split[0],561 id = _object$split[1];562 v.require_range(0, 0xff, type, 'vote type ' + object);563 v.require_range(0, 0xffffff, id, 'vote id ' + object);564 return { type: type, id: id };565 },566 toObject: function toObject(object) {567 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};568 if (debug.use_default && object === undefined) {569 return "0:0";570 }571 v.required(object);572 if (typeof object === "string") object = Types.vote_id.fromObject(object);573 return object.type + ":" + object.id;574 },575 compare: function compare(a, b) {576 if ((typeof a === 'undefined' ? 'undefined' : _typeof(a)) !== "object") a = Types.vote_id.fromObject(a);577 if ((typeof b === 'undefined' ? 'undefined' : _typeof(b)) !== "object") b = Types.vote_id.fromObject(b);578 return parseInt(a.id) - parseInt(b.id);579 }580};581Types.optional = function (st_operation) {582 v.required(st_operation, "st_operation");583 return {584 fromByteBuffer: function fromByteBuffer(b) {585 if (!(b.readUint8() === 1)) {586 return undefined;587 }588 return st_operation.fromByteBuffer(b);589 },590 appendByteBuffer: function appendByteBuffer(b, object) {591 if (object !== null && object !== undefined) {592 b.writeUint8(1);593 st_operation.appendByteBuffer(b, object);594 } else {595 b.writeUint8(0);596 }597 return;598 },599 fromObject: function fromObject(object) {600 if (object === undefined) {601 return undefined;602 }603 return st_operation.fromObject(object);604 },605 toObject: function toObject(object) {606 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};607 // toObject is only null save if use_default is true608 var result_object = function () {609 if (!debug.use_default && object === undefined) {610 return undefined;611 } else {612 return st_operation.toObject(object, debug);613 }614 }();615 if (debug.annotate) {616 if ((typeof result_object === 'undefined' ? 'undefined' : _typeof(result_object)) === "object") {617 result_object.__optional = "parent is optional";618 } else {619 result_object = { __optional: result_object };620 }621 }622 return result_object;623 }624 };625};626Types.static_variant = function (_st_operations) {627 return {628 nosort: true,629 st_operations: _st_operations,630 fromByteBuffer: function fromByteBuffer(b) {631 var type_id = b.readVarint32();632 var st_operation = this.st_operations[type_id];633 if (HEX_DUMP) {634 console.error('static_variant id 0x' + type_id.toString(16) + ' (' + type_id + ')');635 }636 v.required(st_operation, 'operation ' + type_id);637 return [type_id, st_operation.fromByteBuffer(b)];638 },639 appendByteBuffer: function appendByteBuffer(b, object) {640 v.required(object);641 var type_id = object[0];642 var st_operation = this.st_operations[type_id];643 v.required(st_operation, 'operation ' + type_id);644 b.writeVarint32(type_id);645 st_operation.appendByteBuffer(b, object[1]);646 return;647 },648 fromObject: function fromObject(object) {649 v.required(object);650 var type_id = object[0];651 var st_operation = this.st_operations[type_id];652 v.required(st_operation, 'operation ' + type_id);653 return [type_id, st_operation.fromObject(object[1])];654 },655 toObject: function toObject(object) {656 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};657 if (debug.use_default && object === undefined) {658 return [0, this.st_operations[0].toObject(undefined, debug)];659 }660 v.required(object);661 var type_id = object[0];662 var st_operation = this.st_operations[type_id];663 v.required(st_operation, 'operation ' + type_id);664 return [type_id, st_operation.toObject(object[1], debug)];665 }666 };667};668Types.map = function (key_st_operation, value_st_operation) {669 return {670 validate: function validate(array) {671 if (!Array.isArray(array)) {672 throw new Error("expecting array");673 }674 var dup_map = {};675 for (var i = 0, o; i < array.length; i++) {676 o = array[i];677 var ref;678 if (!(o.length === 2)) {679 throw new Error("expecting two elements");680 }681 if (ref = _typeof(o[0]), ['number', 'string'].indexOf(ref) >= 0) {682 if (dup_map[o[0]] !== undefined) {683 throw new Error("duplicate (map)");684 }685 dup_map[o[0]] = true;686 }687 }688 return sortOperation(array, key_st_operation);689 },690 fromByteBuffer: function fromByteBuffer(b) {691 var result = [];692 var end = b.readVarint32();693 for (var i = 0; 0 < end ? i < end : i > end; 0 < end ? i++ : i++) {694 result.push([key_st_operation.fromByteBuffer(b), value_st_operation.fromByteBuffer(b)]);695 }696 return this.validate(result);697 },698 appendByteBuffer: function appendByteBuffer(b, object) {699 this.validate(object);700 b.writeVarint32(object.length);701 for (var i = 0, o; i < object.length; i++) {702 o = object[i];703 key_st_operation.appendByteBuffer(b, o[0]);704 value_st_operation.appendByteBuffer(b, o[1]);705 }706 return;707 },708 fromObject: function fromObject(object) {709 v.required(object);710 var result = [];711 for (var i = 0, o; i < object.length; i++) {712 o = object[i];713 result.push([key_st_operation.fromObject(o[0]), value_st_operation.fromObject(o[1])]);714 }715 return this.validate(result);716 },717 toObject: function toObject(object) {718 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};719 if (debug.use_default && object === undefined) {720 return [[key_st_operation.toObject(undefined, debug), value_st_operation.toObject(undefined, debug)]];721 }722 v.required(object);723 object = this.validate(object);724 var result = [];725 for (var i = 0, o; i < object.length; i++) {726 o = object[i];727 result.push([key_st_operation.toObject(o[0], debug), value_st_operation.toObject(o[1], debug)]);728 }729 return result;730 }731 };732};733Types.public_key = {734 toPublic: function toPublic(object) {735 if (object.resolve !== undefined) {736 object = object.resolve;737 }738 return object == null ? object : object.Q ? object : PublicKey.fromStringOrThrow(object);739 },740 fromByteBuffer: function fromByteBuffer(b) {741 return fp.public_key(b);742 },743 appendByteBuffer: function appendByteBuffer(b, object) {744 v.required(object);745 fp.public_key(b, Types.public_key.toPublic(object));746 return;747 },748 fromObject: function fromObject(object) {749 v.required(object);750 if (object.Q) {751 return object;752 }753 return Types.public_key.toPublic(object);754 },755 toObject: function toObject(object) {756 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};757 if (debug.use_default && object === undefined) {758 return ChainConfig.address_prefix + "859gxfnXyUriMgUeThh1fWv3oqcpLFyHa3TfFYC4PK2HqhToVM";759 }760 v.required(object);761 return object.toString();762 },763 compare: function compare(a, b) {764 return strCmp(a.toAddressString(), b.toAddressString());765 }766};767Types.address = {768 _to_address: function _to_address(object) {769 v.required(object);770 if (object.addy) {771 return object;772 }773 return Address.fromString(object);774 },775 fromByteBuffer: function fromByteBuffer(b) {776 return new Address(fp.ripemd160(b));777 },778 appendByteBuffer: function appendByteBuffer(b, object) {779 fp.ripemd160(b, Types.address._to_address(object).toBuffer());780 return;781 },782 fromObject: function fromObject(object) {783 return Types.address._to_address(object);784 },785 toObject: function toObject(object) {786 var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};787 if (debug.use_default && object === undefined) {788 return ChainConfig.address_prefix + "664KmHxSuQyDsfwo4WEJvWpzg1QKdg67S";789 }790 return Types.address._to_address(object).toString();791 },792 compare: function compare(a, b) {793 return strCmp(a.toString(), b.toString());794 }795};796var strCmp = function strCmp(a, b) {797 return a > b ? 1 : a < b ? -1 : 0;798};799var firstEl = function firstEl(el) {...
image_filters.js
Source:image_filters.js
...90 });91 test('toObject', function() {92 var filter = new fabric.Image.filters.Brightness();93 ok(typeof filter.toObject == 'function');94 var object = filter.toObject();95 equal(JSON.stringify(object), '{"type":"Brightness","brightness":0}');96 filter.brightness = 100;97 object = filter.toObject();98 equal(JSON.stringify(object), '{"type":"Brightness","brightness":100}');99 });100 test('toJSON', function() {101 var filter = new fabric.Image.filters.Brightness();102 ok(typeof filter.toJSON == 'function');103 var json = filter.toJSON();104 equal(JSON.stringify(json), '{"type":"Brightness","brightness":0}');105 filter.brightness = 100;106 json = filter.toJSON();107 equal(JSON.stringify(json), '{"type":"Brightness","brightness":100}');108 });109 test('fromObject', function() {110 var filter = new fabric.Image.filters.Brightness();111 var object = filter.toObject();112 deepEqual(fabric.Image.filters.Brightness.fromObject(object), filter);113 });114 QUnit.module('fabric.Image.filters.Convolute');115 test('constructor', function() {116 ok(fabric.Image.filters.Convolute);117 var filter = new fabric.Image.filters.Convolute();118 ok(filter instanceof fabric.Image.filters.Convolute, 'should inherit from fabric.Image.filters.Convolute');119 });120 test('properties', function() {121 var filter = new fabric.Image.filters.Convolute();122 equal(filter.type, 'Convolute');123 equal(filter.opaque, undefined);124 deepEqual(filter.matrix, [0,0,0,0,1,0,0,0,0]);125 var filter2 = new fabric.Image.filters.Convolute({opaque: 0.5, matrix: [1,-1,1,0,1,0,0,0,0]});126 equal(filter2.opaque, 0.5);127 deepEqual(filter2.matrix, [1,-1,1,0,1,0,0,0,0]);128 });129 test('applyTo', function() {130 var filter = new fabric.Image.filters.Convolute();131 ok(typeof filter.applyTo == 'function');132 });133 test('toObject', function() {134 var filter = new fabric.Image.filters.Convolute({opaque: 1});135 ok(typeof filter.toObject == 'function');136 var object = filter.toObject();137 equal(JSON.stringify(object), '{"type":"Convolute","opaque":1,"matrix":[0,0,0,0,1,0,0,0,0]}');138 });139 test('toJSON', function() {140 var filter = new fabric.Image.filters.Convolute({opaque: 1});141 ok(typeof filter.toJSON == 'function');142 var json = filter.toJSON();143 equal(JSON.stringify(json), '{"type":"Convolute","opaque":1,"matrix":[0,0,0,0,1,0,0,0,0]}');144 });145 test('fromObject', function() {146 var filter = new fabric.Image.filters.Convolute();147 var object = filter.toObject();148 deepEqual(fabric.Image.filters.Convolute.fromObject(object), filter);149 });150 QUnit.module('fabric.Image.filters.GradientTransparency');151 test('constructor', function() {152 ok(fabric.Image.filters.GradientTransparency);153 var filter = new fabric.Image.filters.GradientTransparency();154 ok(filter instanceof fabric.Image.filters.GradientTransparency, 'should inherit from fabric.Image.filters.GradientTransparency');155 });156 test('properties', function() {157 var filter = new fabric.Image.filters.GradientTransparency();158 equal(filter.type, 'GradientTransparency');159 equal(filter.threshold, 100);160 var filter2 = new fabric.Image.filters.GradientTransparency({threshold: 50});161 equal(filter2.threshold, 50);162 });163 test('applyTo', function() {164 var filter = new fabric.Image.filters.GradientTransparency();165 ok(typeof filter.applyTo == 'function');166 });167 test('toObject', function() {168 var filter = new fabric.Image.filters.GradientTransparency();169 ok(typeof filter.toObject == 'function');170 var object = filter.toObject();171 equal(JSON.stringify(object), '{"type":"GradientTransparency","threshold":100}');172 });173 test('toJSON', function() {174 var filter = new fabric.Image.filters.GradientTransparency();175 ok(typeof filter.toJSON == 'function');176 var json = filter.toJSON();177 equal(JSON.stringify(json), '{"type":"GradientTransparency","threshold":100}');178 });179 test('fromObject', function() {180 var filter = new fabric.Image.filters.GradientTransparency();181 var object = filter.toObject();182 deepEqual(fabric.Image.filters.GradientTransparency.fromObject(object), filter);183 });184 QUnit.module('fabric.Image.filters.Grayscale');185 test('constructor', function() {186 ok(fabric.Image.filters.Grayscale);187 var filter = new fabric.Image.filters.Grayscale();188 ok(filter instanceof fabric.Image.filters.Grayscale, 'should inherit from fabric.Image.filters.Grayscale');189 });190 test('properties', function() {191 var filter = new fabric.Image.filters.Grayscale();192 equal(filter.type, 'Grayscale');193 });194 test('applyTo', function() {195 var filter = new fabric.Image.filters.Grayscale();196 ok(typeof filter.applyTo == 'function');197 });198 test('toObject', function() {199 var filter = new fabric.Image.filters.Grayscale();200 ok(typeof filter.toObject == 'function');201 var object = filter.toObject();202 equal(JSON.stringify(object), '{"type":"Grayscale"}');203 });204 test('toJSON', function() {205 var filter = new fabric.Image.filters.Grayscale();206 ok(typeof filter.toJSON == 'function');207 var json = filter.toJSON();208 equal(JSON.stringify(json), '{"type":"Grayscale"}');209 });210 test('fromObject', function() {211 var filter = new fabric.Image.filters.Grayscale();212 var object = filter.toObject();213 deepEqual(fabric.Image.filters.Grayscale.fromObject(object), filter);214 });215 QUnit.module('fabric.Image.filters.Invert');216 test('constructor', function() {217 ok(fabric.Image.filters.Invert);218 var filter = new fabric.Image.filters.Invert();219 ok(filter instanceof fabric.Image.filters.Invert, 'should inherit from fabric.Image.filters.Invert');220 });221 test('properties', function() {222 var filter = new fabric.Image.filters.Invert();223 equal(filter.type, 'Invert');224 });225 test('applyTo', function() {226 var filter = new fabric.Image.filters.Invert();227 ok(typeof filter.applyTo == 'function');228 });229 test('toObject', function() {230 var filter = new fabric.Image.filters.Invert();231 ok(typeof filter.toObject == 'function');232 var object = filter.toObject();233 equal(JSON.stringify(object), '{"type":"Invert"}');234 });235 test('toJSON', function() {236 var filter = new fabric.Image.filters.Invert();237 ok(typeof filter.toJSON == 'function');238 var json = filter.toJSON();239 equal(JSON.stringify(json), '{"type":"Invert"}');240 });241 test('fromObject', function() {242 var filter = new fabric.Image.filters.Invert();243 var object = filter.toObject();244 deepEqual(fabric.Image.filters.Invert.fromObject(object), filter);245 });246 QUnit.module('fabric.Image.filters.Noise');247 test('constructor', function() {248 ok(fabric.Image.filters.Noise);249 var filter = new fabric.Image.filters.Noise();250 ok(filter instanceof fabric.Image.filters.Noise, 'should inherit from fabric.Image.filters.Noise');251 });252 test('properties', function() {253 var filter = new fabric.Image.filters.Noise();254 equal(filter.type, 'Noise');255 equal(filter.noise, 0);256 var filter2 = new fabric.Image.filters.Noise({noise: 200});257 equal(filter2.noise, 200);258 });259 test('applyTo', function() {260 var filter = new fabric.Image.filters.Noise();261 ok(typeof filter.applyTo == 'function');262 });263 test('toObject', function() {264 var filter = new fabric.Image.filters.Noise();265 ok(typeof filter.toObject == 'function');266 var object = filter.toObject();267 equal(JSON.stringify(object), '{"type":"Noise","noise":0}');268 filter.noise = 100;269 object = filter.toObject();270 equal(JSON.stringify(object), '{"type":"Noise","noise":100}');271 });272 test('toJSON', function() {273 var filter = new fabric.Image.filters.Noise();274 ok(typeof filter.toJSON == 'function');275 var json = filter.toJSON();276 equal(JSON.stringify(json), '{"type":"Noise","noise":0}');277 filter.noise = 100;278 json = filter.toJSON();279 equal(JSON.stringify(json), '{"type":"Noise","noise":100}');280 });281 test('fromObject', function() {282 var filter = new fabric.Image.filters.Noise();283 var object = filter.toObject();284 deepEqual(fabric.Image.filters.Noise.fromObject(object), filter);285 });286 QUnit.module('fabric.Image.filters.Pixelate');287 test('constructor', function() {288 ok(fabric.Image.filters.Pixelate);289 var filter = new fabric.Image.filters.Pixelate();290 ok(filter instanceof fabric.Image.filters.Pixelate, 'should inherit from fabric.Image.filters.Pixelate');291 });292 test('properties', function() {293 var filter = new fabric.Image.filters.Pixelate();294 equal(filter.type, 'Pixelate');295 equal(filter.blocksize, 4);296 var filter2 = new fabric.Image.filters.Pixelate({blocksize: 8});297 equal(filter2.blocksize, 8);298 });299 test('applyTo', function() {300 var filter = new fabric.Image.filters.Pixelate();301 ok(typeof filter.applyTo == 'function');302 });303 test('toObject', function() {304 var filter = new fabric.Image.filters.Pixelate();305 ok(typeof filter.toObject == 'function');306 var object = filter.toObject();307 equal(JSON.stringify(object), '{"type":"Pixelate","blocksize":4}');308 });309 test('toJSON', function() {310 var filter = new fabric.Image.filters.Pixelate();311 ok(typeof filter.toJSON == 'function');312 var json = filter.toJSON();313 equal(JSON.stringify(json), '{"type":"Pixelate","blocksize":4}');314 });315 test('fromObject', function() {316 var filter = new fabric.Image.filters.Pixelate();317 var object = filter.toObject();318 deepEqual(fabric.Image.filters.Pixelate.fromObject(object), filter);319 });320 QUnit.module('fabric.Image.filters.RemoveWhite');321 test('constructor', function() {322 ok(fabric.Image.filters.RemoveWhite);323 var filter = new fabric.Image.filters.RemoveWhite();324 ok(filter instanceof fabric.Image.filters.RemoveWhite, 'should inherit from fabric.Image.filters.RemoveWhite');325 });326 test('properties', function() {327 var filter = new fabric.Image.filters.RemoveWhite();328 equal(filter.type, 'RemoveWhite');329 equal(filter.threshold, 30);330 equal(filter.distance, 20);331 var filter2 = new fabric.Image.filters.RemoveWhite({threshold: 10, distance: 60});332 equal(filter2.threshold, 10);333 equal(filter2.distance, 60);334 });335 test('applyTo', function() {336 var filter = new fabric.Image.filters.RemoveWhite();337 ok(typeof filter.applyTo == 'function');338 });339 test('toObject', function() {340 var filter = new fabric.Image.filters.RemoveWhite();341 ok(typeof filter.toObject == 'function');342 var object = filter.toObject();343 equal(JSON.stringify(object), '{"type":"RemoveWhite","threshold":30,"distance":20}');344 });345 test('toJSON', function() {346 var filter = new fabric.Image.filters.RemoveWhite();347 ok(typeof filter.toJSON == 'function');348 var json = filter.toJSON();349 equal(JSON.stringify(json), '{"type":"RemoveWhite","threshold":30,"distance":20}');350 });351 test('fromObject', function() {352 var filter = new fabric.Image.filters.RemoveWhite();353 var object = filter.toObject();354 deepEqual(fabric.Image.filters.RemoveWhite.fromObject(object), filter);355 });356 QUnit.module('fabric.Image.filters.Sepia2');357 test('constructor', function() {358 ok(fabric.Image.filters.Sepia2);359 var filter = new fabric.Image.filters.Sepia2();360 ok(filter instanceof fabric.Image.filters.Sepia2, 'should inherit from fabric.Image.filters.Sepia2');361 });362 test('properties', function() {363 var filter = new fabric.Image.filters.Sepia2();364 equal(filter.type, 'Sepia2');365 });366 test('applyTo', function() {367 var filter = new fabric.Image.filters.Sepia2();368 ok(typeof filter.applyTo == 'function');369 });370 test('toObject', function() {371 var filter = new fabric.Image.filters.Sepia2();372 ok(typeof filter.toObject == 'function');373 var object = filter.toObject();374 equal(JSON.stringify(object), '{"type":"Sepia2"}');375 });376 test('toJSON', function() {377 var filter = new fabric.Image.filters.Sepia2();378 ok(typeof filter.toJSON == 'function');379 var json = filter.toJSON();380 equal(JSON.stringify(json), '{"type":"Sepia2"}');381 });382 test('fromObject', function() {383 var filter = new fabric.Image.filters.Sepia2();384 var object = filter.toObject();385 deepEqual(fabric.Image.filters.Sepia2.fromObject(object), filter);386 });387 QUnit.module('fabric.Image.filters.Sepia');388 test('constructor', function() {389 ok(fabric.Image.filters.Sepia);390 var filter = new fabric.Image.filters.Sepia();391 ok(filter instanceof fabric.Image.filters.Sepia, 'should inherit from fabric.Image.filters.Sepia');392 });393 test('properties', function() {394 var filter = new fabric.Image.filters.Sepia();395 equal(filter.type, 'Sepia');396 });397 test('applyTo', function() {398 var filter = new fabric.Image.filters.Sepia();399 ok(typeof filter.applyTo == 'function');400 });401 test('toObject', function() {402 var filter = new fabric.Image.filters.Sepia();403 ok(typeof filter.toObject == 'function');404 var object = filter.toObject();405 equal(JSON.stringify(object), '{"type":"Sepia"}');406 });407 test('toJSON', function() {408 var filter = new fabric.Image.filters.Sepia();409 ok(typeof filter.toJSON == 'function');410 var json = filter.toJSON();411 equal(JSON.stringify(json), '{"type":"Sepia"}');412 });413 test('fromObject', function() {414 var filter = new fabric.Image.filters.Sepia();415 var object = filter.toObject();416 deepEqual(fabric.Image.filters.Sepia.fromObject(object), filter);417 });418 QUnit.module('fabric.Image.filters.Tint');419 test('constructor', function() {420 ok(fabric.Image.filters.Tint);421 var filter = new fabric.Image.filters.Tint();422 ok(filter instanceof fabric.Image.filters.Tint, 'should inherit from fabric.Image.filters.Tint');423 });424 test('properties', function() {425 var filter = new fabric.Image.filters.Tint();426 equal(filter.type, 'Tint');427 equal(filter.color, '#000000');428 equal(filter.opacity, 1);429 var filter2 = new fabric.Image.filters.Tint({color: 'rgba(0,0,255,0.5)', opacity: 0.2});430 equal(filter2.color, 'rgba(0,0,255,0.5)');431 equal(filter2.opacity, 0.2);432 var filter3 = new fabric.Image.filters.Tint({color: 'rgba(0,0,255,0.5)'});433 equal(filter3.color, 'rgba(0,0,255,0.5)');434 equal(filter3.opacity, 0.5);435 });436 test('applyTo', function() {437 var filter = new fabric.Image.filters.Tint();438 ok(typeof filter.applyTo == 'function');439 });440 test('toObject', function() {441 var filter = new fabric.Image.filters.Tint();442 ok(typeof filter.toObject == 'function');443 var object = filter.toObject();444 equal(JSON.stringify(object), '{"type":"Tint","color":"#000000","opacity":1}');445 filter.color = '#FF00FF';446 filter.opacity = 0.2;447 equal(JSON.stringify(filter.toObject()), '{"type":"Tint","color":"#FF00FF","opacity":0.2}');448 });449 test('toJSON', function() {450 var filter = new fabric.Image.filters.Tint();451 ok(typeof filter.toJSON == 'function');452 var json = filter.toJSON();453 equal(JSON.stringify(json), '{"type":"Tint","color":"#000000","opacity":1}');454 filter.color = '#FF00FF';455 filter.opacity = 0.2;456 equal(JSON.stringify(filter.toJSON()), '{"type":"Tint","color":"#FF00FF","opacity":0.2}');457 });458 test('fromObject', function() {459 var filter = new fabric.Image.filters.Tint();460 var object = filter.toObject();461 deepEqual(fabric.Image.filters.Tint.fromObject(object), filter);462 filter.color = '#FF0000';463 filter.opacity = 0.8;464 deepEqual(fabric.Image.filters.Tint.fromObject(filter.toObject()), filter);465 });466 QUnit.module('fabric.Image.filters.Mask');467 test('constructor', function() {468 ok(fabric.Image.filters.Mask);469 var filter = new fabric.Image.filters.Mask();470 ok(filter instanceof fabric.Image.filters.Mask, 'should inherit from fabric.Image.filters.Mask');471 });472 asyncTest('properties', function() {473 var filter = new fabric.Image.filters.Mask();474 equal(filter.type, 'Mask');475 equal(filter.mask, undefined);476 equal(filter.channel, 0);477 createImageObject(function(image) {478 var filter2 = new fabric.Image.filters.Mask({mask: image, channel: 2});479 equal(filter2.mask, image);480 equal(filter2.channel, 2);481 start();482 });483 });484 test('applyTo', function() {485 var filter = new fabric.Image.filters.Mask();486 ok(typeof filter.applyTo == 'function');487 });488 asyncTest('toObject', function() {489 createImageObject(function(image) {490 var filter = new fabric.Image.filters.Mask({mask: image});491 ok(typeof filter.toObject == 'function');492 var object = filter.toObject(),493 maskObj = object.mask;494 // workaround for node-canvas sometimes producing images with width/height and sometimes not495 if (maskObj.width === 0) {496 maskObj.width = IMG_WIDTH;497 }498 if (maskObj.height === 0) {499 maskObj.height = IMG_HEIGHT;500 }501 equal(JSON.stringify(object), '{"type":"Mask","mask":' + JSON.stringify(maskObj) + ',"channel":0}');502 start();503 });504 });505 asyncTest('toJSON', function() {506 createImageObject(function(image) {507 var filter = new fabric.Image.filters.Mask({mask: image});508 ok(typeof filter.toJSON == 'function');509 var json = filter.toJSON(),510 maskObj = json.mask;511 // workaround for node-canvas sometimes producing images with width/height and sometimes not512 if (maskObj.width === 0) {513 maskObj.width = IMG_WIDTH;514 }515 if (maskObj.height === 0) {516 maskObj.height = IMG_HEIGHT;517 }518 equal(JSON.stringify(json), '{"type":"Mask","mask":' + JSON.stringify(maskObj) + ',"channel":0}');519 start();520 });521 });522 QUnit.module('fabric.Image.filters.Resize');523 test('constructor', function() {524 ok(fabric.Image.filters.Resize);525 var filter = new fabric.Image.filters.Resize();526 ok(filter instanceof fabric.Image.filters.Resize, 'should inherit from fabric.Image.filters.Resize');527 });528 test('properties', function() {529 var filter = new fabric.Image.filters.Resize();530 equal(filter.type, 'Resize');531 equal(filter.resizeType, 'hermite');532 equal(filter.lanczosLobes, 3);533 equal(filter.scaleX, 0);534 equal(filter.scaleY, 0);535 var filter2 = new fabric.Image.filters.Resize({resizeType: 'bilinear', scaleX: 0.3, scaleY: 0.3});536 equal(filter2.resizeType, 'bilinear');537 equal(filter2.scaleX, 0.3);538 equal(filter2.scaleY, 0.3);539 });540 test('applyTo', function() {541 var filter = new fabric.Image.filters.Resize();542 ok(typeof filter.applyTo == 'function');543 });544 test('toObject', function() {545 var filter = new fabric.Image.filters.Resize();546 ok(typeof filter.toObject == 'function');547 var object = filter.toObject();548 equal(JSON.stringify(object), '{"type":"Resize","scaleX":0,"scaleY":0,"resizeType":"hermite","lanczosLobes":3}');549 filter.resizeType = 'bilinear';550 object = filter.toObject();551 equal(JSON.stringify(object), '{"type":"Resize","scaleX":0,"scaleY":0,"resizeType":"bilinear","lanczosLobes":3}');552 });553 test('fromObject', function() {554 var filter = new fabric.Image.filters.Resize();555 var object = filter.toObject();556 var fromObject = fabric.Image.filters.Resize.fromObject(object);557 deepEqual(fromObject, filter);558 ok(fromObject instanceof fabric.Image.filters.Resize, 'should inherit from fabric.Image.filters.Resize');559 filter.resizeType = 'bilinear';560 filter.scaleX = 0.8;561 filter.scaleY = 0.8;562 deepEqual(fabric.Image.filters.Resize.fromObject(filter.toObject()), filter);563 });564 // asyncTest('fromObject', function() {565 // createImageObject(function(image) {566 // var filter = new fabric.Image.filters.Mask({mask: image});567 // var object = filter.toObject();568 // fabric.Image.filters.Mask.fromObject(object, function(filterObj) {569 // deepEqual(filterObj, filter);570 // start();571 // });572 // });573 // });...
image.js
Source:image.js
...108 });109 asyncTest('toObject', function() {110 createImageObject(function(image) {111 ok(typeof image.toObject == 'function');112 var toObject = image.toObject();113 // workaround for node-canvas sometimes producing images with width/height and sometimes not114 if (toObject.width === 0) {115 toObject.width = IMG_WIDTH;116 }117 if (toObject.height === 0) {118 toObject.height = IMG_HEIGHT;119 }120 deepEqual(toObject, REFERENCE_IMG_OBJECT);121 start();122 });123 });124 asyncTest('toObject with no element', function() {125 createImageObject(function(image) {126 ok(typeof image.toObject == 'function');127 var toObject = image.toObject();128 // workaround for node-canvas sometimes producing images with width/height and sometimes not129 if (toObject.width === 0) {130 toObject.width = IMG_WIDTH;131 }132 if (toObject.height === 0) {133 toObject.height = IMG_HEIGHT;134 }135 deepEqual(toObject, REFERENCE_IMG_OBJECT);136 start();137 });138 });139 asyncTest('toObject with resize filter', function() {140 createImageObject(function(image) {141 ok(typeof image.toObject == 'function');142 var filter = new fabric.Image.filters.Resize({resizeType: 'bilinear', scaleX: 0.3, scaleY: 0.3});143 image.resizeFilters.push(filter);144 ok(image.resizeFilters[0] instanceof fabric.Image.filters.Resize, 'should inherit from fabric.Image.filters.Resize');145 var toObject = image.toObject();146 deepEqual(toObject.resizeFilters[0], filter.toObject());147 fabric.Image.fromObject(toObject, function(imageFromObject) {148 var filterFromObj = imageFromObject.resizeFilters[0];149 deepEqual(filterFromObj, filter);150 ok(filterFromObj instanceof fabric.Image.filters.Resize, 'should inherit from fabric.Image.filters.Resize');151 equal(filterFromObj.scaleX, 0.3);152 equal(filterFromObj.scaleY, 0.3);153 equal(filterFromObj.resizeType, 'bilinear');154 start();155 });156 });157 });158 asyncTest('toObject with applied resize filter', function() {159 createImageObject(function(image) {160 ok(typeof image.toObject == 'function');161 var filter = new fabric.Image.filters.Resize({resizeType: 'bilinear', scaleX: 0.2, scaleY: 0.2});162 image.filters.push(filter);163 var width = image.width, height = image.height;164 ok(image.filters[0] instanceof fabric.Image.filters.Resize, 'should inherit from fabric.Image.filters.Resize');165 image.applyFilters(function() {166 equal(image.width, width / 5, 'width should be a fifth');167 equal(image.height, height / 5, 'height should a fifth');168 var toObject = image.toObject();169 deepEqual(toObject.filters[0], filter.toObject());170 equal(toObject.width, width, 'width is stored as before filters');171 equal(toObject.height, height, 'height is stored as before filters');172 fabric.Image.fromObject(toObject, function(_imageFromObject) {173 var filterFromObj = _imageFromObject.filters[0];174 ok(filterFromObj instanceof fabric.Image.filters.Resize, 'should inherit from fabric.Image.filters.Resize');175 equal(filterFromObj.scaleY, 0.2);176 equal(filterFromObj.scaleX, 0.2);177 equal(_imageFromObject.width, width / 5, 'on image reload width is halved again');178 equal(_imageFromObject.height, height / 5, 'on image reload width is halved again');179 start();180 });181 });182 });183 });184 asyncTest('toString', function() {185 createImageObject(function(image) {186 ok(typeof image.toString == 'function');187 equal(image.toString(), '#<fabric.Image: { src: "' + IMG_SRC + '" }>');188 start();189 });190 });191 asyncTest('getSrc', function() {192 createImageObject(function(image) {193 ok(typeof image.getSrc == 'function');194 equal(image.getSrc(), IMG_SRC);195 start();196 });197 });198 test('getElement', function() {199 var elImage = _createImageElement();200 var image = new fabric.Image(elImage);201 ok(typeof image.getElement == 'function');202 equal(image.getElement(), elImage);203 });204 asyncTest('setElement', function() {205 createImageObject(function(image) {206 ok(typeof image.setElement == 'function');207 var elImage = _createImageElement();208 equal(image.setElement(elImage), image, 'chainable');209 equal(image.getElement(), elImage);210 equal(image._originalElement, elImage);211 start();212 });213 });214 asyncTest('crossOrigin', function() {215 createImageObject(function(image) {216 equal(image.crossOrigin, '', 'initial crossOrigin value should be set');217 var elImage = _createImageElement();218 elImage.crossOrigin = 'anonymous';219 image = new fabric.Image(elImage);220 equal(image.crossOrigin, '', 'crossOrigin value on an instance takes precedence');221 var objRepr = image.toObject();222 equal(objRepr.crossOrigin, '', 'toObject should return proper crossOrigin value');223 var elImage2 = _createImageElement();224 elImage2.crossOrigin = 'anonymous';225 image.setElement(elImage2);226 equal(elImage2.crossOrigin, 'anonymous', 'setElement should set proper crossOrigin on an img element');227 // fromObject doesn't work on Node :/228 if (fabric.isLikelyNode) {229 start();230 return;231 }232 fabric.Image.fromObject(objRepr, function(img) {233 equal(img.crossOrigin, '');234 start();235 });236 });237 });238 asyncTest('clone', function() {239 createImageObject(function(image) {240 ok(typeof image.clone == 'function');241 image.clone(function(clone) {242 ok(clone instanceof fabric.Image);243 deepEqual(clone.toObject(), image.toObject());244 start();245 });246 });247 });248 asyncTest('cloneWidthHeight', function() {249 createSmallImageObject(function(image) {250 image.clone(function(clone) {251 equal(clone.width, IMG_WIDTH / 2,252 'clone\'s element should have width identical to that of original image');253 equal(clone.height, IMG_HEIGHT / 2,254 'clone\'s element should have height identical to that of original image');255 start();256 });257 });258 });259 asyncTest('fromObject', function() {260 ok(typeof fabric.Image.fromObject == 'function');261 // should not throw error when no callback is given262 var obj = fabric.util.object.extend(fabric.util.object.clone(REFERENCE_IMG_OBJECT), {263 src: IMG_SRC264 });265 fabric.Image.fromObject(obj, function(instance){266 ok(instance instanceof fabric.Image);267 start();268 });269 });270 asyncTest('fromURL', function() {271 ok(typeof fabric.Image.fromURL == 'function');272 fabric.Image.fromURL(IMG_SRC, function(instance) {273 ok(instance instanceof fabric.Image);274 deepEqual(REFERENCE_IMG_OBJECT, instance.toObject());275 start();276 });277 });278 asyncTest('fromElement', function() {279 function makeImageElement(attributes) {280 var element = _createImageElement();281 if (fabric.isLikelyNode) {282 element.getAttribute = function(x) {283 return element[x];284 };285 element.setAttribute = function(x, value) {286 element[x] = value;287 };288 }289 for (var prop in attributes) {290 element.setAttribute(prop, attributes[prop]);291 }292 return element;293 }294 var IMAGE_DATA_URL = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAARCAYAAADtyJ2fAAAACXBIWXMAAAsSAAALEgHS3X78AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAVBJREFUeNqMU7tOBDEMtENuy614/QE/gZBOuvJK+Et6CiQ6JP6ExxWI7bhL1vgVExYKLPmsTTIzjieHd+MZZSBIAJwEyJU0EWaum+lNljRux3O6nl70Gx/GUwUeyYcDJWZNhMK1aEXYe95Mz4iP44kDTRUZSWSq1YEHri0/HZxXfGSFBN+qDEJTrNI+QXRBviZ7eWCQgjsg+IHiHYB30MhqUxwcmH1Arc2kFDwkBldeFGJLPqs/AbbF2dWgUym6Z2Tb6RVzYxG1wUnmaNcOonZiU0++l6C7FzoQY42g3+8jz+GZ+dWMr1rRH0OjAFhPO+VJFx/vWDqPmk8H97CGBUYUiqAGW0PVe1+aX8j2Ll0tgHtvLx6AK9Tu1ZTFTQ0ojChqGD4qkOzeAuzVfgzsaTym1ClS+IdwtQCFooQMBTumNun1H6Bfcc9/MUn4R3wJMAAZH6MmA4ht4gAAAABJRU5ErkJggg==';295 ok(typeof fabric.Image.fromElement == 'function', 'fromElement should exist');296 var imageEl = makeImageElement({297 width: '14',298 height: '17',299 'xlink:href': IMAGE_DATA_URL300 });301 fabric.Image.fromElement(imageEl, function(imgObject) {302 ok(imgObject instanceof fabric.Image);303 deepEqual(imgObject.get('width'), 14, 'width of an object');304 deepEqual(imgObject.get('height'), 17, 'height of an object');305 deepEqual(imgObject.getSrc(), IMAGE_DATA_URL, 'src of an object');306 start();307 });308 });309 // asyncTest('minimumScale', function() {310 // createImageObject(function(image) {311 // ok(typeof image.toObject == 'function');312 // var filter = new fabric.Image.filters.Resize({resizeType: 'sliceHack', scaleX: 0.2, scaleY: 0.2});313 // image.resizeFilters.push(filter);314 // var width = image.width, height = image.height;315 // ok(image.resizeFilters[0] instanceof fabric.Image.filters.Resize, 'should inherit from fabric.Image.filters.Resize');316 // var toObject = image.toObject();317 // fabric.Image.fromObject(toObject, function(_imageFromObject) {318 // var filterFromObj = _imageFromObject.resizeFilters[0];319 // ok(filterFromObj instanceof fabric.Image.filters.Resize, 'should inherit from fabric.Image.filters.Resize');320 // equal(filterFromObj.scaleY, 0.2);321 // equal(filterFromObj.scaleX, 0.2);322 // var canvasEl = _imageFromObject.applyFilters(null, _imageFromObject.resizeFilters, _imageFromObject._originalElement, true);323 // start();324 // });325 // });326 // });...
binding.js
Source:binding.js
1// ========================================================================2// SC.Binding Tests3// ========================================================================4/*globals module test ok isObj equals expects */5var fromObject, toObject, binding, Bon1, bon2 ; // global variables6suite("basic object binding", {7 8 setup: function() {9 fromObject = SC.Object.create({ value: 'start' }) ;10 toObject = SC.Object.create({ value: 'end' }) ;11 binding = SC.Binding.from("value", fromObject).to("value", toObject).connect() ;12 SC.Binding.flushPendingChanges() ; // actually sets up up the connection13 }14});15 16test("binding is connected", function() {17 equals(binding.isConnected, true, "binding.isConnected") ;18});19test("binding has actually been setup", function() {20 equals(binding._connectionPending, false, "binding._connectionPending") ;21});22test("binding should have synced on connect", function() {23 equals(toObject.get("value"), "start", "toObject.value should match fromObject.value");24});25test("changing fromObject should mark binding as dirty", function() {26 fromObject.set("value", "change") ;27 equals(binding._changePending, true) ;28});29test("fromObject change should propogate to toObject only after flush", function() {30 fromObject.set("value", "change") ;31 equals(toObject.get("value"), "start") ;32 SC.Binding.flushPendingChanges() ;33 equals(toObject.get("value"), "change") ; 34});35test("changing toObject should mark binding as dirty", function() {36 toObject.set("value", "change") ;37 equals(binding._changePending, true) ;38});39test("toObject change should propogate to fromObject only after flush", function() {40 toObject.set("value", "change") ;41 equals(fromObject.get("value"), "start") ;42 SC.Binding.flushPendingChanges() ;43 equals(fromObject.get("value"), "change") ; 44});45test("suspended observing during bindings", function() {46 // setup special binding47 fromObject = SC.Object.create({48 value1: 'value1',49 value2: 'value2'50 });51 52 toObject = SC.Object.create({53 value1: 'value1',54 value2: 'value2',55 56 callCount: 0,57 58 observer: function() {59 equals(this.get('value1'), 'CHANGED', 'value1 when observer fires');60 equals(this.get('value2'), 'CHANGED', 'value2 when observer fires');61 this.callCount++;62 }.observes('value1', 'value2')63 });64 65 toObject.bind('value1', fromObject, 'value1');66 toObject.bind('value2', fromObject, 'value2');67 // change both value1 + value2, then flush bindings. observer should only68 // fire after bindings are done flushing.69 fromObject.set('value1', 'CHANGED').set('value2', 'CHANGED');70 SC.Binding.flushPendingChanges();71 72 equals(toObject.callCount, 2, 'should call observer twice');73});74test("binding will disconnect", function() {75 binding.disconnect();76 equals(binding.isConnected, false, "binding.isConnected");77});78test("binding disconnection actually works", function() {79 binding.disconnect();80 fromObject.set('value', 'change');81 SC.Binding.flushPendingChanges();82 equals(toObject.get('value'), 'start');83});84suite("one way binding", {85 86 setup: function() {87 fromObject = SC.Object.create({ value: 'start' }) ;88 toObject = SC.Object.create({ value: 'end' }) ;89 binding = SC.Binding.from("value", fromObject).to("value", toObject).oneWay().connect() ;90 SC.Binding.flushPendingChanges() ; // actually sets up up the connection91 }92 93});94 95test("changing fromObject should mark binding as dirty", function() {96 fromObject.set("value", "change") ;97 equals(binding._changePending, true) ;98});99test("fromObject change should propogate after flush", function() {100 fromObject.set("value", "change") ;101 equals(toObject.get("value"), "start") ;102 SC.Binding.flushPendingChanges() ;103 equals(toObject.get("value"), "change") ; 104});105test("changing toObject should not make binding dirty", function() {106 toObject.set("value", "change") ;107 equals(binding._changePending, false) ;108});109test("toObject change should falseT propogate", function() {110 toObject.set("value", "change") ;111 equals(fromObject.get("value"), "start") ;112 SC.Binding.flushPendingChanges() ;113 equals(fromObject.get("value"), "start") ; 114});115var first, second, third, binding1, binding2 ; // global variables116suite("chained binding", {117 118 setup: function() {119 first = SC.Object.create({ output: 'first' }) ;120 121 second = SC.Object.create({ 122 input: 'second',123 output: 'second',124 125 inputDidChange: function() {126 this.set("output", this.get("input")) ;127 }.observes("input") 128 }) ;129 130 third = SC.Object.create({ input: "third" }) ;131 132 binding1 = SC.Binding.from("output", first).to("input", second).connect() ;133 binding2 = SC.Binding.from("output", second).to("input", third).connect() ;134 SC.Binding.flushPendingChanges() ; // actually sets up up the connection135 }136 137});138test("changing first output should propograte to third after flush", function() {139 first.set("output", "change") ;140 equals("change", first.get("output"), "first.output") ;141 ok("change" !== third.get("input"), "third.input") ;142 143 var didChange = true;144 while(didChange) didChange = SC.Binding.flushPendingChanges() ;145 146 // bindings should not have bending changes147 equals(binding1._changePending, false, "binding1._changePending") ;148 equals(binding2._changePending, false, "binding2._changePending") ;149 150 equals("change", first.get("output"), "first.output") ;151 equals("change", second.get("input"), "second.input") ;152 equals("change", second.get("output"), "second.output") ;153 equals("change", third.get("input"), "third.input") ;154});155suite("Custom Binding", {156 157 setup: function() {158 Bon1 = SC.Object.extend({159 value1: "hi",160 value2: 83,161 array1: []162 });163 164 bon2 = SC.Object.create({165 val1: "hello",166 val2: 25,167 arr: [1,2,3,4]168 });169 170 TestNamespace = {171 bon2: bon2,172 Bon1: Bon1173 } ;174 },175 176 teardown: function() { 177 delete Bon1 ;178 delete bon2 ;179 //delete TestNamespace;180 }181});182test("Binding value1 such that it will recieve only single values", function() {183 var bon1 = Bon1.create({184 value1Binding: SC.Binding.single("TestNamespace.bon2.val1"),185 array1Binding: SC.Binding.single("TestNamespace.bon2.arr")186 });187 SC.Binding.flushPendingChanges();188 var a = [23,31,12,21];189 bon2.set("arr", a);190 bon2.set("val1","changed");191 SC.Binding.flushPendingChanges();192 equals(bon2.get("val1"),bon1.get("value1"));193 equals("@@MULT@@",bon1.get("array1"));194 bon1.destroy();195});196test("Single binding using notEmpty function.", function() {197 var bond = Bon1.create ({198 array1Binding: SC.Binding.single("TestNamespace.bon2.arr").notEmpty(null,'(EMPTY)')199 });200 SC.Binding.flushPendingChanges();201 bon2.set("arr", []);202 SC.Binding.flushPendingChanges();203 equals("(EMPTY)",bond.get("array1"));204});205test("Binding with transforms, function to check the type of value", function() {206 var jon = Bon1.create({207 value1Binding: SC.Binding.transform(function(val1) {208 return (SC.typeOf(val1) == SC.T_STRING)? val1 : "";209 }).from("TestNamespace.bon2.val1")210 });211 SC.Binding.flushPendingChanges();212 bon2.set("val1","changed");213 SC.Binding.flushPendingChanges();214 equals(jon.get("value1"), bon2.get("val1"));215});216test("two bindings to the same value should sync in the order they are initialized", function() {217 SC.LOG_BINDINGS = true;218 SC.RunLoop.begin();219 window.a = SC.Object.create({ 220 foo: "bar" 221 });222 223 var a = window.a;224 225 window.b = SC.Object.create({ 226 foo: "baz",227 fooBinding: "a.foo",228 229 C: SC.Object.extend({230 foo: "bee",231 fooBinding: "*owner.foo"232 }),233 234 init: function() {235 arguments.callee.base.apply(this, arguments);236 this.set('c', this.C.create({ owner: this }));237 }238 239 });240 241 var b = window.b;242 SC.LOG_BINDINGS = true;243 244 SC.RunLoop.end();245 246 equals(a.get('foo'), "bar", 'a.foo should not change');247 equals(b.get('foo'), "bar", 'a.foo should propogate up to b.foo');248 equals(b.c.get('foo'), "bar", 'a.foo should propogate up to b.c.foo');249 250 window.a = window.b = null ;251 252});253suite("AND binding", {254 setup: function() {255 // temporarily set up two source objects in the SC namespace so we can256 // use property paths to access them257 SC.testControllerA = SC.Object.create({ value: false });258 SC.testControllerB = SC.Object.create({ value: false });259 toObject = SC.Object.create({260 value: null,261 valueBinding: SC.Binding.and('SC.testControllerA.value', 'SC.testControllerB.value')262 });263 },264 teardown: function() {265 delete SC.testControllerA;266 delete SC.testControllerB;267 }268 269});270test("toObject.value should be true if both sources are true", function() {271 SC.RunLoop.begin();272 SC.testControllerA.set('value', true);273 SC.testControllerB.set('value', true);274 SC.RunLoop.end();275 SC.Binding.flushPendingChanges();276 equals(toObject.get('value'), true);277});278test("toObject.value should be false if either source is false", function() {279 SC.RunLoop.begin();280 SC.testControllerA.set('value', true);281 SC.testControllerB.set('value', false);282 SC.RunLoop.end();283 SC.Binding.flushPendingChanges();284 equals(toObject.get('value'), false);285 SC.RunLoop.begin();286 SC.testControllerA.set('value', true);287 SC.testControllerB.set('value', true);288 SC.RunLoop.end();289 SC.Binding.flushPendingChanges();290 equals(toObject.get('value'), true);291 SC.RunLoop.begin();292 SC.testControllerA.set('value', false);293 SC.testControllerB.set('value', true);294 SC.RunLoop.end();295 SC.Binding.flushPendingChanges();296 equals(toObject.get('value'), false);297});298suite("OR binding", {299 setup: function() {300 // temporarily set up two source objects in the SC namespace so we can301 // use property paths to access them302 SC.testControllerA = SC.Object.create({ value: false });303 SC.testControllerB = SC.Object.create({ value: null });304 toObject = SC.Object.create({305 value: null,306 valueBinding: SC.Binding.or('SC.testControllerA.value', 'SC.testControllerB.value')307 });308 },309 teardown: function() {310 delete SC.testControllerA;311 delete SC.testControllerB;312 }313 314});315test("toObject.value should be first value if first value is truthy", function() {316 SC.RunLoop.begin();317 SC.testControllerA.set('value', 'first value');318 SC.testControllerB.set('value', 'second value');319 SC.RunLoop.end();320 SC.Binding.flushPendingChanges();321 equals(toObject.get('value'), 'first value');322});323test("toObject.value should be second value if first is falsy", function() {324 SC.RunLoop.begin();325 SC.testControllerA.set('value', false);326 SC.testControllerB.set('value', 'second value');327 SC.RunLoop.end();328 SC.Binding.flushPendingChanges();329 equals(toObject.get('value'), 'second value');330});331suite("Binding with '[]'", {332 setup: function() {333 fromObject = SC.Object.create({ value: [] });334 toObject = SC.Object.create({ value: '' });335 binding = SC.Binding.transform(function(v) {336 return v ? v.join(',') : '';337 }).from("value.[]", fromObject).to("value", toObject).connect();338 }339});340test("Binding refreshes after a couple of items have been pushed in the array", function() {341 fromObject.get('value').pushObjects(['foo', 'bar']);342 SC.Binding.flushPendingChanges();343 equals(toObject.get('value'), 'foo,bar');...
number-test.js
Source:number-test.js
...8 });9 test('no options', function(assert) {10 assert.expect(2);11 builtOptions = validator.buildOptions({});12 message = validator.validate(undefined, builtOptions.toObject());13 assert.equal(message, true);14 message = validator.validate(22, builtOptions.toObject());15 assert.equal(message, true);16 });17 test('allow string', function(assert) {18 assert.expect(6);19 options = {20 allowString: true21 };22 builtOptions = validator.buildOptions(options);23 message = validator.validate('22', builtOptions.toObject());24 assert.equal(message, true);25 message = validator.validate('22.22', builtOptions.toObject());26 assert.equal(message, true);27 message = validator.validate('test', builtOptions.toObject());28 assert.equal(message, 'This field must be a number');29 message = validator.validate('', builtOptions.toObject());30 assert.equal(message, 'This field must be a number');31 options.allowString = false;32 builtOptions = validator.buildOptions(options);33 message = validator.validate('22', builtOptions.toObject());34 assert.equal(message, 'This field must be a number');35 message = validator.validate('22.22', builtOptions.toObject());36 assert.equal(message, 'This field must be a number');37 });38 test('integer', function(assert) {39 assert.expect(3);40 options = {41 integer: true42 };43 builtOptions = validator.buildOptions(options);44 message = validator.validate(22, builtOptions.toObject());45 assert.equal(message, true);46 message = validator.validate(22.22, builtOptions.toObject());47 assert.equal(message, 'This field must be an integer');48 message = validator.validate(-2.2, builtOptions.toObject());49 assert.equal(message, 'This field must be an integer');50 });51 test('is', function(assert) {52 assert.expect(2);53 options = {54 is: 2255 };56 builtOptions = validator.buildOptions(options);57 message = validator.validate(1, builtOptions.toObject());58 assert.equal(message, 'This field must be equal to 22');59 message = validator.validate(22, builtOptions.toObject());60 assert.equal(message, true);61 });62 test('lt', function(assert) {63 assert.expect(3);64 options = {65 lt: 2266 };67 builtOptions = validator.buildOptions(options);68 message = validator.validate(21, builtOptions.toObject());69 assert.equal(message, true);70 message = validator.validate(22, builtOptions.toObject());71 assert.equal(message, 'This field must be less than 22');72 message = validator.validate(23, builtOptions.toObject());73 assert.equal(message, 'This field must be less than 22');74 });75 test('lte', function(assert) {76 assert.expect(3);77 options = {78 lte: 2279 };80 builtOptions = validator.buildOptions(options);81 message = validator.validate(21, builtOptions.toObject());82 assert.equal(message, true);83 message = validator.validate(22, builtOptions.toObject());84 assert.equal(message, true);85 message = validator.validate(23, builtOptions.toObject());86 assert.equal(message, 'This field must be less than or equal to 22');87 });88 test('gt', function(assert) {89 assert.expect(3);90 options = {91 gt: 2292 };93 builtOptions = validator.buildOptions(options);94 message = validator.validate(21, builtOptions.toObject());95 assert.equal(message, 'This field must be greater than 22');96 message = validator.validate(22, builtOptions.toObject());97 assert.equal(message, 'This field must be greater than 22');98 message = validator.validate(23, builtOptions.toObject());99 assert.equal(message, true);100 });101 test('gte', function(assert) {102 assert.expect(3);103 options = {104 gte: 22105 };106 builtOptions = validator.buildOptions(options);107 message = validator.validate(21, builtOptions.toObject());108 assert.equal(message, 'This field must be greater than or equal to 22');109 message = validator.validate(22, builtOptions.toObject());110 assert.equal(message, true);111 message = validator.validate(23, builtOptions.toObject());112 assert.equal(message, true);113 });114 test('positive', function(assert) {115 assert.expect(4);116 options = {117 positive: true118 };119 builtOptions = validator.buildOptions(options);120 message = validator.validate(-1, builtOptions.toObject());121 assert.equal(message, 'This field must be positive');122 message = validator.validate(-144, builtOptions.toObject());123 assert.equal(message, 'This field must be positive');124 message = validator.validate(0, builtOptions.toObject());125 assert.equal(message, true);126 message = validator.validate(22, builtOptions.toObject());127 assert.equal(message, true);128 });129 test('odd', function(assert) {130 assert.expect(4);131 options = {132 odd: true133 };134 builtOptions = validator.buildOptions(options);135 message = validator.validate(22, builtOptions.toObject());136 assert.equal(message, 'This field must be odd');137 message = validator.validate(-144, builtOptions.toObject());138 assert.equal(message, 'This field must be odd');139 message = validator.validate(21, builtOptions.toObject());140 assert.equal(message, true);141 message = validator.validate(-21, builtOptions.toObject());142 assert.equal(message, true);143 });144 test('even', function(assert) {145 assert.expect(5);146 options = {147 even: true148 };149 builtOptions = validator.buildOptions(options);150 message = validator.validate(22, builtOptions.toObject());151 assert.equal(message, true);152 message = validator.validate(-22, builtOptions.toObject());153 assert.equal(message, true);154 message = validator.validate(22.22, builtOptions.toObject());155 assert.equal(message, 'This field must be even');156 message = validator.validate(21, builtOptions.toObject());157 assert.equal(message, 'This field must be even');158 message = validator.validate(-33, builtOptions.toObject());159 assert.equal(message, 'This field must be even');160 });161 test('allowBlank', function(assert) {162 assert.expect(3);163 options = {164 allowBlank: true165 };166 builtOptions = validator.buildOptions(options);167 message = validator.validate(null, builtOptions.toObject());168 assert.equal(message, true);169 message = validator.validate(undefined, builtOptions.toObject());170 assert.equal(message, true);171 message = validator.validate('', builtOptions.toObject());172 assert.equal(message, true);173 });...
all_types.js
Source:all_types.js
...59 assert(fromObject(allTypes), "serializable" )60 assert(fromObject(fromObject(allTypes)), "non-serializable")61 })62 it("to object", ()=> {63 assert(toObject(allTypes), "serializable" )64 assert.deepEqual(toObject(allTypes), toObject(allTypes), "serializable (single to)" )65 assert.deepEqual(toObject(toObject(allTypes)), toObject(allTypes), "serializable (double to)" )66 assert.deepEqual(toObject(fromObject(allTypes)), toObject(allTypes), "non-serializable" )67 assert.deepEqual(toObject(fromObject(fromObject(allTypes))), toObject(allTypes), "non-serializable (double from)")68 })69 it("to buffer", ()=>{70 assert(toBuffer(allTypes), "serializable" )71 assert(toBuffer(fromObject(allTypes)), "non-serializable")72 assert.equal(73 toBuffer( allTypes ).toString("hex"), // serializable74 toBuffer( fromObject( allTypes )).toString("hex"), // non-serializable75 "serializable and non-serializable"76 )77 })78 it("from buffer", ()=> {79 assert.deepEqual(toObject(fromBuffer(toBuffer(allTypes))), toObject(allTypes), "serializable" )80 assert.deepEqual(toObject(fromBuffer(toBuffer(fromObject(allTypes)))), toObject(allTypes), "non-serializable" )81 })82 it("template", ()=> {83 assert(toObject(allTypes, {use_default: true}))84 assert(toObject(allTypes, {annotate: true}))85 assert(toObject({}, {use_default: true}))86 assert(toObject({}, {use_default: true, annotate: true}))87 })88 // keep last89 it("visual check", ()=> {90 console.log(toObject(fromObject(allTypes)))91 })...
inclusion-test.js
Source:inclusion-test.js
...7 validator = this.owner.lookup('validator:inclusion');8 });9 test('no options', function(assert) {10 assert.expect(1);11 builtOptions = validator.buildOptions({}).toObject();12 try {13 message = validator.validate(undefined, builtOptions);14 } catch (e) {15 assert.ok(true);16 }17 });18 test('allow blank', function(assert) {19 assert.expect(2);20 options = {21 allowBlank: true,22 in: ['foo', 'bar', 'baz']23 };24 builtOptions = validator.buildOptions(options);25 message = validator.validate('', builtOptions.toObject());26 assert.equal(message, true);27 message = validator.validate('test', builtOptions.toObject());28 assert.equal(message, 'This field is not included in the list');29 });30 test('in array', function(assert) {31 assert.expect(4);32 options = {33 in: ['foo', 'bar', 'baz']34 };35 builtOptions = validator.buildOptions(options);36 message = validator.validate('test', builtOptions.toObject());37 assert.equal(message, 'This field is not included in the list');38 message = validator.validate('foo', builtOptions.toObject());39 assert.equal(message, true);40 message = validator.validate('bar', builtOptions.toObject());41 assert.equal(message, true);42 message = validator.validate('baz', builtOptions.toObject());43 assert.equal(message, true);44 });45 test('in range', function(assert) {46 assert.expect(5);47 options = {48 range: [1, 10]49 };50 builtOptions = validator.buildOptions(options);51 message = validator.validate(0, builtOptions.toObject());52 assert.equal(message, 'This field is not included in the list');53 message = validator.validate(100, builtOptions.toObject());54 assert.equal(message, 'This field is not included in the list');55 message = validator.validate(1, builtOptions.toObject());56 assert.equal(message, true);57 message = validator.validate(5, builtOptions.toObject());58 assert.equal(message, true);59 message = validator.validate(10, builtOptions.toObject());60 assert.equal(message, true);61 });62 test('range type check - number', function(assert) {63 assert.expect(7);64 options = {65 range: [1, 10]66 };67 builtOptions = validator.buildOptions(options);68 message = validator.validate('0', builtOptions.toObject());69 assert.equal(message, 'This field is not included in the list');70 message = validator.validate(0, builtOptions.toObject());71 assert.equal(message, 'This field is not included in the list');72 message = validator.validate('1', builtOptions.toObject());73 assert.equal(message, 'This field is not included in the list');74 message = validator.validate('5', builtOptions.toObject());75 assert.equal(message, 'This field is not included in the list');76 message = validator.validate(1, builtOptions.toObject());77 assert.equal(message, true);78 message = validator.validate(5, builtOptions.toObject());79 assert.equal(message, true);80 message = validator.validate(10, builtOptions.toObject());81 assert.equal(message, true);82 });83 test('range type check - string', function(assert) {84 assert.expect(5);85 options = {86 range: ['a', 'z']87 };88 builtOptions = validator.buildOptions(options);89 message = validator.validate(97, builtOptions.toObject());90 assert.equal(message, 'This field is not included in the list');91 message = validator.validate('zzz', builtOptions.toObject());92 assert.equal(message, 'This field is not included in the list');93 message = validator.validate('a', builtOptions.toObject());94 assert.equal(message, true);95 message = validator.validate('o', builtOptions.toObject());96 assert.equal(message, true);97 message = validator.validate('z', builtOptions.toObject());98 assert.equal(message, true);99 });...
Mt3dPackageFactory.test.js
Source:Mt3dPackageFactory.test.js
1import AdvPackage from '../../../../src/core/modflow/mt3d/advPackage';2import BtnPackage from '../../../../src/core/modflow/mt3d/btnPackage';3import DspPackage from '../../../../src/core/modflow/mt3d/dspPackage';4import GcgPackage from '../../../../src/core/modflow/mt3d/gcgPackage';5import Mt3dPackageFactory from '../../../../src/core/modflow/mt3d/Mt3dPackageFactory';6import MtPackage from '../../../../src/core/modflow/mt3d/mtPackage';7import SsmPackage from '../../../../src/core/modflow/mt3d/ssmPackage';8test('Create Adv-Package from Object', () => {9 const p = AdvPackage.fromDefault();10 expect(Mt3dPackageFactory.fromData(p.toObject)).toBeInstanceOf(AdvPackage);11 expect(Mt3dPackageFactory.fromData(p.toObject).toObject).toEqual(p.toObject);12});13test('Create Btn-Package from Object', () => {14 const p = BtnPackage.fromDefault();15 expect(Mt3dPackageFactory.fromData(p.toObject)).toBeInstanceOf(BtnPackage);16 expect(Mt3dPackageFactory.fromData(p.toObject).toObject).toEqual(p.toObject);17});18test('Create Dsp-Package from Object', () => {19 const p = DspPackage.fromDefault();20 expect(Mt3dPackageFactory.fromData(p.toObject)).toBeInstanceOf(DspPackage);21 expect(Mt3dPackageFactory.fromData(p.toObject).toObject).toEqual(p.toObject);22});23test('Create Gcg-Package from Object', () => {24 const p = GcgPackage.fromDefault();25 expect(Mt3dPackageFactory.fromData(p.toObject)).toBeInstanceOf(GcgPackage);26 expect(Mt3dPackageFactory.fromData(p.toObject).toObject).toEqual(p.toObject);27});28test('Create Mt-Package from Object', () => {29 const p = MtPackage.fromDefault();30 expect(Mt3dPackageFactory.fromData(p.toObject)).toBeInstanceOf(MtPackage);31 expect(Mt3dPackageFactory.fromData(p.toObject).toObject).toEqual(p.toObject);32});33test('Create Ssm-Package from Object', () => {34 const p = SsmPackage.fromDefault();35 expect(Mt3dPackageFactory.fromData(p.toObject)).toBeInstanceOf(SsmPackage);36 expect(Mt3dPackageFactory.fromData(p.toObject).toObject).toEqual(p.toObject);37});38test('Create default Object', () => {39 expect(Mt3dPackageFactory.fromData('', {})).toBeNull();...
Using AI Code Generation
1const { toObject } = require('playwright/lib/utils/structs');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const element = await page.$('text=Learn more');7 const rect = await element.boundingBox();8 console.log(toObject(rect));9 await browser.close();10})();11{12}
Using AI Code Generation
1const { toObject } = require('playwright/lib/server/frames');2const { toObject: toObject2 } = require('playwright/lib/server/dom');3const { toObject: toObject3 } = require('playwright/lib/server/locator');4const { toObject: toObject4 } = require('playwright/lib/server/elementHandleDispatcher');5const { toObject: toObject5 } = require('playwright/lib/server/elementHandle');6const { toObject: toObject6 } = require('playwright/lib/server/page');7const { toObject: toObject7 } = require('playwright/lib/server/pageDispatcher');8const { toObject: toObject8 } = require('playwright/lib/server/elementHandle');9const { toObject: toObject9 } = require('playwright/lib/server/elementHandleDispatcher');10const { toObject: toObject10 } = require('playwright/lib/server/elementHandle');11const { toObject: toObject11 } = require('playwright/lib/server/elementHandleDispatcher');12const { toObject: toObject12 } = require('playwright/lib/server/elementHandle');13const { toObject: toObject13 } = require('playwright/lib/server/elementHandleDispatcher');14const { toObject: toObject14 } = require('playwright/lib/server/elementHandle');15const { toObject: toObject15 } = require('playwright/lib/server/elementHandleDispatcher');16const { toObject: toObject16 } = require('playwright/lib/server/elementHandle');17const { toObject: toObject17 } = require('playwright/lib/server/elementHandleDispatcher');18const { toObject: toObject18 } = require('playwright/lib/server/elementHandle');19const { toObject: toObject19 } = require('playwright/lib/server/elementHandleDispatcher');20const { toObject: toObject20 } = require('playwright/lib/server/elementHandle');21const { toObject: toObject21 } = require('playwright/lib/server/elementHandleDispatcher');22const { toObject: toObject22 } = require('playwright/lib/server/elementHandle');23const { toObject: toObject23 } = require('playwright/lib/server/elementHandleDispatcher');24const { toObject: toObject24 } = require('playwright/lib/server/elementHandle');25const { toObject: toObject25 } = require('playwright/lib/server/elementHandle
Using AI Code Generation
1const { toObject } = require('playwright/lib/utils/structs.js');2const { Page } = require('playwright/lib/server/page.js');3const page = new Page();4console.log(toObject(page));5const { toObject } = require('playwright/lib/utils/structs.js');6const { Page } = require('playwright/lib/server/page.js');7const page = new Page();8console.log(toObject(page));9const { toObject } = require('playwright/lib/utils/structs.js');10const { Page } = require('playwright/lib/server/page.js');11const page = new Page();12console.log(toObject(page));13const { toObject } = require('playwright/lib/utils/structs.js');14const { Page } = require('playwright/lib/server/page.js');15const page = new Page();16console.log(toObject(page));17const { toObject } = require('playwright/lib/utils/structs.js');18const { Page } = require('playwright/lib/server/page.js');19const page = new Page();20console.log(toObject(page));21const { toObject } = require('playwright/lib/utils/structs.js');22const { Page } = require('playwright/lib/server/page.js');23const page = new Page();24console.log(toObject(page));25const { toObject } = require('playwright/lib/utils/structs.js');26const { Page } = require('playwright/lib/server/page.js');27const page = new Page();28console.log(toObject(page));
Using AI Code Generation
1const { toObject } = require('playwright/lib/utils/structs');2const { Page } = require('playwright/lib/server/page');3const page = new Page();4page.on('request', (request) => {5 console.log(toObject(request));6});7const { toObject } = require('playwright/lib/utils/structs');8const { Page } = require('playwright/lib/server/page');9const page = new Page();10page.on('request', (request) => {11 console.log(toObject(request));12});13const { toObject } = require('playwright/lib/utils/structs');14const { Page } = require('playwright/lib/server/page');15const page = new Page();16page.on('request', (request) => {17 console.log(toObject(request));18});19const { toObject } = require('playwright/lib/utils/structs');20const { Page } = require('playwright/lib/server/page');21const page = new Page();22page.on('request', (request) => {23 console.log(toObject(request));24});25const { toObject } = require('playwright/lib/utils/structs');26const { Page } = require('playwright/lib/server/page');27const page = new Page();28page.on('request', (request) => {29 console.log(toObject(request));30});31const { toObject } = require('playwright/lib/utils/structs');32const { Page } = require('playwright/lib/server/page');33const page = new Page();34page.on('request', (request) => {35 console.log(toObject(request));36});37const { toObject } = require('playwright/lib/utils/structs');38const { Page } = require('playwright/lib/server/page');39const page = new Page();40page.on('request', (request) => {41 console.log(toObject(request));42});
Using AI Code Generation
1const { toObject } = require('playwright/lib/utils/structs.js');2const { generateTestResult } = require('playwright/lib/test/reporter.js');3const { TestResult } = require('playwright/lib/test/test.js');4const testResult = generateTestResult(new TestResult('test', 'passed', 0, 0));5console.log(toObject(testResult));6const { toObject } = require('playwright/lib/utils/structs.js');7const { generateTestResult } = require('playwright/lib/test/reporter.js');8const { TestResult } = require('playwright/lib/test/test.js');9const testResult = generateTestResult(new TestResult('test', 'passed', 0, 0));10console.log(toObject(testResult));11const { toObject } = require('playwright/lib/utils/structs.js');12const { generateTestResult } = require('playwright/lib/test/reporter.js');13const { TestResult } = require('playwright/lib/test/test.js');14const testResult = generateTestResult(new TestResult('test', 'passed', 0, 0));15console.log(toObject(testResult));16const { toObject } = require('playwright/lib/utils/structs.js');17const { generateTestResult } = require('playwright/lib/test/reporter.js');18const { TestResult } = require('playwright/lib/test/test.js');19const testResult = generateTestResult(new TestResult('test', 'passed', 0, 0));20console.log(toObject(testResult));21const { toObject } = require('playwright/lib/utils/structs.js');22const { generateTestResult } = require('playwright/lib/test/reporter.js');23const { TestResult } = require('playwright/lib/test/test.js');24const testResult = generateTestResult(new TestResult('test', 'passed', 0, 0));25console.log(toObject(testResult));26const { toObject } = require('playwright/lib/utils/structs.js');27const { generateTestResult }
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!