How to use extend method in sinon

Best JavaScript code snippet using sinon

es5-visitors.js

Source:es5-visitors.js Github

copy

Full Screen

...390 else {391 // don't throw here, because there can be a valid js extend that has nothing to do with NS392 return;393 throw {394 message: "You need to call the extend with parameters. Example: '...extend(\"a.b.C\", {...overrides...})') in file: " + config.filePath,395 errCode: 1396 }397 }398 className = arg0.value ? arg0.value : "";399 // Get all methods from the implementation object400 var methodsAndInterfaces = _getOverridenMethodsAndImplementedInterfaces(arg1, config);401 var overriddenMethodNames = methodsAndInterfaces[0];402 var implementedInterfaces = methodsAndInterfaces[1];403 var isCorrectExtendClassName = _testJavaProxyName(className);404 var isCorrectClassName = _testClassName(className);405 if (className && !isCorrectClassName && !isCorrectExtendClassName) {406 throw {407 message: "The 'extend' you are trying to make has an invalid name. Example: '...extend(\"a.b.C\", {...overrides...})'), file: " + config.filePath,408 errCode: 1409 }410 }411 var lineToWrite = "";412 if (isCorrectExtendClassName) {413 if (config.logger) {414 config.logger.info(lineToWrite)415 }416 var classNameFromDecorator = isCorrectExtendClassName ? className : "";417 lineToWrite = _generateLineToWrite(classNameFromDecorator, extendClass.reverse().join("."), overriddenMethodNames, "", config.fullPathName, implementedInterfaces);418 addCustomExtend(classNameFromDecorator, config.fullPathName, lineToWrite);419 return;420 }421 if (config.logger) {422 config.logger.info(lineToWrite)423 }424 var extendInfo = {425 file: config.filePath,426 line: path.node.property.loc.start.line,427 column: path.node.property.loc.start.column + columnOffset,428 className: className429 };430 lineToWrite = _generateLineToWrite(isCorrectExtendClassName ? className : "", extendClass.reverse().join("."), overriddenMethodNames, extendInfo, "", implementedInterfaces);431 normalExtendsArr.push(lineToWrite)432 }433 else {434 // don't throw here, because there can be a valid js extend that has nothing to do with NS435 return;436 throw {437 message: "You need to call the extend '...extend(\"extend_name\", {...overrides...})'), file: " + config.filePath,438 errCode: 1439 }440 }441 }442 /* 443 * HELPER METHODS444 */445 function _getOverriddenMethods(node, config) {446 var overriddenMethodNames = [];447 if (types.isObjectExpression(node)) {448 var objectProperties = node.properties;449 for (var index in objectProperties) {450 overriddenMethodNames.push(objectProperties[index].key.name);451 }...

Full Screen

Full Screen

proto_test.js

Source:proto_test.js Github

copy

Full Screen

1// Protocol Buffers - Google's data interchange format2// Copyright 2008 Google Inc. All rights reserved.3// https://developers.google.com/protocol-buffers/4//5// Redistribution and use in source and binary forms, with or without6// modification, are permitted provided that the following conditions are7// met:8//9// * Redistributions of source code must retain the above copyright10// notice, this list of conditions and the following disclaimer.11// * Redistributions in binary form must reproduce the above12// copyright notice, this list of conditions and the following disclaimer13// in the documentation and/or other materials provided with the14// distribution.15// * Neither the name of Google Inc. nor the names of its16// contributors may be used to endorse or promote products derived from17// this software without specific prior written permission.18//19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.30// Test suite is written using Jasmine -- see http://jasmine.github.io/31goog.require('goog.crypt.base64');32goog.require('goog.testing.asserts');33goog.require('jspb.Message');34// CommonJS-LoadFromFile: ../testbinary_pb proto.jspb.test35goog.require('proto.jspb.test.ExtendsWithMessage');36goog.require('proto.jspb.test.ForeignEnum');37goog.require('proto.jspb.test.ForeignMessage');38goog.require('proto.jspb.test.TestAllTypes');39goog.require('proto.jspb.test.TestExtendable');40goog.require('proto.jspb.test.extendOptionalBool');41goog.require('proto.jspb.test.extendOptionalBytes');42goog.require('proto.jspb.test.extendOptionalDouble');43goog.require('proto.jspb.test.extendOptionalFixed32');44goog.require('proto.jspb.test.extendOptionalFixed64');45goog.require('proto.jspb.test.extendOptionalFloat');46goog.require('proto.jspb.test.extendOptionalForeignEnum');47goog.require('proto.jspb.test.extendOptionalInt32');48goog.require('proto.jspb.test.extendOptionalInt64');49goog.require('proto.jspb.test.extendOptionalSfixed32');50goog.require('proto.jspb.test.extendOptionalSfixed64');51goog.require('proto.jspb.test.extendOptionalSint32');52goog.require('proto.jspb.test.extendOptionalSint64');53goog.require('proto.jspb.test.extendOptionalString');54goog.require('proto.jspb.test.extendOptionalUint32');55goog.require('proto.jspb.test.extendOptionalUint64');56goog.require('proto.jspb.test.extendPackedRepeatedBoolList');57goog.require('proto.jspb.test.extendPackedRepeatedDoubleList');58goog.require('proto.jspb.test.extendPackedRepeatedFixed32List');59goog.require('proto.jspb.test.extendPackedRepeatedFixed64List');60goog.require('proto.jspb.test.extendPackedRepeatedFloatList');61goog.require('proto.jspb.test.extendPackedRepeatedForeignEnumList');62goog.require('proto.jspb.test.extendPackedRepeatedInt32List');63goog.require('proto.jspb.test.extendPackedRepeatedInt64List');64goog.require('proto.jspb.test.extendPackedRepeatedSfixed32List');65goog.require('proto.jspb.test.extendPackedRepeatedSfixed64List');66goog.require('proto.jspb.test.extendPackedRepeatedSint32List');67goog.require('proto.jspb.test.extendPackedRepeatedSint64List');68goog.require('proto.jspb.test.extendPackedRepeatedUint32List');69goog.require('proto.jspb.test.extendPackedRepeatedUint64List');70goog.require('proto.jspb.test.extendRepeatedBoolList');71goog.require('proto.jspb.test.extendRepeatedBytesList');72goog.require('proto.jspb.test.extendRepeatedDoubleList');73goog.require('proto.jspb.test.extendRepeatedFixed32List');74goog.require('proto.jspb.test.extendRepeatedFixed64List');75goog.require('proto.jspb.test.extendRepeatedFloatList');76goog.require('proto.jspb.test.extendRepeatedForeignEnumList');77goog.require('proto.jspb.test.extendRepeatedInt32List');78goog.require('proto.jspb.test.extendRepeatedInt64List');79goog.require('proto.jspb.test.extendRepeatedSfixed32List');80goog.require('proto.jspb.test.extendRepeatedSfixed64List');81goog.require('proto.jspb.test.extendRepeatedSint32List');82goog.require('proto.jspb.test.extendRepeatedSint64List');83goog.require('proto.jspb.test.extendRepeatedStringList');84goog.require('proto.jspb.test.extendRepeatedUint32List');85goog.require('proto.jspb.test.extendRepeatedUint64List');86var suite = {};87var BYTES = new Uint8Array([1, 2, 8, 9]);88var BYTES_B64 = goog.crypt.base64.encodeByteArray(BYTES);89/**90 * Helper: fill all fields on a TestAllTypes message.91 * @param {proto.jspb.test.TestAllTypes} msg92 */93function fillAllFields(msg) {94 msg.setOptionalInt32(-42);95 // can be exactly represented by JS number (64-bit double, i.e., 52-bit96 // mantissa).97 msg.setOptionalInt64(-0x7fffffff00000000);98 msg.setOptionalUint32(0x80000000);99 msg.setOptionalUint64(0xf000000000000000);100 msg.setOptionalSint32(-100);101 msg.setOptionalSint64(-0x8000000000000000);102 msg.setOptionalFixed32(1234);103 msg.setOptionalFixed64(0x1234567800000000);104 msg.setOptionalSfixed32(-1234);105 msg.setOptionalSfixed64(-0x1234567800000000);106 msg.setOptionalFloat(1.5);107 msg.setOptionalDouble(-1.5);108 msg.setOptionalBool(true);109 msg.setOptionalString('hello world');110 msg.setOptionalBytes(BYTES);111 msg.setOptionalGroup(new proto.jspb.test.TestAllTypes.OptionalGroup());112 msg.getOptionalGroup().setA(100);113 var submsg = new proto.jspb.test.ForeignMessage();114 submsg.setC(16);115 msg.setOptionalForeignMessage(submsg);116 msg.setOptionalForeignEnum(proto.jspb.test.ForeignEnum.FOREIGN_FOO);117 msg.setOneofString('oneof');118 msg.setRepeatedInt32List([-42]);119 msg.setRepeatedInt64List([-0x7fffffff00000000]);120 msg.setRepeatedUint32List([0x80000000]);121 msg.setRepeatedUint64List([0xf000000000000000]);122 msg.setRepeatedSint32List([-100]);123 msg.setRepeatedSint64List([-0x8000000000000000]);124 msg.setRepeatedFixed32List([1234]);125 msg.setRepeatedFixed64List([0x1234567800000000]);126 msg.setRepeatedSfixed32List([-1234]);127 msg.setRepeatedSfixed64List([-0x1234567800000000]);128 msg.setRepeatedFloatList([1.5]);129 msg.setRepeatedDoubleList([-1.5]);130 msg.setRepeatedBoolList([true]);131 msg.setRepeatedStringList(['hello world']);132 msg.setRepeatedBytesList([BYTES, BYTES]);133 msg.setRepeatedGroupList([new proto.jspb.test.TestAllTypes.RepeatedGroup()]);134 msg.getRepeatedGroupList()[0].setA(100);135 submsg = new proto.jspb.test.ForeignMessage();136 submsg.setC(1000);137 msg.setRepeatedForeignMessageList([submsg]);138 msg.setRepeatedForeignEnumList([proto.jspb.test.ForeignEnum.FOREIGN_FOO]);139 msg.setPackedRepeatedInt32List([-42]);140 msg.setPackedRepeatedInt64List([-0x7fffffff00000000]);141 msg.setPackedRepeatedUint32List([0x80000000]);142 msg.setPackedRepeatedUint64List([0xf000000000000000]);143 msg.setPackedRepeatedSint32List([-100]);144 msg.setPackedRepeatedSint64List([-0x8000000000000000]);145 msg.setPackedRepeatedFixed32List([1234]);146 msg.setPackedRepeatedFixed64List([0x1234567800000000]);147 msg.setPackedRepeatedSfixed32List([-1234]);148 msg.setPackedRepeatedSfixed64List([-0x1234567800000000]);149 msg.setPackedRepeatedFloatList([1.5]);150 msg.setPackedRepeatedDoubleList([-1.5]);151 msg.setPackedRepeatedBoolList([true]);152}153/**154 * Helper: compare a bytes field to an expected value155 * @param {Uint8Array|string} arr156 * @param {Uint8Array} expected157 * @return {boolean}158 */159function bytesCompare(arr, expected) {160 if (goog.isString(arr)) {161 arr = goog.crypt.base64.decodeStringToUint8Array(arr);162 }163 if (arr.length != expected.length) {164 return false;165 }166 for (var i = 0; i < arr.length; i++) {167 if (arr[i] != expected[i]) {168 return false;169 }170 }171 return true;172}173/**174 * Helper: verify contents of given TestAllTypes message as set by175 * fillAllFields().176 * @param {proto.jspb.test.TestAllTypes} original177 * @param {proto.jspb.test.TestAllTypes} copy178 */179function checkAllFields(original, copy) {180 assertTrue(jspb.Message.equals(original, copy));181 assertEquals(copy.getOptionalInt32(), -42);182 assertEquals(copy.getOptionalInt64(), -0x7fffffff00000000);183 assertEquals(copy.getOptionalUint32(), 0x80000000);184 assertEquals(copy.getOptionalUint64(), 0xf000000000000000);185 assertEquals(copy.getOptionalSint32(), -100);186 assertEquals(copy.getOptionalSint64(), -0x8000000000000000);187 assertEquals(copy.getOptionalFixed32(), 1234);188 assertEquals(copy.getOptionalFixed64(), 0x1234567800000000);189 assertEquals(copy.getOptionalSfixed32(), -1234);190 assertEquals(copy.getOptionalSfixed64(), -0x1234567800000000);191 assertEquals(copy.getOptionalFloat(), 1.5);192 assertEquals(copy.getOptionalDouble(), -1.5);193 assertEquals(copy.getOptionalBool(), true);194 assertEquals(copy.getOptionalString(), 'hello world');195 assertEquals(true, bytesCompare(copy.getOptionalBytes(), BYTES));196 assertEquals(true, bytesCompare(copy.getOptionalBytes_asU8(), BYTES));197 assertEquals(198 copy.getOptionalBytes_asB64(), goog.crypt.base64.encodeByteArray(BYTES));199 assertEquals(copy.getOptionalGroup().getA(), 100);200 assertEquals(copy.getOptionalForeignMessage().getC(), 16);201 assertEquals(copy.getOptionalForeignEnum(),202 proto.jspb.test.ForeignEnum.FOREIGN_FOO);203 assertEquals(copy.getOneofString(), 'oneof');204 assertEquals(copy.getOneofFieldCase(),205 proto.jspb.test.TestAllTypes.OneofFieldCase.ONEOF_STRING);206 assertElementsEquals(copy.getRepeatedInt32List(), [-42]);207 assertElementsEquals(copy.getRepeatedInt64List(), [-0x7fffffff00000000]);208 assertElementsEquals(copy.getRepeatedUint32List(), [0x80000000]);209 assertElementsEquals(copy.getRepeatedUint64List(), [0xf000000000000000]);210 assertElementsEquals(copy.getRepeatedSint32List(), [-100]);211 assertElementsEquals(copy.getRepeatedSint64List(), [-0x8000000000000000]);212 assertElementsEquals(copy.getRepeatedFixed32List(), [1234]);213 assertElementsEquals(copy.getRepeatedFixed64List(), [0x1234567800000000]);214 assertElementsEquals(copy.getRepeatedSfixed32List(), [-1234]);215 assertElementsEquals(copy.getRepeatedSfixed64List(), [-0x1234567800000000]);216 assertElementsEquals(copy.getRepeatedFloatList(), [1.5]);217 assertElementsEquals(copy.getRepeatedDoubleList(), [-1.5]);218 assertElementsEquals(copy.getRepeatedBoolList(), [true]);219 assertElementsEquals(copy.getRepeatedStringList(), ['hello world']);220 assertEquals(copy.getRepeatedBytesList().length, 2);221 assertEquals(true, bytesCompare(copy.getRepeatedBytesList_asU8()[0], BYTES));222 assertEquals(true, bytesCompare(copy.getRepeatedBytesList()[0], BYTES));223 assertEquals(true, bytesCompare(copy.getRepeatedBytesList_asU8()[1], BYTES));224 assertEquals(copy.getRepeatedBytesList_asB64()[0], BYTES_B64);225 assertEquals(copy.getRepeatedBytesList_asB64()[1], BYTES_B64);226 assertEquals(copy.getRepeatedGroupList().length, 1);227 assertEquals(copy.getRepeatedGroupList()[0].getA(), 100);228 assertEquals(copy.getRepeatedForeignMessageList().length, 1);229 assertEquals(copy.getRepeatedForeignMessageList()[0].getC(), 1000);230 assertElementsEquals(copy.getRepeatedForeignEnumList(),231 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]);232 assertElementsEquals(copy.getPackedRepeatedInt32List(), [-42]);233 assertElementsEquals(copy.getPackedRepeatedInt64List(),234 [-0x7fffffff00000000]);235 assertElementsEquals(copy.getPackedRepeatedUint32List(), [0x80000000]);236 assertElementsEquals(copy.getPackedRepeatedUint64List(),237 [0xf000000000000000]);238 assertElementsEquals(copy.getPackedRepeatedSint32List(), [-100]);239 assertElementsEquals(copy.getPackedRepeatedSint64List(),240 [-0x8000000000000000]);241 assertElementsEquals(copy.getPackedRepeatedFixed32List(), [1234]);242 assertElementsEquals(copy.getPackedRepeatedFixed64List(),243 [0x1234567800000000]);244 assertElementsEquals(copy.getPackedRepeatedSfixed32List(), [-1234]);245 assertElementsEquals(copy.getPackedRepeatedSfixed64List(),246 [-0x1234567800000000]);247 assertElementsEquals(copy.getPackedRepeatedFloatList(), [1.5]);248 assertElementsEquals(copy.getPackedRepeatedDoubleList(), [-1.5]);249}250/**251 * Helper: verify that all expected extensions are present.252 * @param {!proto.jspb.test.TestExtendable} msg253 */254function checkExtensions(msg) {255 assertEquals(-42,256 msg.getExtension(proto.jspb.test.extendOptionalInt32));257 assertEquals(-0x7fffffff00000000,258 msg.getExtension(proto.jspb.test.extendOptionalInt64));259 assertEquals(0x80000000,260 msg.getExtension(proto.jspb.test.extendOptionalUint32));261 assertEquals(0xf000000000000000,262 msg.getExtension(proto.jspb.test.extendOptionalUint64));263 assertEquals(-100,264 msg.getExtension(proto.jspb.test.extendOptionalSint32));265 assertEquals(-0x8000000000000000,266 msg.getExtension(proto.jspb.test.extendOptionalSint64));267 assertEquals(1234,268 msg.getExtension(proto.jspb.test.extendOptionalFixed32));269 assertEquals(0x1234567800000000,270 msg.getExtension(proto.jspb.test.extendOptionalFixed64));271 assertEquals(-1234,272 msg.getExtension(proto.jspb.test.extendOptionalSfixed32));273 assertEquals(-0x1234567800000000,274 msg.getExtension(proto.jspb.test.extendOptionalSfixed64));275 assertEquals(1.5,276 msg.getExtension(proto.jspb.test.extendOptionalFloat));277 assertEquals(-1.5,278 msg.getExtension(proto.jspb.test.extendOptionalDouble));279 assertEquals(true,280 msg.getExtension(proto.jspb.test.extendOptionalBool));281 assertEquals('hello world',282 msg.getExtension(proto.jspb.test.extendOptionalString));283 assertEquals(284 true, bytesCompare(285 msg.getExtension(proto.jspb.test.extendOptionalBytes), BYTES));286 assertEquals(16,287 msg.getExtension(288 proto.jspb.test.ExtendsWithMessage.optionalExtension).getFoo());289 assertElementsEquals(290 msg.getExtension(proto.jspb.test.extendRepeatedInt32List),291 [-42]);292 assertElementsEquals(293 msg.getExtension(proto.jspb.test.extendRepeatedInt64List),294 [-0x7fffffff00000000]);295 assertElementsEquals(296 msg.getExtension(proto.jspb.test.extendRepeatedUint32List),297 [0x80000000]);298 assertElementsEquals(299 msg.getExtension(proto.jspb.test.extendRepeatedUint64List),300 [0xf000000000000000]);301 assertElementsEquals(302 msg.getExtension(proto.jspb.test.extendRepeatedSint32List),303 [-100]);304 assertElementsEquals(305 msg.getExtension(proto.jspb.test.extendRepeatedSint64List),306 [-0x8000000000000000]);307 assertElementsEquals(308 msg.getExtension(proto.jspb.test.extendRepeatedFixed32List),309 [1234]);310 assertElementsEquals(311 msg.getExtension(proto.jspb.test.extendRepeatedFixed64List),312 [0x1234567800000000]);313 assertElementsEquals(314 msg.getExtension(proto.jspb.test.extendRepeatedSfixed32List),315 [-1234]);316 assertElementsEquals(317 msg.getExtension(proto.jspb.test.extendRepeatedSfixed64List),318 [-0x1234567800000000]);319 assertElementsEquals(320 msg.getExtension(proto.jspb.test.extendRepeatedFloatList),321 [1.5]);322 assertElementsEquals(323 msg.getExtension(proto.jspb.test.extendRepeatedDoubleList),324 [-1.5]);325 assertElementsEquals(326 msg.getExtension(proto.jspb.test.extendRepeatedBoolList),327 [true]);328 assertElementsEquals(329 msg.getExtension(proto.jspb.test.extendRepeatedStringList),330 ['hello world']);331 assertEquals(332 true,333 bytesCompare(334 msg.getExtension(proto.jspb.test.extendRepeatedBytesList)[0], BYTES));335 assertEquals(1000,336 msg.getExtension(337 proto.jspb.test.ExtendsWithMessage.repeatedExtensionList)[0]338 .getFoo());339 assertElementsEquals(340 msg.getExtension(proto.jspb.test.extendRepeatedForeignEnumList),341 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]);342 assertElementsEquals(343 msg.getExtension(proto.jspb.test.extendPackedRepeatedInt32List),344 [-42]);345 assertElementsEquals(346 msg.getExtension(proto.jspb.test.extendPackedRepeatedInt64List),347 [-0x7fffffff00000000]);348 assertElementsEquals(349 msg.getExtension(proto.jspb.test.extendPackedRepeatedUint32List),350 [0x80000000]);351 assertElementsEquals(352 msg.getExtension(proto.jspb.test.extendPackedRepeatedUint64List),353 [0xf000000000000000]);354 assertElementsEquals(355 msg.getExtension(proto.jspb.test.extendPackedRepeatedSint32List),356 [-100]);357 assertElementsEquals(358 msg.getExtension(proto.jspb.test.extendPackedRepeatedSint64List),359 [-0x8000000000000000]);360 assertElementsEquals(361 msg.getExtension(proto.jspb.test.extendPackedRepeatedFixed32List),362 [1234]);363 assertElementsEquals(364 msg.getExtension(proto.jspb.test.extendPackedRepeatedFixed64List),365 [0x1234567800000000]);366 assertElementsEquals(367 msg.getExtension(proto.jspb.test.extendPackedRepeatedSfixed32List),368 [-1234]);369 assertElementsEquals(370 msg.getExtension(proto.jspb.test.extendPackedRepeatedSfixed64List),371 [-0x1234567800000000]);372 assertElementsEquals(373 msg.getExtension(proto.jspb.test.extendPackedRepeatedFloatList),374 [1.5]);375 assertElementsEquals(376 msg.getExtension(proto.jspb.test.extendPackedRepeatedDoubleList),377 [-1.5]);378 assertElementsEquals(379 msg.getExtension(proto.jspb.test.extendPackedRepeatedBoolList),380 [true]);381 assertElementsEquals(382 msg.getExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList),383 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]);384}385describe('protoBinaryTest', function() {386 /**387 * Tests a basic serialization-deserializaton round-trip with all supported388 * field types (on the TestAllTypes message type).389 */390 it('testRoundTrip', function() {391 var msg = new proto.jspb.test.TestAllTypes();392 fillAllFields(msg);393 var encoded = msg.serializeBinary();394 var decoded = proto.jspb.test.TestAllTypes.deserializeBinary(encoded);395 checkAllFields(msg, decoded);396 });397 /**398 * Test that base64 string and Uint8Array are interchangeable in bytes fields.399 */400 it('testBytesFieldsGettersInterop', function() {401 var msg = new proto.jspb.test.TestAllTypes();402 // Set from a base64 string and check all the getters work.403 msg.setOptionalBytes(BYTES_B64);404 assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES));405 assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES));406 assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));407 // Test binary serialize round trip doesn't break it.408 msg = proto.jspb.test.TestAllTypes.deserializeBinary(msg.serializeBinary());409 assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES));410 assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES));411 assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));412 msg = new proto.jspb.test.TestAllTypes();413 // Set from a Uint8Array and check all the getters work.414 msg.setOptionalBytes(BYTES);415 assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES));416 assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES));417 assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));418 });419 /**420 * Test that bytes setters will receive result of any of the getters.421 */422 it('testBytesFieldsSettersInterop', function() {423 var msg = new proto.jspb.test.TestAllTypes();424 msg.setOptionalBytes(BYTES);425 assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));426 msg.setOptionalBytes(msg.getOptionalBytes());427 assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));428 msg.setOptionalBytes(msg.getOptionalBytes_asB64());429 assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));430 msg.setOptionalBytes(msg.getOptionalBytes_asU8());431 assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));432 });433 /**434 * Test that bytes setters will receive result of any of the getters.435 */436 it('testRepeatedBytesGetters', function() {437 var msg = new proto.jspb.test.TestAllTypes();438 function assertGetters() {439 assertTrue(goog.isString(msg.getRepeatedBytesList_asB64()[0]));440 assertTrue(goog.isString(msg.getRepeatedBytesList_asB64()[1]));441 assertTrue(msg.getRepeatedBytesList_asU8()[0] instanceof Uint8Array);442 assertTrue(msg.getRepeatedBytesList_asU8()[1] instanceof Uint8Array);443 assertTrue(bytesCompare(msg.getRepeatedBytesList()[0], BYTES));444 assertTrue(bytesCompare(msg.getRepeatedBytesList()[1], BYTES));445 assertTrue(bytesCompare(msg.getRepeatedBytesList_asB64()[0], BYTES));446 assertTrue(bytesCompare(msg.getRepeatedBytesList_asB64()[1], BYTES));447 assertTrue(bytesCompare(msg.getRepeatedBytesList_asU8()[0], BYTES));448 assertTrue(bytesCompare(msg.getRepeatedBytesList_asU8()[1], BYTES));449 }450 msg.setRepeatedBytesList([BYTES, BYTES]);451 assertGetters();452 msg.setRepeatedBytesList([BYTES_B64, BYTES_B64]);453 assertGetters();454 msg.setRepeatedBytesList([]);455 assertEquals(0, msg.getRepeatedBytesList().length);456 assertEquals(0, msg.getRepeatedBytesList_asB64().length);457 assertEquals(0, msg.getRepeatedBytesList_asU8().length);458 });459 /**460 * Helper: fill all extension values.461 * @param {proto.jspb.test.TestExtendable} msg462 */463 function fillExtensions(msg) {464 msg.setExtension(465 proto.jspb.test.extendOptionalInt32, -42);466 msg.setExtension(467 proto.jspb.test.extendOptionalInt64, -0x7fffffff00000000);468 msg.setExtension(469 proto.jspb.test.extendOptionalUint32, 0x80000000);470 msg.setExtension(471 proto.jspb.test.extendOptionalUint64, 0xf000000000000000);472 msg.setExtension(473 proto.jspb.test.extendOptionalSint32, -100);474 msg.setExtension(475 proto.jspb.test.extendOptionalSint64, -0x8000000000000000);476 msg.setExtension(477 proto.jspb.test.extendOptionalFixed32, 1234);478 msg.setExtension(479 proto.jspb.test.extendOptionalFixed64, 0x1234567800000000);480 msg.setExtension(481 proto.jspb.test.extendOptionalSfixed32, -1234);482 msg.setExtension(483 proto.jspb.test.extendOptionalSfixed64, -0x1234567800000000);484 msg.setExtension(485 proto.jspb.test.extendOptionalFloat, 1.5);486 msg.setExtension(487 proto.jspb.test.extendOptionalDouble, -1.5);488 msg.setExtension(489 proto.jspb.test.extendOptionalBool, true);490 msg.setExtension(491 proto.jspb.test.extendOptionalString, 'hello world');492 msg.setExtension(proto.jspb.test.extendOptionalBytes, BYTES);493 var submsg = new proto.jspb.test.ExtendsWithMessage();494 submsg.setFoo(16);495 msg.setExtension(496 proto.jspb.test.ExtendsWithMessage.optionalExtension, submsg);497 msg.setExtension(498 proto.jspb.test.extendOptionalForeignEnum,499 proto.jspb.test.ForeignEnum.FOREIGN_FOO);500 msg.setExtension(501 proto.jspb.test.extendRepeatedInt32List, [-42]);502 msg.setExtension(503 proto.jspb.test.extendRepeatedInt64List, [-0x7fffffff00000000]);504 msg.setExtension(505 proto.jspb.test.extendRepeatedUint32List, [0x80000000]);506 msg.setExtension(507 proto.jspb.test.extendRepeatedUint64List, [0xf000000000000000]);508 msg.setExtension(509 proto.jspb.test.extendRepeatedSint32List, [-100]);510 msg.setExtension(511 proto.jspb.test.extendRepeatedSint64List, [-0x8000000000000000]);512 msg.setExtension(513 proto.jspb.test.extendRepeatedFixed32List, [1234]);514 msg.setExtension(515 proto.jspb.test.extendRepeatedFixed64List, [0x1234567800000000]);516 msg.setExtension(517 proto.jspb.test.extendRepeatedSfixed32List, [-1234]);518 msg.setExtension(519 proto.jspb.test.extendRepeatedSfixed64List, [-0x1234567800000000]);520 msg.setExtension(521 proto.jspb.test.extendRepeatedFloatList, [1.5]);522 msg.setExtension(523 proto.jspb.test.extendRepeatedDoubleList, [-1.5]);524 msg.setExtension(525 proto.jspb.test.extendRepeatedBoolList, [true]);526 msg.setExtension(527 proto.jspb.test.extendRepeatedStringList, ['hello world']);528 msg.setExtension(proto.jspb.test.extendRepeatedBytesList, [BYTES]);529 submsg = new proto.jspb.test.ExtendsWithMessage();530 submsg.setFoo(1000);531 msg.setExtension(532 proto.jspb.test.ExtendsWithMessage.repeatedExtensionList, [submsg]);533 msg.setExtension(proto.jspb.test.extendRepeatedForeignEnumList,534 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]);535 msg.setExtension(536 proto.jspb.test.extendPackedRepeatedInt32List, [-42]);537 msg.setExtension(538 proto.jspb.test.extendPackedRepeatedInt64List, [-0x7fffffff00000000]);539 msg.setExtension(540 proto.jspb.test.extendPackedRepeatedUint32List, [0x80000000]);541 msg.setExtension(542 proto.jspb.test.extendPackedRepeatedUint64List, [0xf000000000000000]);543 msg.setExtension(544 proto.jspb.test.extendPackedRepeatedSint32List, [-100]);545 msg.setExtension(546 proto.jspb.test.extendPackedRepeatedSint64List, [-0x8000000000000000]);547 msg.setExtension(548 proto.jspb.test.extendPackedRepeatedFixed32List, [1234]);549 msg.setExtension(550 proto.jspb.test.extendPackedRepeatedFixed64List, [0x1234567800000000]);551 msg.setExtension(552 proto.jspb.test.extendPackedRepeatedSfixed32List, [-1234]);553 msg.setExtension(554 proto.jspb.test.extendPackedRepeatedSfixed64List,555 [-0x1234567800000000]);556 msg.setExtension(557 proto.jspb.test.extendPackedRepeatedFloatList, [1.5]);558 msg.setExtension(559 proto.jspb.test.extendPackedRepeatedDoubleList, [-1.5]);560 msg.setExtension(561 proto.jspb.test.extendPackedRepeatedBoolList, [true]);562 msg.setExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList,563 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]);564 }565 /**566 * Tests extension serialization and deserialization.567 */568 it('testExtensions', function() {569 var msg = new proto.jspb.test.TestExtendable();570 fillExtensions(msg);571 var encoded = msg.serializeBinary();572 var decoded = proto.jspb.test.TestExtendable.deserializeBinary(encoded);573 checkExtensions(decoded);574 });...

Full Screen

Full Screen

extend-visitor.js

Source:extend-visitor.js Github

copy

Full Screen

...21 if (rulesetNode.root) {22 return;23 }24 var i, j, extend, allSelectorsExtendList = [], extendList;25 // get &:extend(.a); rules which apply to all selectors in this ruleset26 var rules = rulesetNode.rules, ruleCnt = rules ? rules.length : 0;27 for(i = 0; i < ruleCnt; i++) {28 if (rulesetNode.rules[i] instanceof tree.Extend) {29 allSelectorsExtendList.push(rules[i]);30 rulesetNode.extendOnEveryPath = true;31 }32 }33 // now find every selector and apply the extends that apply to all extends34 // and the ones which apply to an individual extend35 var paths = rulesetNode.paths;36 for(i = 0; i < paths.length; i++) {37 var selectorPath = paths[i],38 selector = selectorPath[selectorPath.length - 1],39 selExtendList = selector.extendList;40 extendList = selExtendList ? selExtendList.slice(0).concat(allSelectorsExtendList)41 : allSelectorsExtendList;42 if (extendList) {43 extendList = extendList.map(function(allSelectorsExtend) {44 return allSelectorsExtend.clone();45 });46 }47 for(j = 0; j < extendList.length; j++) {48 this.foundExtends = true;49 extend = extendList[j];50 extend.findSelfSelectors(selectorPath);51 extend.ruleset = rulesetNode;52 if (j === 0) { extend.firstExtendOnThisSelectorPath = true; }53 this.allExtendsStack[this.allExtendsStack.length-1].push(extend);54 }55 }56 this.contexts.push(rulesetNode.selectors);57 },58 visitRulesetOut: function (rulesetNode) {59 if (!rulesetNode.root) {60 this.contexts.length = this.contexts.length - 1;61 }62 },63 visitMedia: function (mediaNode, visitArgs) {64 mediaNode.allExtends = [];65 this.allExtendsStack.push(mediaNode.allExtends);66 },67 visitMediaOut: function (mediaNode) {68 this.allExtendsStack.length = this.allExtendsStack.length - 1;69 },70 visitDirective: function (directiveNode, visitArgs) {71 directiveNode.allExtends = [];72 this.allExtendsStack.push(directiveNode.allExtends);73 },74 visitDirectiveOut: function (directiveNode) {75 this.allExtendsStack.length = this.allExtendsStack.length - 1;76 }77 };78 tree.processExtendsVisitor = function() {79 this._visitor = new tree.visitor(this);80 };81 tree.processExtendsVisitor.prototype = {82 run: function(root) {83 var extendFinder = new tree.extendFinderVisitor();84 extendFinder.run(root);85 if (!extendFinder.foundExtends) { return root; }86 root.allExtends = root.allExtends.concat(this.doExtendChaining(root.allExtends, root.allExtends));87 this.allExtendsStack = [root.allExtends];88 return this._visitor.visit(root);89 },90 doExtendChaining: function (extendsList, extendsListTarget, iterationCount) {91 //92 // chaining is different from normal extension.. if we extend an extend then we are not just copying, altering and pasting93 // the selector we would do normally, but we are also adding an extend with the same target selector94 // this means this new extend can then go and alter other extends95 //96 // this method deals with all the chaining work - without it, extend is flat and doesn't work on other extend selectors97 // this is also the most expensive.. and a match on one selector can cause an extension of a selector we had already processed if98 // we look at each selector at a time, as is done in visitRuleset99 var extendIndex, targetExtendIndex, matches, extendsToAdd = [], newSelector, extendVisitor = this, selectorPath, extend, targetExtend, newExtend;100 iterationCount = iterationCount || 0;101 //loop through comparing every extend with every target extend.102 // a target extend is the one on the ruleset we are looking at copy/edit/pasting in place103 // e.g. .a:extend(.b) {} and .b:extend(.c) {} then the first extend extends the second one104 // and the second is the target.105 // the seperation into two lists allows us to process a subset of chains with a bigger set, as is the106 // case when processing media queries107 for(extendIndex = 0; extendIndex < extendsList.length; extendIndex++){108 for(targetExtendIndex = 0; targetExtendIndex < extendsListTarget.length; targetExtendIndex++){109 extend = extendsList[extendIndex];110 targetExtend = extendsListTarget[targetExtendIndex];111 // look for circular references112 if( extend.parent_ids.indexOf( targetExtend.object_id ) >= 0 ){ continue; }113 // find a match in the target extends self selector (the bit before :extend)114 selectorPath = [targetExtend.selfSelectors[0]];115 matches = extendVisitor.findMatch(extend, selectorPath);116 if (matches.length) {117 // we found a match, so for each self selector..118 extend.selfSelectors.forEach(function(selfSelector) {119 // process the extend as usual120 newSelector = extendVisitor.extendSelector(matches, selectorPath, selfSelector);121 // but now we create a new extend from it122 newExtend = new(tree.Extend)(targetExtend.selector, targetExtend.option, 0);123 newExtend.selfSelectors = newSelector;124 // add the extend onto the list of extends for that selector125 newSelector[newSelector.length-1].extendList = [newExtend];126 // record that we need to add it.127 extendsToAdd.push(newExtend);128 newExtend.ruleset = targetExtend.ruleset;129 //remember its parents for circular references130 newExtend.parent_ids = newExtend.parent_ids.concat(targetExtend.parent_ids, extend.parent_ids);131 // only process the selector once.. if we have :extend(.a,.b) then multiple132 // extends will look at the same selector path, so when extending133 // we know that any others will be duplicates in terms of what is added to the css134 if (targetExtend.firstExtendOnThisSelectorPath) {135 newExtend.firstExtendOnThisSelectorPath = true;136 targetExtend.ruleset.paths.push(newSelector);137 }138 });139 }140 }141 }142 if (extendsToAdd.length) {143 // try to detect circular references to stop a stack overflow.144 // may no longer be needed.145 this.extendChainCount++;146 if (iterationCount > 100) {147 var selectorOne = "{unable to calculate}";148 var selectorTwo = "{unable to calculate}";149 try150 {151 selectorOne = extendsToAdd[0].selfSelectors[0].toCSS();152 selectorTwo = extendsToAdd[0].selector.toCSS();153 }154 catch(e) {}155 throw {message: "extend circular reference detected. One of the circular extends is currently:"+selectorOne+":extend(" + selectorTwo+")"};156 }157 // now process the new extends on the existing rules so that we can handle a extending b extending c ectending d extending e...158 return extendsToAdd.concat(extendVisitor.doExtendChaining(extendsToAdd, extendsListTarget, iterationCount+1));159 } else {160 return extendsToAdd;161 }162 },163 visitRule: function (ruleNode, visitArgs) {164 visitArgs.visitDeeper = false;165 },166 visitMixinDefinition: function (mixinDefinitionNode, visitArgs) {167 visitArgs.visitDeeper = false;168 },169 visitSelector: function (selectorNode, visitArgs) {...

Full Screen

Full Screen

Component.js

Source:Component.js Github

copy

Full Screen

2 var utHelper = window.utHelper;3 var testCase = utHelper.prepare(['echarts/model/Component']);4 describe('topologicalTravel', function () {5 testCase('topologicalTravel_base', function (ComponentModel) {6 ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});7 ComponentModel.extend({type: 'a1'});8 ComponentModel.extend({type: 'a2'});9 var result = [];10 var allList = ComponentModel.getAllClassMainTypes();11 ComponentModel.topologicalTravel(['m1', 'a1', 'a2'], allList, function (componentType, dependencies) {12 result.push([componentType, dependencies]);13 });14 expect(result).toEqual([['a2', []], ['a1', []], ['m1', ['a1', 'a2']]]);15 });16 testCase('topologicalTravel_a1IsAbsent', function (ComponentModel) {17 ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});18 ComponentModel.extend({type: 'a2'});19 var allList = ComponentModel.getAllClassMainTypes();20 var result = [];21 ComponentModel.topologicalTravel(['m1', 'a2'], allList, function (componentType, dependencies) {22 result.push([componentType, dependencies]);23 });24 expect(result).toEqual([['a2', []], ['m1', ['a1', 'a2']]]);25 });26 testCase('topologicalTravel_empty', function (ComponentModel) {27 ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});28 ComponentModel.extend({type: 'a1'});29 ComponentModel.extend({type: 'a2'});30 var allList = ComponentModel.getAllClassMainTypes();31 var result = [];32 ComponentModel.topologicalTravel([], allList, function (componentType, dependencies) {33 result.push([componentType, dependencies]);34 });35 expect(result).toEqual([]);36 });37 testCase('topologicalTravel_isolate', function (ComponentModel) {38 ComponentModel.extend({type: 'a2'});39 ComponentModel.extend({type: 'a1'});40 ComponentModel.extend({type: 'm1', dependencies: ['a2']});41 var allList = ComponentModel.getAllClassMainTypes();42 var result = [];43 ComponentModel.topologicalTravel(['a1', 'a2', 'm1'], allList, function (componentType, dependencies) {44 result.push([componentType, dependencies]);45 });46 expect(result).toEqual([['a1', []], ['a2', []], ['m1', ['a2']]]);47 });48 testCase('topologicalTravel_diamond', function (ComponentModel) {49 ComponentModel.extend({type: 'a1', dependencies: []});50 ComponentModel.extend({type: 'a2', dependencies: ['a1']});51 ComponentModel.extend({type: 'a3', dependencies: ['a1']});52 ComponentModel.extend({type: 'm1', dependencies: ['a2', 'a3']});53 var allList = ComponentModel.getAllClassMainTypes();54 var result = [];55 ComponentModel.topologicalTravel(['m1', 'a1', 'a2', 'a3'], allList, function (componentType, dependencies) {56 result.push([componentType, dependencies]);57 });58 expect(result).toEqual([['a1', []], ['a3', ['a1']], ['a2', ['a1']], ['m1', ['a2', 'a3']]]);59 });60 testCase('topologicalTravel_loop', function (ComponentModel) {61 ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});62 ComponentModel.extend({type: 'm2', dependencies: ['m1', 'a2']});63 ComponentModel.extend({type: 'a1', dependencies: ['m2', 'a2', 'a3']});64 ComponentModel.extend({type: 'a2'});65 ComponentModel.extend({type: 'a3'});66 var allList = ComponentModel.getAllClassMainTypes();67 expect(function () {68 ComponentModel.topologicalTravel(['m1', 'm2', 'a1'], allList);69 }).toThrowError(/Circl/);70 });71 testCase('topologicalTravel_multipleEchartsInstance', function (ComponentModel) {72 ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});73 ComponentModel.extend({type: 'a1'});74 ComponentModel.extend({type: 'a2'});75 var allList = ComponentModel.getAllClassMainTypes();76 var result = [];77 ComponentModel.topologicalTravel(['m1', 'a1', 'a2'], allList, function (componentType, dependencies) {78 result.push([componentType, dependencies]);79 });80 expect(result).toEqual([['a2', []], ['a1', []], ['m1', ['a1', 'a2']]]);81 result = [];82 ComponentModel.extend({type: 'm2', dependencies: ['a1', 'm1']});83 var allList = ComponentModel.getAllClassMainTypes();84 ComponentModel.topologicalTravel(['m2', 'm1', 'a1', 'a2'], allList, function (componentType, dependencies) {85 result.push([componentType, dependencies]);86 });87 expect(result).toEqual([['a2', []], ['a1', []], ['m1', ['a1', 'a2']], ['m2', ['a1', 'm1']]]);88 });89 testCase('topologicalTravel_missingSomeNodeButHasDependencies', function (ComponentModel) {90 ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});91 ComponentModel.extend({type: 'a2', dependencies: ['a3']});92 ComponentModel.extend({type: 'a3'});93 ComponentModel.extend({type: 'a4'});94 var result = [];95 var allList = ComponentModel.getAllClassMainTypes();96 ComponentModel.topologicalTravel(['a3', 'm1'], allList, function (componentType, dependencies) {97 result.push([componentType, dependencies]);98 });99 expect(result).toEqual([['a3', []], ['a2', ['a3']], ['m1', ['a1', 'a2']]]);100 var result = [];101 var allList = ComponentModel.getAllClassMainTypes();102 ComponentModel.topologicalTravel(['m1', 'a3'], allList, function (componentType, dependencies) {103 result.push([componentType, dependencies]);104 });105 expect(result).toEqual([['a3', []], ['a2', ['a3']], ['m1', ['a1', 'a2']]]);106 });107 testCase('topologicalTravel_subType', function (ComponentModel) {108 ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});109 ComponentModel.extend({type: 'a1.aaa', dependencies: ['a2']});110 ComponentModel.extend({type: 'a1.bbb', dependencies: ['a3', 'a4']});111 ComponentModel.extend({type: 'a2'});112 ComponentModel.extend({type: 'a3'});113 ComponentModel.extend({type: 'a4'});114 var result = [];115 var allList = ComponentModel.getAllClassMainTypes();116 ComponentModel.topologicalTravel(['m1', 'a1', 'a2', 'a4'], allList, function (componentType, dependencies) {117 result.push([componentType, dependencies]);118 });119 expect(result).toEqual([['a4', []], ['a2',[]], ['a1', ['a2','a3','a4']], ['m1', ['a1', 'a2']]]);120 });121 });...

