Best JavaScript code snippet using chai
model_deploy.py
Source:model_deploy.py
...193 clone_loss)194 if regularization_loss is not None:195 tf.summary.scalar('Losses/regularization_loss', regularization_loss)196 return sum_loss197def _optimize_clone(optimizer, clone, num_clones, regularization_losses,198 **kwargs):199 """Compute losses and gradients for a single clone.200 Args:201 optimizer: A tf.Optimizer object.202 clone: A Clone namedtuple.203 num_clones: The number of clones being deployed.204 regularization_losses: Possibly empty list of regularization_losses205 to add to the clone losses.206 **kwargs: Dict of kwarg to pass to compute_gradients().207 Returns:208 A tuple (clone_loss, clone_grads_and_vars).209 - clone_loss: A tensor for the total loss for the clone. Can be None.210 - clone_grads_and_vars: List of (gradient, variable) for the clone.211 Can be empty.212 """213 sum_loss = _gather_clone_loss(clone, num_clones, regularization_losses)214 clone_grad = None215 if sum_loss is not None:216 with tf.device(clone.device):217 clone_grad = optimizer.compute_gradients(sum_loss, **kwargs)218 return sum_loss, clone_grad219def optimize_clones(clones, optimizer,220 regularization_losses=None,221 **kwargs):222 """Compute clone losses and gradients for the given list of `Clones`.223 Note: The regularization_losses are added to the first clone losses.224 Args:225 clones: List of `Clones` created by `create_clones()`.226 optimizer: An `Optimizer` object.227 regularization_losses: Optional list of regularization losses. If None it228 will gather them from tf.GraphKeys.REGULARIZATION_LOSSES. Pass `[]` to229 exclude them.230 **kwargs: Optional list of keyword arguments to pass to `compute_gradients`.231 Returns:232 A tuple (total_loss, grads_and_vars).233 - total_loss: A Tensor containing the average of the clone losses including234 the regularization loss.235 - grads_and_vars: A List of tuples (gradient, variable) containing the sum236 of the gradients for each variable.237 """238 grads_and_vars = []239 clones_losses = []240 num_clones = len(clones)241 if regularization_losses is None:242 regularization_losses = tf.get_collection(243 tf.GraphKeys.REGULARIZATION_LOSSES)244 for clone in clones:245 with tf.name_scope(clone.scope):246 clone_loss, clone_grad = _optimize_clone(247 optimizer, clone, num_clones, regularization_losses, **kwargs)248 if clone_loss is not None:249 clones_losses.append(clone_loss)250 grads_and_vars.append(clone_grad)251 # Only use regularization_losses for the first clone252 regularization_losses = None253 # Compute the total_loss summing all the clones_losses.254 total_loss = tf.add_n(clones_losses, name='total_loss')255 # Sum the gradients across clones.256 grads_and_vars = _sum_clones_gradients(grads_and_vars)257 return total_loss, grads_and_vars258def deploy(config,259 model_fn,260 args=None,...
cmd.js
Source:cmd.js
1module('cmd');2test('cmd.wrap', function() {3 var p = K.query('#test-data-01 p'),4 cloneP, div, strong, range, cmd;5 var div = K('<div></div>');6 document.body.appendChild(div.get());7 //18 cloneP = p.cloneNode(true);9 document.body.appendChild(cloneP);10 strong = K.query('strong', cloneP);11 range = K.range(document);12 range.selectNode(strong);13 cmd = K.cmd(range);14 cmd.wrap('<span class="aaa"></span>');15 equals(range.html(), '<strong><span class="aaa">efg</span></strong>');16 document.body.removeChild(cloneP);17 //218 cloneP = p.cloneNode(true);19 document.body.appendChild(cloneP);20 strong = K.query('strong', cloneP);21 range = K.range(document);22 range.selectNode(strong);23 cmd = K.cmd(range);24 cmd.wrap('<span style="color:red;"></span>');25 equals(range.html(), '<strong><span style="color:red;">efg</span></strong>');26 document.body.removeChild(cloneP);27 //328 cloneP = p.cloneNode(true);29 document.body.appendChild(cloneP);30 strong = K.query('strong', cloneP);31 range = K.range(document);32 range.selectNodeContents(cloneP);33 cmd = K.cmd(range);34 cmd.wrap('<span style="color:red;"></span>');35 ok(K.queryAll('span[style]', cloneP).length === 7);36 equals(range.toString(), 'abcdefghijkxyz0123456789');37 document.body.removeChild(cloneP);38 //439 cloneP = p.cloneNode(true);40 document.body.appendChild(cloneP);41 strong = K.query('strong', cloneP);42 range = K.range(document);43 range.selectNodeContents(cloneP);44 cmd = K.cmd(range);45 cmd.wrap('<span class="aaa"></span>');46 ok(K.queryAll('span[class="aaa"]', cloneP).length === 7);47 equals(range.toString(), 'abcdefghijkxyz0123456789');48 document.body.removeChild(cloneP);49 //550 cloneP = p.cloneNode(true);51 document.body.appendChild(cloneP);52 strong = K.query('strong', cloneP);53 range = K.range(document);54 range.setStart(strong.firstChild, 1);55 range.setEnd(strong.firstChild, 2);56 cmd = K.cmd(range);57 cmd.wrap('<span class="aaa"></span>');58 equals(range.html(), '<span class="aaa">f</span>');59 document.body.removeChild(cloneP);60 //661 cloneP = p.cloneNode(true);62 document.body.appendChild(cloneP);63 strong = K.query('strong', cloneP);64 range = K.range(document);65 range.setStart(strong.firstChild, 1);66 range.setEnd(strong.firstChild, 3);67 cmd = K.cmd(range);68 cmd.wrap('<span class="aaa"></span>');69 equals(range.html(), '<strong><span class="aaa">fg</span></strong>');70 document.body.removeChild(cloneP);71 //772 cloneP = p.cloneNode(true);73 document.body.appendChild(cloneP);74 strong = K.query('strong', cloneP);75 range = K.range(document);76 range.setStart(strong.firstChild, 1);77 range.setEnd(strong.firstChild, 2);78 cmd = K.cmd(range);79 cmd.wrap('<strong></strong>');80 equals(range.html(), '<strong>f</strong>');81 document.body.removeChild(cloneP);82 //883 cloneP = p.cloneNode(true);84 document.body.appendChild(cloneP);85 strong = K.query('strong', cloneP);86 range = K.range(document);87 range.setStart(cloneP, 1);88 range.setEnd(strong.firstChild, 3);89 cmd = K.cmd(range);90 cmd.wrap('<strong></strong>');91 equals(range.html(), '<strong>efg</strong>');92 document.body.removeChild(cloneP);93 //994 cloneP = p.cloneNode(true);95 document.body.appendChild(cloneP);96 strong = K.query('strong', cloneP);97 range = K.range(document);98 range.selectNodeContents(strong);99 range.collapse(true);100 cmd = K.cmd(range);101 cmd.wrap('<strong></strong>');102 equals(strong.innerHTML.toLowerCase(), '<strong></strong>efg');103 document.body.removeChild(cloneP);104 //10105 cloneP = p.cloneNode(true);106 document.body.appendChild(cloneP);107 strong = K.query('strong', cloneP);108 range = K.range(document);109 range.selectNodeContents(cloneP);110 cmd = K.cmd(range);111 cmd.wrap('<div></div>');112 equals(K(cloneP).first().name, 'div');113 same(K(cloneP).children().length, 1);114 document.body.removeChild(cloneP);115 //11116 cloneP = p.cloneNode(true);117 document.body.appendChild(cloneP);118 strong = K.query('strong', cloneP);119 range = K.range(document);120 range.setStart(strong.firstChild, 3);121 range.setEnd(strong.nextSibling, 3);122 cmd = K.cmd(range);123 cmd.wrap('<strong></strong>');124 equals(cmd.range.html(), '<strong>hij</strong>');125 document.body.removeChild(cloneP);126 //12127 cloneP = p.cloneNode(true);128 document.body.appendChild(cloneP);129 strong = K.query('strong', cloneP);130 range = K.range(document);131 range.selectNode(strong);132 cmd = K.cmd(range);133 cmd.wrap('<div><p></p></div>');134 equals(range.html().replace(/\s/g, ''), '<div><p><strong>efg</strong></p></div>');135 document.body.removeChild(cloneP);136 //13137 cloneP = p.cloneNode(true);138 document.body.appendChild(cloneP);139 strong = K.query('strong', cloneP);140 range = K.range(document);141 range.setStart(strong.firstChild, 1);142 range.setEnd(strong.firstChild, 2);143 cmd = K.cmd(range);144 cmd.wrap('<span class="aaa"><strong></strong></span>');145 equals(range.html(), '<span class="aaa"><strong>f</strong></span>');146 document.body.removeChild(cloneP);147 //14148 cloneP = p.cloneNode(true);149 document.body.appendChild(cloneP);150 strong = K.query('strong', cloneP);151 range = K.range(document);152 range.setStart(strong.firstChild, 1);153 range.setEnd(strong.firstChild, 2);154 cmd = K.cmd(range);155 cmd.wrap('<span class="aaa"><strong><em></em></strong></span>');156 equals(range.html(), '<span class="aaa"><strong><em>f</em></strong></span>');157 document.body.removeChild(cloneP);158 //15159 cloneP = K('<p>abc</p>').get();160 document.body.appendChild(cloneP);161 range = K.range(document);162 range.selectNodeContents(cloneP);163 cmd = K.cmd(range);164 cmd.wrap('<strong></strong>');165 cmd.wrap('<em></em>');166 equals(range.html(), '<strong><em>abc</em></strong>');167 document.body.removeChild(cloneP);168 //16169 div.html('<p>123</p><p>456</p>');170 range = K.range(document);171 range.setStart(div.first().first()[0], 0);172 range.setEnd(div.last().last()[0], 3);173 cmd = K.cmd(range);174 cmd.wrap('<strong></strong>');175 equals(div.html().replace(/\n/, ''), '<p><strong>123</strong></p><p><strong>456</strong></p>');176 div.html('');177 //17178 div.html('123<strong>4</strong>56');179 range = K.range(document);180 range.setStart(div.first()[0], 2);181 range.setEnd(div.first()[0], 3);182 cmd = K.cmd(range);183 cmd.wrap('<strong></strong>');184 equals(range.html(), '<strong>3</strong>');185 div.html('');186});187test('cmd.remove', function() {188 var p = K.query('#test-data-01 p'),189 cloneP, strong, range, cmd;190 var div = K('<div></div>');191 document.body.appendChild(div[0]);192 //1193 cloneP = p.cloneNode(true);194 document.body.appendChild(cloneP);195 strong = K.query('strong', cloneP);196 range = K.range(document);197 range.selectNode(strong);198 cmd = K.cmd(range);199 cmd.remove({200 strong : '*'201 });202 equals(cmd.range.html(), 'efg');203 document.body.removeChild(cloneP);204 //2205 cloneP = p.cloneNode(true);206 document.body.appendChild(cloneP);207 strong = K.query('strong', cloneP);208 range = K.range(document);209 range.selectNode(strong);210 cmd = K.cmd(range);211 cmd.remove({212 '*' : '*'213 });214 equals(cmd.range.html(), 'efg');215 document.body.removeChild(cloneP);216 //3217 cloneP = p.cloneNode(true);218 document.body.appendChild(cloneP);219 strong = K.query('strong', cloneP);220 range = K.range(document);221 range.selectNode(strong);222 cmd = K.cmd(range);223 cmd.remove({224 'span' : '*'225 });226 equals(cmd.range.html(), '<strong>efg</strong>');227 document.body.removeChild(cloneP);228 //4229 div.html('<strong>efg</strong>');230 range = K.range(document);231 range.setStart(div.first().first()[0], 1);232 range.setEnd(div.first().first()[0], 2);233 cmd = K.cmd(range);234 cmd.remove({235 'strong' : '*'236 });237 equals(div.html(), '<strong>e</strong>f<strong>g</strong>');238 equals(cmd.range.toString(), 'f');239 div.html('');240 //5241 cloneP = p.cloneNode(true);242 document.body.appendChild(cloneP);243 strong = K.query('strong', cloneP);244 range = K.range(document);245 range.setStart(strong.firstChild, 0);246 range.setEnd(strong.firstChild, 3);247 cmd = K.cmd(range);248 cmd.remove({249 'strong' : '*'250 });251 equals(cmd.range.toString(), 'efg');252 document.body.removeChild(cloneP);253 //6254 cloneP = p.cloneNode(true);255 document.body.appendChild(cloneP);256 strong = K.query('strong', cloneP);257 K(strong).addClass('abc').css('color', '#FF0000');258 range = K.range(document);259 range.setStart(strong.firstChild, 1);260 range.setEnd(strong.firstChild, 2);261 cmd = K.cmd(range);262 cmd.remove({263 'strong' : 'class'264 });265 equals(range.html().toLowerCase(), '<strong style="color:#ff0000;">f</strong>');266 document.body.removeChild(cloneP);267 //7268 cloneP = p.cloneNode(true);269 document.body.appendChild(cloneP);270 strong = K.query('strong', cloneP);271 K(strong).addClass('abc').css('color', '#FF0000');272 range = K.range(document);273 range.setStart(strong.firstChild, 1);274 range.setEnd(strong.firstChild, 2);275 cmd = K.cmd(range);276 cmd.remove({277 'strong' : 'class,style'278 });279 equals(cmd.range.html().toLowerCase(), '<strong>f</strong>');280 document.body.removeChild(cloneP);281 //8282 cloneP = p.cloneNode(true);283 document.body.appendChild(cloneP);284 strong = K.query('strong', cloneP);285 K(strong).addClass('abc').css('color', '#FF0000');286 range = K.range(document);287 range.setStart(strong.firstChild, 1);288 range.setEnd(strong.firstChild, 2);289 cmd = K.cmd(range);290 cmd.remove({291 'strong' : 'class,.color,.background-color'292 });293 equals(cmd.range.html().toLowerCase(), '<strong>f</strong>');294 document.body.removeChild(cloneP);295 //9296 cloneP = p.cloneNode(true);297 document.body.appendChild(cloneP);298 strong = K.query('strong', cloneP);299 range = K.range(document);300 range.setStart(cloneP, 1);301 range.setEnd(strong.firstChild, 3);302 cmd = K.cmd(range);303 cmd.remove({304 'strong' : '*'305 });306 equals(range.html(), 'efg');307 document.body.removeChild(cloneP);308 //10309 cloneP = p.cloneNode(true);310 document.body.appendChild(cloneP);311 strong = K.query('strong', cloneP);312 strong.innerHTML = '<strong>efg</strong>';313 range = K.range(document);314 range.setStart(strong.firstChild.firstChild, 1);315 range.setEnd(strong.firstChild.firstChild, 2);316 cmd = K.cmd(range);317 cmd.remove({318 'strong' : '*'319 });320 equals(range.html(), 'f');321 document.body.removeChild(cloneP);322 //11323 cloneP = p.cloneNode(true);324 document.body.appendChild(cloneP);325 strong = K.query('strong', cloneP);326 strong.innerHTML = '<strong>efg</strong>';327 range = K.range(document);328 range.setStart(strong.firstChild.firstChild, 0);329 range.setEnd(strong.firstChild.firstChild, 3);330 cmd = K.cmd(range);331 cmd.remove({332 'strong' : '*'333 });334 equals(K(cloneP).html().substr(0, 11), 'abcdefghijk');335 document.body.removeChild(cloneP);336 //12337 cloneP = p.cloneNode(true);338 document.body.appendChild(cloneP);339 strong = K.query('strong', cloneP);340 range = K.range(document);341 range.setStart(strong.firstChild, 1);342 range.setEnd(strong.firstChild, 1);343 cmd = K.cmd(range);344 cmd.remove({345 'strong' : '*'346 });347 var str = 'abcd<strong>e</strong><strong>fg';348 equals(K(cloneP).html().substr(0, str.length), str);349 document.body.removeChild(cloneP);350 //13351 cloneP = p.cloneNode(true);352 document.body.appendChild(cloneP);353 strong = K.query('strong', cloneP);354 range = K.range(document);355 range.setStart(strong.firstChild, 1);356 range.setEnd(strong.firstChild, 2);357 cmd = K.cmd(range);358 cmd.remove({359 'strong' : '*'360 });361 cmd.wrap('<strong></strong>');362 equals(range.html(), '<strong>f</strong>');363 document.body.removeChild(cloneP);364 //14365 cloneP = p.cloneNode(true);366 document.body.appendChild(cloneP);367 strong = K.query('strong', cloneP);368 range = K.range(document);369 range.selectNodeContents(strong);370 cmd = K.cmd(range);371 cmd.remove({372 strong : '*'373 });374 equals(range.html(), 'efg');375 document.body.removeChild(cloneP);376});377test('cmd.execute', function() {378 var div = K('<div></div>'), node, range;379 document.body.appendChild(div[0]);380 //1381 node = K('<strong>abcd</strong>').get();382 div.append(node);383 range = K.range(document);384 range.selectNode(node);385 cmd = K.cmd(range);386 cmd.bold();387 cmd.bold();388 equals(range.html(), '<strong>abcd</strong>');389 div.html('');390 //2391 div.html('abcd');392 range = K.range(document);393 range.setStart(div.first().get(), 0);394 range.setEnd(div.first().get(), 4);395 cmd = K.cmd(range);396 cmd.bold();397 cmd.italic();398 equals(range.html(), '<strong><em>abcd</em></strong>');399 div.html('');400 //3401 div.html('abcd');402 range = K.range(document);403 range.setStart(div.first().get(), 0);404 range.setEnd(div.first().get(), 4);405 cmd = K.cmd(range);406 cmd.bold();407 cmd.italic();408 cmd.bold();409 equals(range.html(), '<em>abcd</em>');410 div.html('');411 //4412 div.html('<strong>abc</strong><strong>def</strong><strong>ghi</strong>');413 range = K.range(document);414 range.setStart(div.first().first().get(), 3);415 range.setEnd(div.first().next().first().get(), 3);416 cmd = K.cmd(range);417 cmd.bold();418 equals(range.html(), 'def');419 div.html('');420 //5421 div.html('<div>abcd<img /><strong>efg</strong><br />hijk</div>');422 range = K.range(document);423 range.selectNodeContents(div[0]);424 cmd = K.cmd(range);425 cmd.removeformat();426 equals(range.html(), '<div>abcd<img />efg<br />hijk</div>');427 div.html('');428 //6429 div.html('<p>abcd</p><p>1234</p>');430 range = K.range(document);431 range.selectNodeContents(div[0]);432 cmd = K.cmd(range);433 cmd.bold();434 equals(range.html().replace(/\n/, ''), '<p><strong>abcd</strong></p><p><strong>1234</strong></p>');435 cmd.removeformat();436 equals(range.html().replace(/\n/, ''), '<p>abcd</p><p>1234</p>');437 div.html('');438 //7439 div.html('<p><strong>abcd</strong></p><p><strong>1234</strong></p>');440 range = K.range(document);441 range.setStart(div.first().first().last()[0], 0);442 range.setEnd(div.last().last().last()[0], 4);443 cmd = K.cmd(range);444 cmd.removeformat();445 equals(range.html().replace(/\n/, ''), '<p>abcd</p><p>1234</p>');446 div.html('');447 //8448 div.html('<p><strong>abcd</strong></p><p><strong>1234</strong></p>');449 range = K.range(document);450 range.setStart(div.first().first().first()[0], 0);451 range.setEnd(div.last().last().last()[0], 4);452 cmd = K.cmd(range);453 cmd.italic();454 equals(range.html().replace(/\n/, ''), '<p><strong><em>abcd</em></strong></p><p><strong><em>1234</em></strong></p>');455 div.html('');456 //9457 div.html('<p><strong>abcd</strong></p><p><strong>1234</strong></p>');458 range = K.range(document);459 range.setStart(div.first().first()[0], 0);460 range.setEnd(div.last().last()[0], 1);461 cmd = K.cmd(range);462 cmd.italic();463 equals(range.html().replace(/\n/, ''), '<p><strong><em>abcd</em></strong></p><p><strong><em>1234</em></strong></p>');464 div.html('');465 //10466 div.html('<table><tr><td>1</td></tr></table><img>0123456789');467 range = K.range(document);468 range.setStart(div.last()[0], 4);469 range.setEnd(div.last()[0], 6);470 cmd = K.cmd(range);471 cmd.bold();472 cmd.bold();473 cmd.bold();474 equals(range.html().replace(/\n/, ''), '<strong>45</strong>');475 div.html('');476 //11477 div.html('<table><tr><td>1</td></tr></table><img>0123<strong>45</strong>6789');478 range = K.range(document);479 range.setStart(div.last().prev().prev()[0], 4);480 range.setEnd(div.last()[0], 0);481 cmd = K.cmd(range);482 cmd.bold();483 equals(range.html().replace(/\n/, ''), '45');484 div.html('');485 //12486 div.html('<p><strong><em>123456789</em></strong></p>');487 range = K.range(document);488 range.setStart(div.first().first().first()[0], 0);489 range.setEnd(div.first().first().first().first()[0], 9);490 cmd = K.cmd(range);491 cmd.underline();492 equals(div.html().replace(/\n/, ''), '<p><strong><em><u>123456789</u></em></strong></p>');493 div.html('');494 //13495 div.html('<p><strong><em>123456789</em></strong></p>');496 range = K.range(document);497 range.setStart(div.first().first().first()[0], 0);498 range.setEnd(div.first().first().first().first()[0], 9);499 cmd = K.cmd(range);500 cmd.bold();501 equals(div.html().replace(/\n/, ''), '<p><em>123456789</em></p>');502 div.html('');503 //14504 div.html('<p style="background-color:#000000;">1234</p>');505 range = K.range(document);506 range.setStart(div.first().first()[0], 0);507 range.setEnd(div.first().first()[0], 4);508 cmd = K.cmd(range);509 cmd.removeformat();510 equals(div.html().replace(/\n/, ''), '<p>1234</p>');511 div.html('');512 //15513 div.html('<span style="color:#e56600;">abc</span><span><span style="color:#e56600;">d</span><span style="color:#e56600;">efg</span></span>');514 range = K.range(document);515 range.setStart(div[0], 0);516 range.setEnd(div[0], 2);517 cmd = K.cmd(range);518 cmd.removeformat();519 same(range.html(), 'abcdefg');520 div.html('');521 //14522 div.html('\n<span></span><span><span style="font-size:18px;">abcd</span><span style="font-size:18px;"></span><span style="font-size:18px;"></span></span>\n');523 range = K.range(document);524 range.setEnd(div[0], 0);525 range.setEnd(div.first().next()[0], 1);526 cmd = K.cmd(range);527 cmd.removeformat();528 same(range.html(), 'abcd');529 div.html('');530 //15531 div.html('<img src="/kindeditor/plugins/emoticons/images/0.gif" /><strong>abc</strong>');532 range = K.range(document);533 range.selectNodeContents(div.last()[0]);534 cmd = K.cmd(range);535 cmd.bold();536 equals(div.html(), '<img src="/kindeditor/plugins/emoticons/images/0.gif" />abc');537 div.html('');538});539test('cmd.inserthtml', function() {540 //1541 var div = K('<div>1234</div>');542 K(document.body).append(div);543 range = K.range(document);544 range.setStart(div.first()[0], 1);545 range.setEnd(div.first()[0], 1);546 cmd = K.cmd(range);547 cmd.inserthtml('<strong>abcd</strong>');548 equals(div.html().replace(/\n/, ''), '1<strong>abcd</strong>234');549 div.remove();550});551test('cmd.insertimage', function() {552 //1553 var div = K('<div><p align="center">123</p><p align="center"><img style="margin-right:10px;" height="100" width="100" /></p><p align="center">123</p></div>');554 K(document.body).append(div);555 range = K.range(document);556 var img = K('img', div);557 range.selectNode(img[0]);558 cmd = K.cmd(range);559 var url = 'http://www.kindsoft.net/images/logo.png';560 cmd.insertimage(url);561 equals(K('img', div).attr('src'), url);562 div.remove();...
Box2.tests.js
Source:Box2.tests.js
...18 QUnit.test( "Instancing", ( assert ) => {19 var a = new Box2();20 assert.ok( a.min.equals( posInf2 ), "Passed!" );21 assert.ok( a.max.equals( negInf2 ), "Passed!" );22 var a = new Box2( zero2.clone(), zero2.clone() );23 assert.ok( a.min.equals( zero2 ), "Passed!" );24 assert.ok( a.max.equals( zero2 ), "Passed!" );25 var a = new Box2( zero2.clone(), one2.clone() );26 assert.ok( a.min.equals( zero2 ), "Passed!" );27 assert.ok( a.max.equals( one2 ), "Passed!" );28 } );29 // PUBLIC STUFF30 QUnit.test( "set", ( assert ) => {31 var a = new Box2();32 a.set( zero2, one2 );33 assert.ok( a.min.equals( zero2 ), "Passed!" );34 assert.ok( a.max.equals( one2 ), "Passed!" );35 } );36 QUnit.test( "setFromPoints", ( assert ) => {37 var a = new Box2();38 a.setFromPoints( [ zero2, one2, two2 ] );39 assert.ok( a.min.equals( zero2 ), "Passed!" );40 assert.ok( a.max.equals( two2 ), "Passed!" );41 a.setFromPoints( [ one2 ] );42 assert.ok( a.min.equals( one2 ), "Passed!" );43 assert.ok( a.max.equals( one2 ), "Passed!" );44 a.setFromPoints( [] );45 assert.ok( a.isEmpty(), "Passed!" );46 } );47 QUnit.todo( "setFromCenterAndSize", ( assert ) => {48 assert.ok( false, "everything's gonna be alright" );49 } );50 QUnit.todo( "clone", ( assert ) => {51 assert.ok( false, "everything's gonna be alright" );52 } );53 QUnit.test( "copy", ( assert ) => {54 var a = new Box2( zero2.clone(), one2.clone() );55 var b = new Box2().copy( a );56 assert.ok( b.min.equals( zero2 ), "Passed!" );57 assert.ok( b.max.equals( one2 ), "Passed!" );58 // ensure that it is a true copy59 a.min = zero2;60 a.max = one2;61 assert.ok( b.min.equals( zero2 ), "Passed!" );62 assert.ok( b.max.equals( one2 ), "Passed!" );63 } );64 QUnit.test( "empty/makeEmpty", ( assert ) => {65 var a = new Box2();66 assert.ok( a.isEmpty(), "Passed!" );67 var a = new Box2( zero2.clone(), one2.clone() );68 assert.ok( ! a.isEmpty(), "Passed!" );69 a.makeEmpty();70 assert.ok( a.isEmpty(), "Passed!" );71 } );72 QUnit.todo( "isEmpty", ( assert ) => {73 assert.ok( false, "everything's gonna be alright" );74 } );75 QUnit.test( "getCenter", ( assert ) => {76 var a = new Box2( zero2.clone(), zero2.clone() );77 var center = new Vector2();78 assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );79 var a = new Box2( zero2, one2 );80 var midpoint = one2.clone().multiplyScalar( 0.5 );81 assert.ok( a.getCenter( center ).equals( midpoint ), "Passed!" );82 } );83 QUnit.test( "getSize", ( assert ) => {84 var a = new Box2( zero2.clone(), zero2.clone() );85 var size = new Vector2();86 assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );87 var a = new Box2( zero2.clone(), one2.clone() );88 assert.ok( a.getSize( size ).equals( one2 ), "Passed!" );89 } );90 QUnit.test( "expandByPoint", ( assert ) => {91 var a = new Box2( zero2.clone(), zero2.clone() );92 var size = new Vector2();93 var center = new Vector2();94 a.expandByPoint( zero2 );95 assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );96 a.expandByPoint( one2 );97 assert.ok( a.getSize( size ).equals( one2 ), "Passed!" );98 a.expandByPoint( one2.clone().negate() );99 assert.ok( a.getSize( size ).equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );100 assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );101 } );102 QUnit.test( "expandByVector", ( assert ) => {103 var a = new Box2( zero2.clone(), zero2.clone() );104 var size = new Vector2();105 var center = new Vector2();106 a.expandByVector( zero2 );107 assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );108 a.expandByVector( one2 );109 assert.ok( a.getSize( size ).equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );110 assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );111 } );112 QUnit.test( "expandByScalar", ( assert ) => {113 var a = new Box2( zero2.clone(), zero2.clone() );114 var size = new Vector2();115 var center = new Vector2();116 a.expandByScalar( 0 );117 assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );118 a.expandByScalar( 1 );119 assert.ok( a.getSize( size ).equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );120 assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );121 } );122 QUnit.test( "containsPoint", ( assert ) => {123 var a = new Box2( zero2.clone(), zero2.clone() );124 assert.ok( a.containsPoint( zero2 ), "Passed!" );125 assert.ok( ! a.containsPoint( one2 ), "Passed!" );126 a.expandByScalar( 1 );127 assert.ok( a.containsPoint( zero2 ), "Passed!" );128 assert.ok( a.containsPoint( one2 ), "Passed!" );129 assert.ok( a.containsPoint( one2.clone().negate() ), "Passed!" );130 } );131 QUnit.test( "containsBox", ( assert ) => {132 var a = new Box2( zero2.clone(), zero2.clone() );133 var b = new Box2( zero2.clone(), one2.clone() );134 var c = new Box2( one2.clone().negate(), one2.clone() );135 assert.ok( a.containsBox( a ), "Passed!" );136 assert.ok( ! a.containsBox( b ), "Passed!" );137 assert.ok( ! a.containsBox( c ), "Passed!" );138 assert.ok( b.containsBox( a ), "Passed!" );139 assert.ok( c.containsBox( a ), "Passed!" );140 assert.ok( ! b.containsBox( c ), "Passed!" );141 } );142 QUnit.test( "getParameter", ( assert ) => {143 var a = new Box2( zero2.clone(), one2.clone() );144 var b = new Box2( one2.clone().negate(), one2.clone() );145 var parameter = new Vector2();146 a.getParameter( zero2, parameter );147 assert.ok( parameter.equals( zero2 ), "Passed!" );148 a.getParameter( one2, parameter );149 assert.ok( parameter.equals( one2 ), "Passed!" );150 b.getParameter( one2.clone().negate(), parameter );151 assert.ok( parameter.equals( zero2 ), "Passed!" );152 b.getParameter( zero2, parameter );153 assert.ok( parameter.equals( new Vector2( 0.5, 0.5 ) ), "Passed!" );154 b.getParameter( one2, parameter );155 assert.ok( parameter.equals( one2 ), "Passed!" );156 } );157 QUnit.test( "intersectsBox", ( assert ) => {158 var a = new Box2( zero2.clone(), zero2.clone() );159 var b = new Box2( zero2.clone(), one2.clone() );160 var c = new Box2( one2.clone().negate(), one2.clone() );161 assert.ok( a.intersectsBox( a ), "Passed!" );162 assert.ok( a.intersectsBox( b ), "Passed!" );163 assert.ok( a.intersectsBox( c ), "Passed!" );164 assert.ok( b.intersectsBox( a ), "Passed!" );165 assert.ok( c.intersectsBox( a ), "Passed!" );166 assert.ok( b.intersectsBox( c ), "Passed!" );167 b.translate( two2 );168 assert.ok( ! a.intersectsBox( b ), "Passed!" );169 assert.ok( ! b.intersectsBox( a ), "Passed!" );170 assert.ok( ! b.intersectsBox( c ), "Passed!" );171 } );172 QUnit.test( "clampPoint", ( assert ) => {173 var a = new Box2( zero2.clone(), zero2.clone() );174 var b = new Box2( one2.clone().negate(), one2.clone() );175 var point = new Vector2();176 a.clampPoint( zero2, point );177 assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );178 a.clampPoint( one2, point );179 assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );180 a.clampPoint( one2.clone().negate(), point );181 assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );182 b.clampPoint( two2, point );183 assert.ok( point.equals( new Vector2( 1, 1 ) ), "Passed!" );184 b.clampPoint( one2, point );185 assert.ok( point.equals( new Vector2( 1, 1 ) ), "Passed!" );186 b.clampPoint( zero2, point );187 assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );188 b.clampPoint( one2.clone().negate(), point );189 assert.ok( point.equals( new Vector2( - 1, - 1 ) ), "Passed!" );190 b.clampPoint( two2.clone().negate(), point );191 assert.ok( point.equals( new Vector2( - 1, - 1 ) ), "Passed!" );192 } );193 QUnit.test( "distanceToPoint", ( assert ) => {194 var a = new Box2( zero2.clone(), zero2.clone() );195 var b = new Box2( one2.clone().negate(), one2.clone() );196 assert.ok( a.distanceToPoint( new Vector2( 0, 0 ) ) == 0, "Passed!" );197 assert.ok( a.distanceToPoint( new Vector2( 1, 1 ) ) == Math.sqrt( 2 ), "Passed!" );198 assert.ok( a.distanceToPoint( new Vector2( - 1, - 1 ) ) == Math.sqrt( 2 ), "Passed!" );199 assert.ok( b.distanceToPoint( new Vector2( 2, 2 ) ) == Math.sqrt( 2 ), "Passed!" );200 assert.ok( b.distanceToPoint( new Vector2( 1, 1 ) ) == 0, "Passed!" );201 assert.ok( b.distanceToPoint( new Vector2( 0, 0 ) ) == 0, "Passed!" );202 assert.ok( b.distanceToPoint( new Vector2( - 1, - 1 ) ) == 0, "Passed!" );203 assert.ok( b.distanceToPoint( new Vector2( - 2, - 2 ) ) == Math.sqrt( 2 ), "Passed!" );204 } );205 QUnit.test( "intersect", ( assert ) => {206 var a = new Box2( zero2.clone(), zero2.clone() );207 var b = new Box2( zero2.clone(), one2.clone() );208 var c = new Box2( one2.clone().negate(), one2.clone() );209 assert.ok( a.clone().intersect( a ).equals( a ), "Passed!" );210 assert.ok( a.clone().intersect( b ).equals( a ), "Passed!" );211 assert.ok( b.clone().intersect( b ).equals( b ), "Passed!" );212 assert.ok( a.clone().intersect( c ).equals( a ), "Passed!" );213 assert.ok( b.clone().intersect( c ).equals( b ), "Passed!" );214 assert.ok( c.clone().intersect( c ).equals( c ), "Passed!" );215 } );216 QUnit.test( "union", ( assert ) => {217 var a = new Box2( zero2.clone(), zero2.clone() );218 var b = new Box2( zero2.clone(), one2.clone() );219 var c = new Box2( one2.clone().negate(), one2.clone() );220 assert.ok( a.clone().union( a ).equals( a ), "Passed!" );221 assert.ok( a.clone().union( b ).equals( b ), "Passed!" );222 assert.ok( a.clone().union( c ).equals( c ), "Passed!" );223 assert.ok( b.clone().union( c ).equals( c ), "Passed!" );224 } );225 QUnit.test( "translate", ( assert ) => {226 var a = new Box2( zero2.clone(), zero2.clone() );227 var b = new Box2( zero2.clone(), one2.clone() );228 var c = new Box2( one2.clone().negate(), one2.clone() );229 var d = new Box2( one2.clone().negate(), zero2.clone() );230 assert.ok( a.clone().translate( one2 ).equals( new Box2( one2, one2 ) ), "Passed!" );231 assert.ok( a.clone().translate( one2 ).translate( one2.clone().negate() ).equals( a ), "Passed!" );232 assert.ok( d.clone().translate( one2 ).equals( b ), "Passed!" );233 assert.ok( b.clone().translate( one2.clone().negate() ).equals( d ), "Passed!" );234 } );235 QUnit.todo( "equals", ( assert ) => {236 assert.ok( false, "everything's gonna be alright" );237 } );238 } );...
shadowClone.js
Source:shadowClone.js
1var CenteringTextElement = require("./util/CenteringTextElement");2var elementTools = require("./util/elementTools")();3var math = require("./util/math")();4module.exports = function (graph) {5 /** variable defs **/6 var ShadowClone = {};7 ShadowClone.nodeId = 10003;8 ShadowClone.parent = undefined;9 ShadowClone.s_x = 0;10 ShadowClone.s_y = 0;11 ShadowClone.e_x = 0;12 ShadowClone.e_y = 0;13 ShadowClone.rootElement = undefined;14 ShadowClone.rootNodeLayer = undefined;15 ShadowClone.pathLayer = undefined;16 ShadowClone.nodeElement = undefined;17 ShadowClone.pathElement = undefined;18 ShadowClone.typus = "shadowClone";19 ShadowClone.type = function () {20 return ShadowClone.typus;21 };22 // TODO: We need the endPoint of the Link here!23 ShadowClone.parentNode = function () {24 return ShadowClone.parent;25 };26 ShadowClone.setParentProperty = function (parentProperty, inverted) {27 ShadowClone.invertedProperty = inverted;28 ShadowClone.parent = parentProperty;29 var renElment;30 if (inverted === true) {31 renElment = parentProperty.inverse().labelObject();32 if (renElment !== undefined) {33 if (renElment.linkRangeIntersection && renElment.linkDomainIntersection) {34 var iiP_range = renElment.linkDomainIntersection;35 var iiP_domain = renElment.linkRangeIntersection;36 ShadowClone.s_x = iiP_domain.x;37 ShadowClone.s_y = iiP_domain.y;38 ShadowClone.e_x = iiP_range.x;39 ShadowClone.e_y = iiP_range.y;40 }41 }42 } else {43 renElment = parentProperty.labelObject();44 if (renElment.linkRangeIntersection && renElment.linkDomainIntersection) {45 var iP_range = renElment.linkRangeIntersection;46 var iP_domain = renElment.linkDomainIntersection;47 ShadowClone.s_x = iP_domain.x;48 ShadowClone.s_y = iP_domain.y;49 ShadowClone.e_x = iP_range.x;50 ShadowClone.e_y = iP_range.y;51 }52 }53 ShadowClone.rootNodeLayer.remove();54 ShadowClone.rootNodeLayer = ShadowClone.rootElement.append('g');55 ShadowClone.rootNodeLayer.datum(parentProperty);56 // ShadowClone.pathElement.remove();57 // ShadowClone.pathElement = ShadowClone.pathLayer.append('line');58 //59 // ShadowClone.pathElement.attr("x1", ShadowClone.s_x)60 // .attr("y1", ShadowClone.s_y)61 // .attr("x2", ShadowClone.e_x)62 // .attr("y2", ShadowClone.e_y);63 ShadowClone.pathElement.remove();64 ShadowClone.pathElement = ShadowClone.pathLayer.append('line');65 ShadowClone.markerElement = ShadowClone.pathLayer.append("marker");66 ShadowClone.markerElement.attr("id", "shadowCloneMarker");67 ShadowClone.pathElement.attr("x1", ShadowClone.e_x)68 .attr("y1", ShadowClone.e_y)69 .attr("x2", ShadowClone.s_x)70 .attr("y2", ShadowClone.s_y);71 ShadowClone.pathElement.classed(parentProperty.linkType(), true);72 if (parentProperty.markerElement()) {73 ShadowClone.markerElement.attr("viewBox", parentProperty.markerElement().attr("viewBox"))74 .attr("markerWidth", parentProperty.markerElement().attr("markerWidth"))75 .attr("markerHeight", parentProperty.markerElement().attr("markerHeight"))76 .attr("orient", parentProperty.markerElement().attr("orient"));77 var markerPath = parentProperty.markerElement().select("path");78 if (!markerPath[0].includes(null)) {79 ShadowClone.markerElement.append("path")80 .attr("d", markerPath.attr("d"))81 .classed(parentProperty.markerType(), true);82 }83 ShadowClone.pathElement.attr("marker-end", "url(#" + "shadowCloneMarker" + ")");84 ShadowClone.markerElement.classed("hidden", !elementTools.isDatatypeProperty(parentProperty));85 }86 var rect = ShadowClone.rootNodeLayer.append("rect")87 .classed(parentProperty.styleClass(), true)88 .classed("property", true)89 .attr("x", -parentProperty.width() / 2)90 .attr("y", -parentProperty.height() / 2)91 .attr("width", parentProperty.width())92 .attr("height", parentProperty.height());93 if (parentProperty.visualAttributes()) {94 rect.classed(parentProperty.visualAttributes(), true);95 }96 rect.classed("datatype", false);97 var bgColor = parentProperty.backgroundColor();98 if (parentProperty.attributes().indexOf("deprecated") > -1) {99 bgColor = undefined;100 rect.classed("deprecatedproperty", true);101 } else {102 rect.classed("deprecatedproperty", false);103 }104 rect.style("fill", bgColor);105 // add Text;106 var equivalentsString = parentProperty.equivalentsString();107 var suffixForFollowingEquivalents = equivalentsString ? "," : "";108 var textElement = new CenteringTextElement(ShadowClone.rootNodeLayer, bgColor);109 textElement.addText(parentProperty.labelForCurrentLanguage(), "", suffixForFollowingEquivalents);110 textElement.addEquivalents(equivalentsString);111 textElement.addSubText(parentProperty.indicationString());112 var cx = 0.5 * (ShadowClone.s_x + ShadowClone.e_x);113 var cy = 0.5 * (ShadowClone.s_y + ShadowClone.e_y);114 ShadowClone.rootNodeLayer.attr("transform", "translate(" + cx + "," + cy + ")");115 ShadowClone.rootNodeLayer.classed("hidden", true);116 ShadowClone.pathElement.classed("hidden", true);117 };118 ShadowClone.hideClone = function (val) {119 if (ShadowClone.rootNodeLayer) ShadowClone.rootNodeLayer.classed("hidden", val);120 if (ShadowClone.pathElement) ShadowClone.pathElement.classed("hidden", val);121 };122 ShadowClone.hideParentProperty = function (val) {123 var labelObj = ShadowClone.parent.labelObject();124 if (labelObj) {125 if (ShadowClone.parent.labelElement().attr("transform") === "translate(0,15)" ||126 ShadowClone.parent.labelElement().attr("transform") === "translate(0,-15)")127 ShadowClone.parent.inverse().hide(val);128 }129 ShadowClone.parent.hide(val);130 };131 /** BASE HANDLING FUNCTIONS ------------------------------------------------- **/132 ShadowClone.id = function (index) {133 if (!arguments.length) {134 return ShadowClone.nodeId;135 }136 ShadowClone.nodeId = index;137 };138 ShadowClone.svgPathLayer = function (layer) {139 ShadowClone.pathLayer = layer.append('g');140 };141 ShadowClone.svgRoot = function (root) {142 if (!arguments.length)143 return ShadowClone.rootElement;144 ShadowClone.rootElement = root;145 ShadowClone.rootNodeLayer = ShadowClone.rootElement.append('g');146 };147 /** DRAWING FUNCTIONS ------------------------------------------------- **/148 ShadowClone.drawClone = function () {149 ShadowClone.pathElement = ShadowClone.pathLayer.append('line');150 ShadowClone.pathElement.attr("x1", 0)151 .attr("y1", 0)152 .attr("x2", 0)153 .attr("y2", 0);154 };155 ShadowClone.updateElement = function () {156 ShadowClone.pathElement.attr("x1", ShadowClone.e_x)157 .attr("y1", ShadowClone.e_y)158 .attr("x2", ShadowClone.s_x)159 .attr("y2", ShadowClone.s_y);160 var cx = 0.5 * (ShadowClone.s_x + ShadowClone.e_x);161 var cy = 0.5 * (ShadowClone.s_y + ShadowClone.e_y);162 ShadowClone.rootNodeLayer.attr("transform", "translate(" + cx + "," + cy + ")");163 };164 ShadowClone.setInitialPosition = function () {165 var renElment = ShadowClone.parent.labelObject();166 if (renElment.linkRangeIntersection && renElment.linkDomainIntersection) {167 var iP_range = renElment.linkRangeIntersection;168 var iP_domain = renElment.linkDomainIntersection;169 ShadowClone.e_x = iP_domain.x;170 ShadowClone.e_y = iP_domain.y;171 ShadowClone.s_x = iP_range.x;172 ShadowClone.s_y = iP_range.y;173 }174 ShadowClone.updateElement();175 return;176 //177 // var rex=ShadowClone.parent.range().x;178 // var rey=ShadowClone.parent.range().y;179 //180 //181 // var dex=ShadowClone.parent.domain().x;182 // var dey=ShadowClone.parent.domain().y;183 //184 //185 // var dir_X= rex-dex;186 // var dir_Y= rey-dey;187 //188 // var len=Math.sqrt(dir_X*dir_X+dir_Y*dir_Y);189 // var nX=dir_X/len;190 // var nY=dir_Y/len;191 // ShadowClone.s_x=rex-nX*ShadowClone.parent.range().actualRadius();192 // ShadowClone.s_y=rey-nY*ShadowClone.parent.range().actualRadius();193 //194 // ShadowClone.e_x=dex+nX*ShadowClone.parent.domain().actualRadius();195 // ShadowClone.e_y=dey+nY*ShadowClone.parent.domain().actualRadius();196 // ShadowClone.updateElement();197 };198 ShadowClone.setPositionDomain = function (e_x, e_y) {199 var rex = ShadowClone.parent.range().x;200 var rey = ShadowClone.parent.range().y;201 if (elementTools.isDatatype(ShadowClone.parent.range()) === true) {202 var intersection = math.calculateIntersection({ x: e_x, y: e_y }, ShadowClone.parent.range(), 0);203 ShadowClone.s_x = intersection.x;204 ShadowClone.s_y = intersection.y;205 } else {206 var dir_X = rex - e_x;207 var dir_Y = rey - e_y;208 var len = Math.sqrt(dir_X * dir_X + dir_Y * dir_Y);209 var nX = dir_X / len;210 var nY = dir_Y / len;211 ShadowClone.s_x = rex - nX * ShadowClone.parent.range().actualRadius();212 ShadowClone.s_y = rey - nY * ShadowClone.parent.range().actualRadius();213 }214 ShadowClone.e_x = e_x;215 ShadowClone.e_y = e_y;216 ShadowClone.updateElement();217 };218 ShadowClone.setPosition = function (s_x, s_y) {219 ShadowClone.s_x = s_x;220 ShadowClone.s_y = s_y;221 // add normalized dir;222 var dex = ShadowClone.parent.domain().x;223 var dey = ShadowClone.parent.domain().y;224 var dir_X = s_x - dex;225 var dir_Y = s_y - dey;226 var len = Math.sqrt(dir_X * dir_X + dir_Y * dir_Y);227 var nX = dir_X / len;228 var nY = dir_Y / len;229 ShadowClone.e_x = dex + nX * ShadowClone.parent.domain().actualRadius();230 ShadowClone.e_y = dey + nY * ShadowClone.parent.domain().actualRadius();231 ShadowClone.updateElement();232 };233 /** MOUSE HANDLING FUNCTIONS ------------------------------------------------- **/234 return ShadowClone;...
cssModel.js
Source:cssModel.js
...59 clone: function() {60 return cloneCSSObject(this);61 },62 cloneNode: function() {63 return this.clone();64 }65 }66 function ArrayCloneObject(array) {67 this.length = 0;68 for (var i = 0; i < array.length; i++) {69 this.push(cloneCSSObject(array[i]));70 }71 }72 ArrayCloneObject.prototype = {73 // for in interation does not work on built in types, thus we have to74 // selectively extend the array prototype75 push: Array.prototype.push,76 splice: Array.prototype.splice,77 equals: function arrayEquals(right) {
...
cssModelTest.js
Source:cssModelTest.js
1function runTest() {2 var urlBase = FBTest.getHTTPURLBase();3 var CSSModel = FBTest.FirebugWindow.FireDiff.CSSModel,4 FBTrace = FBTest.FirebugWindow.FBTrace;5 FBTestFirebug.openNewTab(urlBase + "lib/cssModel.htm", function(win) {6 var doc = win.document;7 8 function createSheet(cssText) {9 var style = doc.createElement("style");10 style.type = "text/css";11 style.innerHTML = cssText;12 13 // Sheet is only defined if it is a part of the document14 doc.getElementsByTagName("head")[0].appendChild(style);15 16 return style.sheet;17 }18 19 function compareCSS(left, right, expected, msg) {20 var cloneLeft = CSSModel.cloneCSSObject(left),21 cloneRight = CSSModel.cloneCSSObject(right);22 FBTest.compare(true, cloneLeft.equals(CSSModel.cloneCSSObject(left)), msg + " left clone identity");23 FBTest.compare(true, cloneRight.equals(CSSModel.cloneCSSObject(right)), msg + " right clone identity");24 FBTest.compare(expected, cloneLeft.equals(cloneRight), msg);25 }26 27 var sheetOne = createSheet(".rule1 {} .rule2 {} .rule3 { border: medium none; }"),28 sheetTwo = createSheet(".rule1 {}"),29 sheetThree = createSheet(".rule1 {} .rule2 {} .rule3 { border: medium none; }");30 31 // Test clone contents32 var cloneOne = CSSModel.cloneCSSObject(sheetOne);33 FBTest.compare("text/css", cloneOne.type, "clone type");34 FBTest.compare(false, cloneOne.disabled, "clone disabled");35 FBTest.compare(undefined, cloneOne.href, "clone href");36 FBTest.compare(0, cloneOne.media && cloneOne.media.length, "clone media");37 FBTest.compare("", cloneOne.title, "clone title");38 FBTest.compare(3, cloneOne.cssRules && cloneOne.cssRules.length, "clone cssRules.length");39 40 var testRule = cloneOne.cssRules[0];41 FBTest.compare(CSSRule.STYLE_RULE, testRule.type, "clone .rule1 type");42 FBTest.compare(".rule1", testRule.selectorText, "clone .rule1 selectorText");43 FBTest.compare(0, testRule.style.length, "clone .rule1 style length");44 45 testRule = cloneOne.cssRules[1];46 FBTest.compare(CSSRule.STYLE_RULE, testRule.type, "clone .rule2 type");47 FBTest.compare(".rule2", testRule.selectorText, "clone .rule2 selectorText");48 FBTest.compare(0, testRule.style.length, "clone .rule2 style length");49 50 testRule = cloneOne.cssRules[2];51 FBTest.compare(CSSRule.STYLE_RULE, testRule.type, "clone .rule3 type");52 FBTest.compare(".rule3", testRule.selectorText, "clone .rule3 selectorText");53 FBTest.compare(1, testRule.style.length, "clone .rule3 style length");54 FBTest.compare("border", testRule.style[0], "clone .rule3 style prop lookup");55 FBTest.compare("medium none", testRule.style.getPropertyValue("border"), "clone .rule3 style prop value");56 FBTest.compare("", testRule.style.getPropertyPriority("border"), "clone .rule3 style prop priority");57 58 var link1 = doc.styleSheets[2], link2 = doc.styleSheets[doc.styleSheets.length - 2];59 cloneOne = CSSModel.cloneCSSObject(link1);60 // This is lazy, but firefox 3.0 doesn't match the expected behavior, so we'll ignore61 if (!FBTestFireDiff.isFirefox30()) {62 testRule = cloneOne.cssRules[2];63 FBTest.compare(true, testRule.equals(testRule), "clone media equal");64 FBTest.compare(CSSRule.MEDIA_RULE, testRule.type, "clone media type");65 FBTest.compare(2, testRule.media && testRule.media.length, "clone media lenth");66 FBTest.compare("tv", testRule.media[0], "clone media value");67 FBTest.compare("print", testRule.media[1], "clone media value");68 FBTest.compare(1, testRule.cssRules && testRule.cssRules.length, "clone media rules length");69 70 testRule = testRule.cssRules[0];71 FBTest.compare(CSSRule.STYLE_RULE, testRule.type, "clone #div2 type");72 FBTest.compare("#div2", testRule.selectorText, "clone #div2 selectorText");73 FBTest.compare(1, testRule.style.length, "clone #div2 style length");74 FBTest.compare("overflow", testRule.style[0], "clone #div2 style prop lookup");75 FBTest.compare("hidden", testRule.style.getPropertyValue("overflow"), "clone #div2 style prop value");76 FBTest.compare("", testRule.style.getPropertyPriority("overflow"), "clone #div2 style prop priority");77 }78 79 cloneOne = CSSModel.cloneCSSObject(link2);80 81 testRule = cloneOne.cssRules[0];82 var importSheet = testRule.styleSheet;83 FBTest.compare(true, testRule.equals(testRule), "clone import equal");84 FBTest.compare(CSSRule.IMPORT_RULE, testRule.type, "clone import type");85 FBTest.compare("import.css", testRule.href, "clone import href");86 FBTest.compare(0, testRule.media && testRule.media.length, "clone import media lenth");87 FBTest.sysout("import " + testRule, testRule);88 FBTest.compare(urlBase + "lib/import.css", testRule.styleSheet && testRule.styleSheet.href, "clone import media sheet href");89 90 // Test CSS equals91 compareCSS(link1, link1, true, "link1 equals link1");92 compareCSS(link2, link2, true, "link2 equals link2");93 compareCSS(importSheet, importSheet, true, "import equals import");94 95 compareCSS(sheetOne, sheetOne, true, "sheetOne equals sheetOne");96 compareCSS(sheetOne, sheetTwo, false, "sheetOne not equals sheetTwo");97 compareCSS(sheetOne, sheetThree, true, "sheetOne equals sheetThree");98 99 compareCSS(sheetTwo, sheetTwo, true, "sheetTwo equals sheetTwo");100 compareCSS(sheetTwo, sheetThree, false, "sheetOne not equals sheetOne");101 // (.rule1, .rule1) equal, styles equal102 compareCSS(sheetOne.cssRules[0], sheetOne.cssRules[0], true, "sheetOne.rule1 equals sheetOne.rule1");103 compareCSS(sheetOne.cssRules[0], sheetTwo.cssRules[0], true, "sheetOne.rule1 equals sheetTwo.rule1");104 compareCSS(sheetOne.cssRules[0], sheetThree.cssRules[0], true, "sheetOne.rule1 equals sheetThree.rule1");105 compareCSS(sheetOne.cssRules[0].style, sheetOne.cssRules[0].style, true, "sheetOne.rule1.style equals sheetOne.rule1.style");106 compareCSS(sheetOne.cssRules[0].style, sheetTwo.cssRules[0].style, true, "sheetOne.rule1.style equals sheetTwo.rule1.style");107 compareCSS(sheetOne.cssRules[0].style, sheetThree.cssRules[0].style, true, "sheetOne.rule1.style equals sheetThree.rule1.style");108 109 // (.rule1, .rule2) not equal, styles equal110 compareCSS(sheetOne.cssRules[0], sheetOne.cssRules[1], false, "sheetOne.rule1 not equals sheetOne.rule2");111 compareCSS(sheetOne.cssRules[0], sheetThree.cssRules[1], false, "sheetOne.rule1 not equals sheetThree.rule2");112 compareCSS(sheetOne.cssRules[0].style, sheetOne.cssRules[1].style, true, "sheetOne.rule1.style equals sheetOne.rule2.style");113 compareCSS(sheetOne.cssRules[0].style, sheetThree.cssRules[1].style, true, "sheetOne.rule1.style equals sheetThree.rule2.style");114 115 // (.rule1, .rule3) not equal, styles not equal116 compareCSS(sheetOne.cssRules[0], sheetOne.cssRules[2], false, "sheetOne.rule1 not equals sheetOne.rule3");117 compareCSS(sheetOne.cssRules[0], sheetThree.cssRules[2], false, "sheetOne.rule1 not equals sheetThree.rule3");118 compareCSS(sheetOne.cssRules[0].style, sheetOne.cssRules[2].style, false, "sheetOne.rule1.style not equals sheetOne.rule3.style");119 compareCSS(sheetOne.cssRules[0].style, sheetThree.cssRules[2].style, false, "sheetOne.rule1.style not equals sheetThree.rule3.style");120 121 // Test Apply + Revert on the clone + equality122 var cloneOne = CSSModel.cloneCSSObject(sheetOne.cssRules[0].style);123 // Yes cheating here. FF converts 'none' -> 'medium none' behind the scenes124 // meaning we can't have a true one to one mapping, but it should be close125 // enough as we are recording input from the developer who in theory knows 126 // what's going on and FF should apply the same transformations on application127 cloneOne.setProperty("border", "medium none");128 FBTest.compare(true, cloneOne.equals(CSSModel.cloneCSSObject(sheetThree.cssRules[2].style)), "Compare add property");129 cloneOne = CSSModel.cloneCSSObject(sheetOne.cssRules[2].style);130 cloneOne.removeProperty("border");131 FBTest.compare(true, cloneOne.equals(CSSModel.cloneCSSObject(sheetThree.cssRules[0].style)), "Compare remove property");132 133 // Test clone of a changed style declaration134 cloneOne = CSSModel.cloneCSSObject(sheetOne.cssRules[0].style);135 cloneOne.setProperty("border", "medium none");136 FBTest.compare(true, cloneOne.equals(CSSModel.cloneCSSObject(cloneOne)), "Compare change style clone");137 138 // Test stylesheet deleteRule139 cloneOne = CSSModel.cloneCSSObject(sheetOne);140 cloneOne.deleteRule(1);141 cloneOne.deleteRule(1);142 FBTest.compare(true, cloneOne.equals(CSSModel.cloneCSSObject(sheetTwo)), "Compare deleteRule clone");143 144 // Test stylesheet insertRule145 cloneOne = CSSModel.cloneCSSObject(sheetTwo);146 cloneOne.insertRule(CSSModel.cloneCSSObject(sheetOne.cssRules[1]), 1);147 cloneOne.insertRule(CSSModel.cloneCSSObject(sheetOne.cssRules[2]), 2);148 FBTest.compare(true, cloneOne.equals(CSSModel.cloneCSSObject(sheetOne)), "Compare insertRule clone");149 150 FBTestFirebug.testDone();151 });...
clone.js
Source:clone.js
...117 /**118 * Clone fields119 * @param $container A div container which has all fields120 */121 function clone( $container ) {122 var $last = $container.children( '.rwmb-clone' ).last(),123 $clone = $last.clone(),124 inputSelectors = 'input[class*="rwmb"], textarea[class*="rwmb"], select[class*="rwmb"], button[class*="rwmb"]',125 $inputs = $clone.find( inputSelectors ),126 nextIndex = cloneIndex.nextIndex( $container );127 // Reset value for fields128 $inputs.each( cloneValue.reset );129 // Insert Clone130 $clone.insertAfter( $last );131 // Trigger custom event for the clone instance. Required for Group extension to update sub fields.132 $clone.trigger( 'clone_instance', nextIndex );133 // Set fields index. Must run before trigger clone event.134 cloneIndex.set( $inputs, nextIndex );135 // Trigger custom clone event136 $inputs.trigger( 'clone', nextIndex );137 }138 /**139 * Hide remove buttons when there's only 1 of them140 *141 * @param $container .rwmb-input container142 */143 function toggleRemoveButtons( $container ) {144 var $clones = $container.children( '.rwmb-clone' );145 $clones.children( '.remove-clone' ).toggle( $clones.length > 1 );146 // Recursive for nested groups.147 $container.find( '.rwmb-input' ).each( function () {148 toggleRemoveButtons( $( this ) );149 } );150 }151 /**152 * Toggle add button153 * Used with [data-max-clone] attribute. When max clone is reached, the add button is hid and vice versa154 *155 * @param $container .rwmb-input container156 */157 function toggleAddButton( $container ) {158 var $button = $container.find( '.add-clone' ),159 maxClone = parseInt( $container.data( 'max-clone' ) ),160 numClone = $container.find( '.rwmb-clone' ).length;161 $button.toggle( isNaN( maxClone ) || ( maxClone && numClone < maxClone ) );162 }163 $( document )164 // Add clones165 .on( 'click', '.add-clone', function ( e ) {166 e.preventDefault();167 var $container = $( this ).closest( '.rwmb-input' );168 clone( $container );169 toggleRemoveButtons( $container );170 toggleAddButton( $container );171 } )172 // Remove clones173 .on( 'click', '.remove-clone', function ( e ) {174 e.preventDefault();175 var $this = $( this ),176 $container = $this.closest( '.rwmb-input' );177 // Remove clone only if there are 2 or more of them178 if ( $container.children( '.rwmb-clone' ).length < 2 ) {179 return;180 }181 $this.parent().trigger( 'remove' ).remove();182 toggleRemoveButtons( $container );...
clone.py
Source:clone.py
1from django.contrib import messages2from django.utils.html import mark_safe3from gen.utils.todo import create_bug_issue4class CloneObjectMixin:5 action_name = 'clone_object'6 short_description = 'ÐлониÑоваÑÑ'7 prefix_clone = '_CLONE'8 def __init__(self, clone=None):9 self.clone = clone10 @classmethod11 def clone_success(cls, request, obj):12 title = 'ÐбÑÐµÐºÑ ÐºÐ»Ð¾Ð½Ð¸Ñован! <b>{}</b>'.format(obj)13 messages.success(request, mark_safe(title))14 @classmethod15 def clone_error(cls, request, obj):16 title = 'Сбой клониÑованиÑ! <b>{}</b>'.format(obj)17 messages.warning(request, mark_safe(title))18 create_bug_issue(title)19 @classmethod20 def is_valid(cls, obj):21 return (22 hasattr(obj, 'title') or hasattr(obj, 'image_title') or hasattr(obj, 'email') or hasattr(obj, 'name')23 )24 def clone_queryset(self, request, queryset):25 [self._clone_object(request, obj) for obj in queryset]26 def clone_format(self, value):27 return '{}{}'.format(value, self.prefix_clone) if value else self.prefix_clone28 def _clone_object(self, request, obj):29 if self.is_valid(obj):30 clone = self._prepare(obj)31 clone.save()32 self.clone_success(request, obj)33 else:34 self.clone_error(request, obj)35 def _prepare(self, obj):36 clone = obj37 clone.id = None38 self._set_clone_model_seo_page(clone)39 self._set_clone_model_image(clone)40 self._set_clone_model_user(clone)41 self._set_clone_product_item(clone)42 return self.clone43 def _set_clone_model_seo_page(self, clone):44 if hasattr(clone, 'title') and hasattr(clone, 'slug'):45 clone.title = self.clone_format(clone.title)46 clone.description = self.clone_format(clone.description)47 clone.slug = self.clone_format(clone.slug)48 clone.seo_title = self.clone_format(clone.seo_title)49 clone.seo_description = self.clone_format(clone.seo_description)50 clone.seo_keywords = self.clone_format(clone.seo_keywords)51 clone.sort = -152 self.clone = clone53 def _set_clone_model_image(self, clone):54 if hasattr(clone, 'image_title') and not hasattr(clone, 'slug'):55 clone.image_title = self.clone_format(clone.image_title)56 clone.image_description = self.clone_format(clone.image_description)57 self.clone = clone58 def _set_clone_model_user(self, clone):59 if hasattr(clone, 'email'):60 clone.email = self.clone_format(clone.email)61 clone.username = self.clone_format(clone.username)62 clone.first_name = self.clone_format(clone.first_name)63 clone.last_name = self.clone_format(clone.last_name)64 clone.is_superuser = clone.is_active = False65 self.clone = clone66 def _set_clone_product_item(self, clone):67 if hasattr(clone, 'name'):68 clone.name = self.clone_format(clone.name)69 self.clone = clone70 def _set_clone_default(self, clone):71 if hasattr(clone, 'title') and not hasattr(clone, 'slug'):72 clone.title = self.clone_format(clone.title)73 if hasattr(clone, 'sort'):74 clone.sort = -1...
Using AI Code Generation
1var clone = require('clone');2var obj = {3 c: {4 }5};6var clonedObj = clone(obj);7clonedObj.a = 5;8clonedObj.c.d = 6;9var clone = require('clone');10var obj = {11 c: {12 }13};14var clonedObj = clone(obj);15clonedObj.a = 5;16clonedObj.c.d = 6;17var clone = require('clone');18var obj = {19 c: {20 }21};22var clonedObj = clone(obj);23clonedObj.a = 5;24clonedObj.c.d = 6;25var clone = require('clone');26var obj = {27 c: {28 }29};30var clonedObj = clone(obj);31clonedObj.a = 5;32clonedObj.c.d = 6;33var clone = require('clone
Using AI Code Generation
1const chain = require('./chain.js');2const chain1 = new chain();3chain1.addBlock('block1');4chain1.addBlock('block2');5chain1.addBlock('block3');6chain1.addBlock('block4');7chain1.addBlock('block5');8chain1.addBlock('block6');9chain1.addBlock('block7');10chain1.addBlock('block8');11chain1.addBlock('block9');12chain1.addBlock('block10');13chain1.addBlock('block11');14chain1.addBlock('block12');15chain1.addBlock('block13');16chain1.addBlock('block14');17chain1.addBlock('block15');18chain1.addBlock('block16');19chain1.addBlock('block17');20chain1.addBlock('block18');21chain1.addBlock('block19');22chain1.addBlock('block20');23chain1.addBlock('block21');24chain1.addBlock('block22');25chain1.addBlock('block23');26chain1.addBlock('block24');27chain1.addBlock('block25');28chain1.addBlock('block26');29chain1.addBlock('block27');30chain1.addBlock('block28');31chain1.addBlock('block29');32chain1.addBlock('block30');33chain1.addBlock('block31');34chain1.addBlock('block32');35chain1.addBlock('block33');36chain1.addBlock('block34');37chain1.addBlock('block35');38chain1.addBlock('block36');39chain1.addBlock('block37');40chain1.addBlock('block38');41chain1.addBlock('block39');42chain1.addBlock('block40');43chain1.addBlock('block41');44chain1.addBlock('block42');45chain1.addBlock('block43');46chain1.addBlock('block44');47chain1.addBlock('block45');48chain1.addBlock('block46');49chain1.addBlock('block47');50chain1.addBlock('block48');51chain1.addBlock('block49');52chain1.addBlock('block50');53chain1.addBlock('block51');54chain1.addBlock('block52');55chain1.addBlock('block53');56chain1.addBlock('block54');57chain1.addBlock('block55');58chain1.addBlock('block56');59chain1.addBlock('block57');60chain1.addBlock('block58');61chain1.addBlock('block59');62chain1.addBlock('block60');
Using AI Code Generation
1const { Chain } = require('./chain');2const chain = new Chain();3 .addBlock('Block 1')4 .addBlock('Block 2')5 .addBlock('Block 3')6 .addBlock('Block 4')7 .addBlock('Block 5');8const clonedChain = chain.clone();9clonedChain.addBlock('Block 6');10console.log('Original Chain', chain);11console.log('Cloned Chain', clonedChain);
Using AI Code Generation
1const _ = require('lodash');2const arr = [1, 2, 3, 4, 5, 6];3const cloneArr = _.chain(arr)4 .clone()5 .push(7)6 .push(8)7 .value();8console.log(cloneArr);9const _ = require('lodash');10const obj = { a: 1, b: 2, c: 3, d: { e: 4, f: 5 } };11const cloneObj = _.chain(obj)12 .cloneDeep()13 .set('a', 2)14 .set('d.e', 5)15 .value();16console.log(cloneObj);17const _ = require('lodash');18const arr = [0, 1, false, 2, '', 3];19const compactArr = _.chain(arr)20 .compact()21 .value();22console.log(compactArr);23const _ = require('lodash');24const arr = [1];25const concatArr = _.chain(arr)26 .concat(2, [3], [[4]])27 .value();28console.log(concatArr);29const _ = require('lodash');30const arr = [2, 1];31const differenceArr = _.chain(arr)32 .difference([2, 3])33 .value();34console.log(differenceArr);35const _ = require('lodash');36const arr = [2.1, 1.2];37const differenceByArr = _.chain(arr)38 .differenceBy([2
Using AI Code Generation
1var chain = require('./chain.js');2var chain1 = chain.chain();3chain1.addBlock(new chain.block(1, "10/07/2017", { amount: 4 }));4chain1.addBlock(new chain.block(2, "12/07/2017", { amount: 10 }));5chain1.addBlock(new chain.block(3, "13/07/2017", { amount: 20 }));6chain1.addBlock(new chain.block(4, "14/07/2017", { amount: 30 }));7var chain2 = chain1.clone();8chain2.chain[2].data = { amount: 40 };9chain1.chain[3].data = { amount: 50 };10console.log("chain1");11chain1.print();12console.log("chain2");13chain2.print();
Using AI Code Generation
1const { Chain } = require("blockchain");2const chain = new Chain();3chain.addBlock({ data: "Initial" });4console.log("first chain", chain.chain);5const clonedChain = chain.clone();6console.log("cloned chain", clonedChain.chain);7clonedChain.addBlock({ data: "second" });8clonedChain.addBlock({ data: "third" });9console.log("cloned chain", clonedChain.chain);10console.log("first chain", chain.chain);
Using AI Code Generation
1const {expect,assert,should} = require('chai');2const {clone} = require('lodash');3describe('clone', () => {4 it('should return a new object', () => {5 const obj = {a: 1};6 const actual = clone(obj);7 expect(actual).to.not.equal(obj);8 });9 it('should return an object with the same properties', () => {10 const obj = {a: 1};11 const actual = clone(obj);12 expect(actual).to.eql(obj);13 });14 it('should return an object with the same properties and methods', () => {15 const obj = {a: 1, b: () => {}};16 const actual = clone(obj);17 expect(actual).to.eql(obj);18 });19 it('should return an object with the same properties and methods', () => {20 const obj = {a: 1, b: () => {}};21 const actual = clone(obj);22 expect(actual).to.eql(obj);23 });24 it('should return an object with the same properties and methods', () => {25 const obj = {a: 1, b: () => {}};26 const actual = clone(obj);27 expect(actual).to.eql(obj);28 });29 it('should return an object with the same properties and methods', () => {30 const obj = {a: 1, b: () => {}};31 const actual = clone(obj);32 expect(actual).to.eql(obj);33 });34 it('should return an object with the same properties and methods', () => {35 const obj = {a: 1, b: () => {}};36 const actual = clone(obj);37 expect(actual).to.eql(obj);38 });39 it('should return an object with the same properties and methods', () => {40 const obj = {a: 1, b: () => {}};41 const actual = clone(obj);42 expect(actual).to.eql(obj);43 });44 it('should return an object with the same properties and methods', () => {45 const obj = {a: 1, b: () => {}};46 const actual = clone(obj);47 expect(actual).to.eql(obj);48 });49 it('should return an object with the same properties and methods', () => {50 const obj = {a: 1, b: () => {}};
Using AI Code Generation
1var chain = require('./chain.js');2var obj = {a: 1, b: 2};3var obj1 = chain(obj).clone();4obj1.a = 3;5console.log(obj);6console.log(obj1);7var chain = require('./chain.js');8var obj = {a: 1, b: 2, c: {d: 3}};9var obj1 = chain(obj).cloneDeep();10obj1.c.d = 4;11console.log(obj);12console.log(obj1);13var chain = require('./chain.js');14var arr = [1, 2];15var arr1 = chain(arr).concat(3, 4).value();16console.log(arr);17console.log(arr1);18var chain = require('./chain.js');19var arr = [1, 2, 3, 4, 5, 6];20var arr1 = chain(arr).countBy(function(num) {21 return num % 2 == 0 ? 'even': 'odd';22}).value();23console.log(arr1);24var chain = require('./chain.js');25var arr = [1, 2, 3, 4, 5, 6];26var arr1 = chain(arr).create(function(num) {27 return num % 2 == 0 ? 'even': 'odd';28}).value();29console.log(arr1);30var chain = require('./chain.js');
Using AI Code Generation
1const _ = require('lodash');2const obj = {3 address: {4 }5};6const newObj = _.clone(obj);7newObj.address.city = 'Miami';8console.log(obj);9console.log(newObj);10const _ = require('lodash');11const obj = {12 address: {13 }14};15const newObj = _.cloneDeep(obj);16newObj.address.city = 'Miami';17console.log(obj);18console.log(newObj);19const _ = require('lodash');20const obj = {21 address: {22 }23};24const newObj = _.cloneDeepWith(obj, (value) => {25 if (_.isDate(value)) {26 return value.toISOString();27 }28});29newObj.address.city = 'Miami';30console.log(obj);31console.log(newObj);32const _ = require('lodash');33const obj = {34 address: {
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!