Full Screen

Full Screen

extend_certificate.js

Source:extend_certificate.js Github

copy

Full Screen

1/**2 * 3 * This file provides all methods for extend_certificate.jsp.4 * 5 * @author Jonathan Schlotz6 *7 */89// ====================================================================================//10// ================================= INITIALIZATION ===================================//11// ====================================================================================//1213$(document).ready(function() {1415 // Method that triggers the 'Aktivieren' button when the 'enter'-key is pressed16 $('#password, #password_confirm').keypress(function(e) {17 if (e.keyCode == 13)18 $('#step2_button_extend').click();19 });20 21});2223// ====================================================================================//24// ================================== AJAX FUNCTIONS ==================================//25// ====================================================================================//2627/**28 * Sends an ajax request to the backend to request a certificate.29 * 30 */31function requestCertificate() {32 setLoading(1)33 $.ajax({34 url : '../RequestCertificateServlet',35 type : 'POST',36 dataType : 'json',37 timeout : 8000,38 success : function(data) {39 if (data.validSession && data.createdRequest) {40 successful(1, "SCS_CERT_REQUEST")41 } else if (data.validSession && data.createdRequest === false) {42 unsuccessful(1, "ERR_CERT_REQUEST")43 } else {44 window.setTimeout(function() {45 location.href = 'login.jsp';46 }, 1000);47 }48 },49 error : function() {50 unsuccessful(1, "ERR_CONNECTION")51 }52 })53}5455/**56 * Sends an ajax request to the backend to activate a certificate57 * 58 */59function activateCertificate() {60 $61 .ajax({62 url : '../ActivateCertificateServlet',63 type : 'POST',64 dataType : 'json',65 data : $('#password').serialize(),66 timeout : 8000,67 success : function(data) {68 if (data.validSession && data.activatedCertificate) {69 successful(2, "SCS_CERT_ACTIIVATION")70 } else if (data.validSession71 && data.activatedCertificate === false) {72 unsuccessful(2, "ERR_CERT_ACTIVATION")73 } else {74 window.setTimeout(function() {75 location.href = 'login.jsp';76 }, 1000);77 }78 },79 error : function() {80 unsuccessful(2, "ERR_CONNECTION")81 }82 })83}8485// ====================================================================================//86// ================================== MAIN FUNCTIONS ==================================//87// ====================================================================================//8889/**90 * Logs out the user.91 * 92 */93function logout() {94 document.form_logout.submit()95}9697/**98 * Checks the length of the password.99 * 100 */101function validatePassword() {102 var regEx = /.{6}/;103104 if ($("#password").val() !== "" && !regEx.test($("#password").val())) {105 buildAndShowMessageBar("WRN_INPUT_PASSWORD", "messagebar_extend")106 $("#page_content_extend").addClass("page_content_move_down")107 } else {108 hideMessageBar()109 }110}111112/**113 * Compare both password field values witch each other.114 * 115 */116function comparePasswords() {117 // Both fields have to be filled out118 if ($("#password").val() !== "" && $("#password_confirm").val() !== "") {119120 // Repeated new password and password have to be the same121 if ($("#password").val() === $("#password_confirm").val()) {122 return true;123124 } else { // If repeated new password and password are not the125 // same126 buildAndShowMessageBar("ERR_INPUT_PASSWORD_COMP",127 "messagebar_extend")128 $("#page_content_extend").addClass("page_content_move_down")129 }130131 } else { // If one field is empty132 buildAndShowMessageBar("WRN_EMPTY_CERT_PWD", "messagebar_extend")133 $("#page_content_extend").addClass("page_content_move_down")134 }135 return false;136}137138/**139 * Executed by a click on the 'Aktivieren' button.140 * 141 */142function onActivateClick() {143 if (comparePasswords()) {144 setLoading(2)145 activateCertificate()146 }147}148149/**150 * Sets the ui area to a loading state.151 * 152 * @param stepNumber The step which is currently shown as active.153 * 154 */155function setLoading(stepNumber) {156 $("#step" + stepNumber + "_panel_body_extend").addClass(157 "panel_next_step_or_loading")158 $("#loading_gif_extend").fadeIn()159 $("#step" + stepNumber + "_button_extend").attr("disabled", "");160 $("#step" + stepNumber + "_button_extend").removeAttr("onclick")161}162163/**164 * Manipulates the ui after successful ajax request.165 * 166 * @param stepNumber The step which is currently shown as active.167 * @param message The message to be displayed in the message bar.168 * 169 */170function successful(stepNumber, message) {171 var stepNumberNextStep = stepNumber + 1172 $("#loading_gif_extend").fadeOut()173 buildAndShowMessageBar(message, "messagebar_extend")174 $("#page_content_extend").addClass("page_content_move_down")175 if (stepNumber > 1) {176 window.setTimeout(function() {177 hideMessageBar()178 $("#step" + stepNumber + "_content_extend").slideUp()179 $("#step" + stepNumber + "_icon_extend").addClass(180 "messageicon_border_success")181 $("#step" + stepNumber + "_iconfont_extend").addClass(182 "messageicon_success")183 $("#step" + stepNumber + "_header_extend").addClass(184 "panelheader_completed")185 $("#step" + stepNumberNextStep + "_content_extend").slideDown()186 $("#step" + stepNumberNextStep + "_header_extend").addClass(187 "panelheader_set_current_step")188 }, 1500);189 } else {190 window.setTimeout(function() {191 $("#step" + stepNumber + "_content_extend").slideUp()192 $("#step" + stepNumber + "_icon_extend").addClass(193 "messageicon_border_success")194 $("#step" + stepNumber + "_iconfont_extend").addClass(195 "messageicon_success")196 $("#step" + stepNumber + "_header_extend").addClass(197 "panelheader_completed")198 buildAndShowMessageBar("WRN_CERT_REQUEST_WAITING",199 "messagebar_extend")200 }, 1500);201 }202}203204/**205 * Manipulates the ui after unsuccessful ajax request.206 * 207 * @param stepNumber The step which is currently shown as active.208 * @param message The message which will be displayed in the message bar.209 * 210 */211function unsuccessful(stepNumber, message) {212 $("#step" + stepNumber + "_panel_body_extend").removeClass("panel_next_step_or_loading")213 $("#loading_gif_extend").fadeOut()214 $("#step" + stepNumber + "_button_extend").removeAttr("disabled")215 216 if (stepNumber === 1) {217 $("#step" + stepNumber + "_button_extend").attr("onclick","requestCertificate()")218 } else if (stepNumber === 2) {219 $("#step" + stepNumber + "_button_extend").attr("onclick","onActivateClick()")220 }221 222 buildAndShowMessageBar(message, "messagebar_extend")223 $("#page_content_extend").addClass("page_content_move_down")224225 window.setTimeout(function() {226 hideMessageBar()227 }, 1500);228}229230/**231 * Hides the message bar.232 * 233 */234function hideMessageBar() {235 $("#messagebar_extend").addClass("messagebar_hidden")236 $("#page_content_extend").removeClass("page_content_move_down") ...

Full Screen

Full Screen

base.js

Source:base.js Github

copy

Full Screen

...104 return this;105 }106};107// initialise108Base = Base.extend({109 constructor: function() {110 this.extend(arguments[0]);111 }112}, {113 ancestor: Object,114 version: "1.1",115 116 forEach: function(object, block, context) {117 for (var key in object) {118 if (this.prototype[key] === undefined) {119 block.call(context, object[key], key, object);120 }121 }122 },123 124 implement: function() {125 for (var i = 0; i < arguments.length; i++) {126 if (typeof arguments[i] == "function") {127 // if it's a function, call it128 arguments[i](this.prototype);129 } else {130 // add the interface using the extend method131 this.prototype.extend(arguments[i]);132 }133 }134 return this;135 },136 137 toString: function() {138 return String(this.valueOf());139 }...

Full Screen

Full Screen

extend.spec.js

Source:extend.spec.js Github

copy

Full Screen

1import Vue from 'vue'23describe('Global API: extend', () => {4 it('should correctly merge options', () => {5 const Test = Vue.extend({6 name: 'test',7 a: 1,8 b: 29 })10 expect(Test.options.a).toBe(1)11 expect(Test.options.b).toBe(2)12 expect(Test.super).toBe(Vue)13 const t = new Test({14 a: 215 })16 expect(t.$options.a).toBe(2)17 expect(t.$options.b).toBe(2)18 // inheritance19 const Test2 = Test.extend({20 a: 221 })22 expect(Test2.options.a).toBe(2)23 expect(Test2.options.b).toBe(2)24 const t2 = new Test2({25 a: 326 })27 expect(t2.$options.a).toBe(3)28 expect(t2.$options.b).toBe(2)29 })3031 it('should warn invalid names', () => {32 Vue.extend({ name: '123' })33 expect('Invalid component name: "123"').toHaveBeenWarned()34 Vue.extend({ name: '_fesf' })35 expect('Invalid component name: "_fesf"').toHaveBeenWarned()36 Vue.extend({ name: 'Some App' })37 expect('Invalid component name: "Some App"').toHaveBeenWarned()38 })3940 it('should work when used as components', () => {41 const foo = Vue.extend({42 template: '<span>foo</span>'43 })44 const bar = Vue.extend({45 template: '<span>bar</span>'46 })47 const vm = new Vue({48 template: '<div><foo></foo><bar></bar></div>',49 components: { foo, bar }50 }).$mount()51 expect(vm.$el.innerHTML).toBe('<span>foo</span><span>bar</span>')52 })5354 it('should merge lifecycle hooks', () => {55 const calls = []56 const A = Vue.extend({57 created () {58 calls.push(1)59 }60 })61 const B = A.extend({62 created () {63 calls.push(2)64 }65 })66 new B({67 created () {68 calls.push(3)69 }70 })71 expect(calls).toEqual([1, 2, 3])72 })7374 it('should not merge nested mixins created with Vue.extend', () => {75 const A = Vue.extend({76 created: () => {}77 })78 const B = Vue.extend({79 mixins: [A],80 created: () => {}81 })82 const C = Vue.extend({83 extends: B,84 created: () => {}85 })86 const D = Vue.extend({87 mixins: [C],88 created: () => {}89 })90 expect(D.options.created.length).toBe(4)91 })9293 it('should merge methods', () => {94 const A = Vue.extend({95 methods: {96 a () { return this.n }97 }98 })99 const B = A.extend({100 methods: {101 b () { return this.n + 1 }102 }103 })104 const b = new B({105 data: { n: 0 },106 methods: {107 c () { return this.n + 2 }108 }109 })110 expect(b.a()).toBe(0)111 expect(b.b()).toBe(1)112 expect(b.c()).toBe(2)113 })114115 it('should merge assets', () => {116 const A = Vue.extend({117 components: {118 aa: {119 template: '<div>A</div>'120 }121 }122 })123 const B = A.extend({124 components: {125 bb: {126 template: '<div>B</div>'127 }128 }129 })130 const b = new B({131 template: '<div><aa></aa><bb></bb></div>'132 }).$mount()133 expect(b.$el.innerHTML).toBe('<div>A</div><div>B</div>')134 })135136 it('caching', () => {137 const options = {138 template: '<div></div>'139 }140 const A = Vue.extend(options)141 const B = Vue.extend(options)142 expect(A).toBe(B)143 })144145 // #4767146 it('extended options should use different identify from parent', () => {147 const A = Vue.extend({ computed: {}})148 const B = A.extend()149 B.options.computed.b = () => 'foo'150 expect(B.options.computed).not.toBe(A.options.computed)151 expect(A.options.computed.b).toBeUndefined()152 }) ...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...14 * constructor onto `Child` constructors.15 *16 * ```js17 * var extend = require('static-extend');18 * Parent.extend = extend(Parent);19 *20 * // optionally pass a custom merge function as the second arg21 * Parent.extend = extend(Parent, function(Child) {22 * Child.prototype.mixin = function(key, val) {23 * Child.prototype[key] = val;24 * };25 * });26 *27 * // extend "child" constructors28 * Parent.extend(Child);29 *30 * // optionally define prototype methods as the second arg31 * Parent.extend(Child, {32 * foo: function() {},33 * bar: function() {}34 * });35 * ```36 * @param {Function} `Parent` Parent ctor37 * @param {Function} `extendFn` Optional extend function for handling any necessary custom merging. Useful when updating methods that require a specific prototype.38 * @param {Function} `Child` Child ctor39 * @param {Object} `proto` Optionally pass additional prototype properties to inherit.40 * @return {Object}41 * @api public42 */43function extend(Parent, extendFn) {44 if (typeof Parent !== 'function') {45 throw new TypeError('expected Parent to be a function.');46 }47 return function(Ctor, proto) {48 if (typeof Ctor !== 'function') {49 throw new TypeError('expected Ctor to be a function.');50 }51 util.inherits(Ctor, Parent);52 copy(Ctor, Parent);53 // proto can be null or a plain object54 if (typeof proto === 'object') {55 var obj = Object.create(proto);56 for (var k in obj) {57 Ctor.prototype[k] = obj[k];58 }59 }60 // keep a reference to the parent prototype61 define(Ctor.prototype, '_parent_', {62 configurable: true,63 set: function() {},64 get: function() {65 return Parent.prototype;66 }67 });68 if (typeof extendFn === 'function') {69 extendFn(Ctor, Parent);70 }71 Ctor.extend = extend(Ctor, extendFn);72 };73};74/**75 * Expose `extend`76 */...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var sinonTest = require('sinon-test');3sinon.test = sinonTest.configureTest(sinon);4describe('test', function() {5 it('test', sinon.test(function() {6 var callback = this.stub();7 callback(42);8 callback(42);9 assert(callback.calledTwice);10 }));11});12var sinon = require('sinon');13var sinonTest = require('sinon-test');14sinon.test = sinonTest.configureTest(sinon);15describe('test', function() {16 it('test', sinon.test(function() {17 var callback = this.stub();18 callback(42);19 callback(42);20 assert(callback.calledTwice);21 }));22});

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var extend = require('extend');3var obj = {4};5var obj2 = {6};7var obj3 = {8};9var obj4 = {10};11var obj5 = {12};13var obj6 = {14};15var obj7 = {16};17var obj8 = {18};19var obj9 = {20};21var obj10 = {22};23var obj11 = {24};25var obj12 = {26};27var obj13 = {28};29var obj14 = {30};31var obj15 = {32};33var obj16 = {34};35var obj17 = {36};37var obj18 = {38};39var obj19 = {40};41var obj20 = {42};

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var extend = require('extend');3var assert = require('assert');4var sinonStubPromise = require('sinon-stub-promise');5sinonStubPromise(sinon);6var myObj = {7 get: function (url) {8 return new Promise(function (resolve, reject) {9 });10 }11};12var stub = sinon.stub(myObj, 'get');13stub.returnsPromise().resolves('foo');14describe('test', function () {15 it('test', function () {16 });17});18var stub = sinon.stub(myObj, 'get').returnsPromise().resolves('foo');19var sinon = require('sinon');20var extend = require('extend');21var assert = require('assert');22var sinonStubPromise = require('sinon-stub-promise');23sinonStubPromise(sinon);24var myObj = {25 get: function (url) {26 return new Promise(function (resolve, reject) {27 });28 }29};30var stub = sinon.stub(myObj, 'get');31stub.returnsPromise().resolves('foo');32describe('test', function () {33 it('test', function () {34 });35});36var stub = sinon.stub(myObj, 'get').returnsPromise().resolves('foo');37var sinon = require('sinon');38var extend = require('extend');39var assert = require('assert');

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var sinonTest = require('sinon-test');3sinon.test = sinonTest.configureTest(sinon);4sinon.test(function(){5});6sinon.test(function(){7});8sinon.test(function(){9 var sandbox = sinon.sandbox.create();10 sandbox.restore();11});12sinon.test(function(){13 var sandbox = sinon.sandbox.create();14 sandbox.restore();15});16sinon.test(function(){17 var stub = sinon.stub();18 stub.restore();19});20sinon.test(function(){21 var stub = sinon.stub();22 stub.restore();23});24sinon.test(function(){25 var mock = sinon.mock();26 mock.restore();27});28sinon.test(function(){29 var mock = sinon.mock();30 mock.restore();31});32sinon.test(function(){33 var spy = sinon.spy();34 spy.restore();35});36sinon.test(function(){37 var spy = sinon.spy();38 spy.restore();39});40sinon.test(function(){41 var server = sinon.fakeServer.create();42 server.restore();43});44sinon.test(function(){45 var server = sinon.fakeServer.create();46 server.restore();47});48sinon.test(function(){49 var clock = sinon.useFakeTimers();50 clock.restore();51});52sinon.test(function(){53 var clock = sinon.useFakeTimers();54 clock.restore();55});56sinon.test(function(){57 var xhr = sinon.useFakeXMLHttpRequest();58 xhr.restore();59});60sinon.test(function(){61 var xhr = sinon.useFakeXMLHttpRequest();62 xhr.restore();63});64sinon.test(function(){

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var myObj = {3 myMethod: function(){4 console.log('my method called');5 }6};7var spy = sinon.spy(myObj, 'myMethod');8myObj.myMethod();9var sinon = require('sinon');10var myObj = {11 myMethod: function(){12 console.log('my method called');13 }14};15var stub = sinon.stub(myObj, 'myMethod');16myObj.myMethod();17var myObj = {18 myMethod: function(){19 console.log('my method called');20 }21};22var stub = sinon.stub(myObj, 'myMethod');23myObj.myMethod();24stub.restore();25myObj.myMethod();26var sinon = require('sinon');27var myObj = {28 myMethod: function(){29 console.log('my method called');30 }31};32var stub = sinon.stub(myObj, 'myMethod');33myObj.myMethod();34stub.restore();35myObj.myMethod();36var sinon = require('sinon');37var myObj = {38 myMethod: function(){39 console.log('my method called');40 }41};42var stub = sinon.stub(myObj, 'myMethod');43myObj.myMethod();44stub.restore();45myObj.myMethod();46var sinon = require('sinon');47var myObj = {48 myMethod: function(){49 console.log('my method called');50 }51};52var stub = sinon.stub(myObj, 'myMethod');53myObj.myMethod();54stub.restore();55myObj.myMethod();56var sinon = require('sinon');57var myObj = {58 myMethod: function(){59 console.log('my method called');60 }61};62var stub = sinon.stub(myObj, 'myMethod');63myObj.myMethod();64stub.restore();65myObj.myMethod();66var sinon = require('

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var extend = require('extend');3var extend = sinon.spy(extend);4var a = {a: 'a'};5var b = {b: 'b'};6extend(a, b);7console.log(a);8console.log(extend.calledOn(new

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var extend = require('extend');3var sinonExtend = require('sinon-extend');4sinonExtend(sinon, extend);5var foo = sinon.stub().returns(42);6console.log(foo());7var sinon = require('sinon');8var extend = require('extend');9var sinonExtend = require('sinon-extend');10sinonExtend(sinon, extend);11var foo = sinon.stub().returns(42);12console.log(foo());13var sinon = require('sinon');14var extend = require('extend');15var sinonExtend = require('sinon-extend');16sinonExtend(sinon, extend);17var foo = sinon.stub().returns(42);18console.log(foo());19var sinon = require('sinon');20var extend = require('extend');21var sinonExtend = require('sinon-extend');22sinonExtend(sinon, extend);23describe('test', function() {24 it('test', function() {25 var obj = {26 foo: function() {27 return 42;28 }29 };30 var objStub = sinon.stub(obj);31 objStub.foo.withArgs(1).returns(1);32 objStub.foo.withArgs(2).returns(2);33 objStub.foo.withArgs(3).returns(3);34 console.log(objStub.foo(1));35 console.log(objStub.foo(2));36 console.log(objStub.foo(3));37 });38});

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var extend = require('extend');3var assert = require('assert');4var a = { a: 1, b: 2, c: 3 };5var b = { b: 4, c: 5, d: 6 };6var c = extend(a, b);7console.log(c);8var a = { a: 1, b: 2, c: 3 };9var b = { b: 4, c: 5, d: 6 };10var c = sinon.extend(a, b);11console.log(c);12{ a: 1, b: 4, c: 5, d: 6 }13{ a: 1, b: 2, c: 3, d: 6 }14What is the difference between extend() and sinon.extend() ?15Your name to display (optional):16Your name to display (optional):17Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var obj = {4 method: function() {5 console.log('hello');6 }7}8obj.method = sinon.spy();9obj.method();10assert(obj.method.called);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run sinon automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful