How to use wrapper method in storybook-root

Best JavaScript code snippet using storybook-root

menuInteraction.js

Source:menuInteraction.js Github

copy

Full Screen

1var setupMenuEvents = function() {2 var getEquation = function() {3 var equation = null;4 if ($('.cursor').length > 0) {5 equation = $('.cursor').parent().data('eqObject').equation;6 } else if ($('.highlight').length > 0) {7 equation = $('.highlight').parent().data('eqObject').equation;8 }9 return equation;10 };11 $(document).on('touchstart mousedown', '#stackedFractionButton', function (e) {12 e.preventDefault();13 e.stopPropagation();14 var equation = getEquation();15 var stackedFractionWrapper = new eqEd.StackedFractionWrapper(equation);16 insertWrapper(stackedFractionWrapper);17 });18 $(document).on('touchstart mousedown', '#superscriptButton', function (e) {19 e.preventDefault();20 e.stopPropagation();21 var equation = getEquation();22 var superscriptWrapper = new eqEd.SuperscriptWrapper(equation);23 insertWrapper(superscriptWrapper);24 });25 $(document).on('touchstart mousedown', '#subscriptButton', function (e) {26 e.preventDefault();27 e.stopPropagation();28 var equation = getEquation();29 var subscriptWrapper = new eqEd.SubscriptWrapper(equation);30 insertWrapper(subscriptWrapper);31 });32 $(document).on('touchstart mousedown', '#superscriptAndSubscriptButton', function (e) {33 e.preventDefault();34 e.stopPropagation();35 var equation = getEquation();36 var superscriptAndSubscriptWrapper = new eqEd.SuperscriptAndSubscriptWrapper(equation);37 insertWrapper(superscriptAndSubscriptWrapper);38 });39 $(document).on('touchstart mousedown', '#squareRootButton', function (e) {40 e.preventDefault();41 e.stopPropagation();42 var equation = getEquation();43 var squareRootWrapper = new eqEd.SquareRootWrapper(equation);44 insertWrapper(squareRootWrapper);45 });46 $(document).on('touchstart mousedown', '#nthRootButton', function (e) {47 e.preventDefault();48 e.stopPropagation();49 var equation = getEquation();50 var nthRootButton = new eqEd.NthRootWrapper(equation);51 insertWrapper(nthRootButton);52 });53 54 $(document).on('touchstart mousedown', '#leftAngleBracketButton', function (e) {55 e.preventDefault();56 e.stopPropagation();57 var equation = getEquation();58 var leftAngleBracketWrapper = new eqEd.BracketWrapper(equation, "leftAngleBracket");59 insertWrapper(leftAngleBracketWrapper);60 });61 $(document).on('touchstart mousedown', '#rightAngleBracketButton', function (e) {62 e.preventDefault();63 e.stopPropagation();64 var equation = getEquation();65 var rightAngleBracketWrapper = new eqEd.BracketWrapper(equation, "rightAngleBracket");66 insertWrapper(rightAngleBracketWrapper);67 });68 $(document).on('touchstart mousedown', '#leftFloorBracketButton', function (e) {69 e.preventDefault();70 e.stopPropagation();71 var equation = getEquation();72 var leftFloorBracketWrapper = new eqEd.BracketWrapper(equation, "leftFloorBracket");73 insertWrapper(leftFloorBracketWrapper);74 });75 $(document).on('touchstart mousedown', '#rightFloorBracketButton', function (e) {76 e.preventDefault();77 e.stopPropagation();78 var equation = getEquation();79 var rightFloorBracketWrapper = new eqEd.BracketWrapper(equation, "rightFloorBracket");80 insertWrapper(rightFloorBracketWrapper);81 });82 $(document).on('touchstart mousedown', '#leftCeilBracketButton', function (e) {83 e.preventDefault();84 e.stopPropagation();85 var equation = getEquation();86 var leftCeilBracketWrapper = new eqEd.BracketWrapper(equation, "leftCeilBracket");87 insertWrapper(leftCeilBracketWrapper);88 });89 $(document).on('touchstart mousedown', '#rightCeilBracketButton', function (e) {90 e.preventDefault();91 e.stopPropagation();92 var equation = getEquation();93 var rightCeilBracketWrapper = new eqEd.BracketWrapper(equation, "rightCeilBracket");94 insertWrapper(rightCeilBracketWrapper);95 });96 $(document).on('touchstart mousedown', '#parenthesesBracketPairButton', function (e) {97 e.preventDefault();98 e.stopPropagation();99 var equation = getEquation();100 var parenthesesBracketPair = new eqEd.BracketPairWrapper(equation, "parenthesisBracket");101 insertWrapper(parenthesesBracketPair);102 });103 $(document).on('touchstart mousedown', '#squareBracketPairButton', function (e) {104 e.preventDefault();105 e.stopPropagation();106 var equation = getEquation();107 var squareBracketPair = new eqEd.BracketPairWrapper(equation, "squareBracket");108 insertWrapper(squareBracketPair);109 });110 $(document).on('touchstart mousedown', '#curlyBracketPairButton', function (e) {111 e.preventDefault();112 e.stopPropagation();113 var equation = getEquation();114 var curlyBracketPair = new eqEd.BracketPairWrapper(equation, "curlyBracket");115 insertWrapper(curlyBracketPair);116 });117 $(document).on('touchstart mousedown', '#angleBracketPairButton', function (e) {118 e.preventDefault();119 e.stopPropagation();120 var equation = getEquation();121 var angleBracketPair = new eqEd.BracketPairWrapper(equation, "angleBracket");122 insertWrapper(angleBracketPair);123 });$(document).on('touchstart mousedown', '#floorBracketPairButton', function (e) {124 e.preventDefault();125 e.stopPropagation();126 var equation = getEquation();127 var floorBracketPair = new eqEd.BracketPairWrapper(equation, "floorBracket");128 insertWrapper(floorBracketPair);129 });130 $(document).on('touchstart mousedown', '#ceilBracketPairButton', function (e) {131 e.preventDefault();132 e.stopPropagation();133 var equation = getEquation();134 var ceilBracketPair = new eqEd.BracketPairWrapper(equation, "ceilBracket");135 insertWrapper(ceilBracketPair);136 });137 $(document).on('touchstart mousedown', '#absValBracketPairButton', function (e) {138 e.preventDefault();139 e.stopPropagation();140 var equation = getEquation();141 var absValBracketPair = new eqEd.BracketPairWrapper(equation, "absValBracket");142 insertWrapper(absValBracketPair);143 });144 $(document).on('touchstart mousedown', '#normBracketPairButton', function (e) {145 e.preventDefault();146 e.stopPropagation();147 var equation = getEquation();148 var normBracketPair = new eqEd.BracketPairWrapper(equation, "normBracket");149 insertWrapper(normBracketPair);150 });151 $(document).on('touchstart mousedown', '#sumBigOperatorButton', function (e) {152 e.preventDefault();153 e.stopPropagation();154 var equation = getEquation();155 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, true, true, 'sum');156 insertWrapper(bigOperator);157 });158 $(document).on('touchstart mousedown', '#sumBigOperatorNoUpperButton', function (e) {159 e.preventDefault();160 e.stopPropagation();161 var equation = getEquation();162 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, true, 'sum');163 insertWrapper(bigOperator);164 });165 $(document).on('touchstart mousedown', '#sumBigOperatorNoUpperNoLowerButton', function (e) {166 e.preventDefault();167 e.stopPropagation();168 var equation = getEquation();169 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, false, 'sum');170 insertWrapper(bigOperator);171 });172 $(document).on('touchstart mousedown', '#bigCapBigOperatorButton', function (e) {173 e.preventDefault();174 e.stopPropagation();175 var equation = getEquation();176 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, true, true, 'bigCap');177 insertWrapper(bigOperator);178 });179 $(document).on('touchstart mousedown', '#bigCapBigOperatorNoUpperButton', function (e) {180 e.preventDefault();181 e.stopPropagation();182 var equation = getEquation();183 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, true, 'bigCap');184 insertWrapper(bigOperator);185 });186 $(document).on('touchstart mousedown', '#bigCapBigOperatorNoUpperNoLowerButton', function (e) {187 e.preventDefault();188 e.stopPropagation();189 var equation = getEquation();190 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, false, 'bigCap');191 insertWrapper(bigOperator);192 });193 $(document).on('touchstart mousedown', '#bigCupBigOperatorButton', function (e) {194 e.preventDefault();195 e.stopPropagation();196 var equation = getEquation();197 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, true, true, 'bigCup');198 insertWrapper(bigOperator);199 });200 $(document).on('touchstart mousedown', '#bigCupBigOperatorNoUpperButton', function (e) {201 e.preventDefault();202 e.stopPropagation();203 var equation = getEquation();204 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, true, 'bigCup');205 insertWrapper(bigOperator);206 });207 $(document).on('touchstart mousedown', '#bigCupBigOperatorNoUpperNoLowerButton', function (e) {208 e.preventDefault();209 e.stopPropagation();210 var equation = getEquation();211 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, false, 'bigCup');212 insertWrapper(bigOperator);213 });214 $(document).on('touchstart mousedown', '#bigSqCapBigOperatorButton', function (e) {215 e.preventDefault();216 e.stopPropagation();217 var equation = getEquation();218 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, true, true, 'bigSqCap');219 insertWrapper(bigOperator);220 });221 $(document).on('touchstart mousedown', '#bigSqCapBigOperatorNoUpperButton', function (e) {222 e.preventDefault();223 e.stopPropagation();224 var equation = getEquation();225 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, true, 'bigSqCap');226 insertWrapper(bigOperator);227 });228 $(document).on('touchstart mousedown', '#bigSqCapBigOperatorNoUpperNoLowerButton', function (e) {229 e.preventDefault();230 e.stopPropagation();231 var equation = getEquation();232 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, false, 'bigSqCap');233 insertWrapper(bigOperator);234 });235 $(document).on('touchstart mousedown', '#bigSqCupBigOperatorButton', function (e) {236 e.preventDefault();237 e.stopPropagation();238 var equation = getEquation();239 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, true, true, 'bigSqCup');240 insertWrapper(bigOperator);241 });242 $(document).on('touchstart mousedown', '#bigSqCupBigOperatorNoUpperButton', function (e) {243 e.preventDefault();244 e.stopPropagation();245 var equation = getEquation();246 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, true, 'bigSqCup');247 insertWrapper(bigOperator);248 });249 $(document).on('touchstart mousedown', '#bigSqCupBigOperatorNoUpperNoLowerButton', function (e) {250 e.preventDefault();251 e.stopPropagation();252 var equation = getEquation();253 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, false, 'bigSqCup');254 insertWrapper(bigOperator);255 });256 $(document).on('touchstart mousedown', '#prodBigOperatorButton', function (e) {257 e.preventDefault();258 e.stopPropagation();259 var equation = getEquation();260 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, true, true, 'prod');261 insertWrapper(bigOperator);262 });263 $(document).on('touchstart mousedown', '#prodBigOperatorNoUpperButton', function (e) {264 e.preventDefault();265 e.stopPropagation();266 var equation = getEquation();267 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, true, 'prod');268 insertWrapper(bigOperator);269 });270 $(document).on('touchstart mousedown', '#prodBigOperatorNoUpperNoLowerButton', function (e) {271 e.preventDefault();272 e.stopPropagation();273 var equation = getEquation();274 var equation = getEquation();275 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, false, 'prod');276 insertWrapper(bigOperator);277 });278 $(document).on('touchstart mousedown', '#coProdBigOperatorButton', function (e) {279 e.preventDefault();280 e.stopPropagation();281 var equation = getEquation();282 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, true, true, 'coProd');283 insertWrapper(bigOperator);284 });285 $(document).on('touchstart mousedown', '#coProdBigOperatorNoUpperButton', function (e) {286 e.preventDefault();287 e.stopPropagation();288 var equation = getEquation();289 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, true, 'coProd');290 insertWrapper(bigOperator);291 });292 $(document).on('touchstart mousedown', '#coProdBigOperatorNoUpperNoLowerButton', function (e) {293 e.preventDefault();294 e.stopPropagation();295 var equation = getEquation();296 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, false, 'coProd');297 insertWrapper(bigOperator);298 });299 $(document).on('touchstart mousedown', '#bigVeeBigOperatorButton', function (e) {300 e.preventDefault();301 e.stopPropagation();302 var equation = getEquation();303 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, true, true, 'bigVee');304 insertWrapper(bigOperator);305 });306 $(document).on('touchstart mousedown', '#bigVeeBigOperatorNoUpperButton', function (e) {307 e.preventDefault();308 e.stopPropagation();309 var equation = getEquation();310 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, true, 'bigVee');311 insertWrapper(bigOperator);312 });313 $(document).on('touchstart mousedown', '#bigVeeBigOperatorNoUpperNoLowerButton', function (e) {314 e.preventDefault();315 e.stopPropagation();316 var equation = getEquation();317 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, false, 'bigVee');318 insertWrapper(bigOperator);319 });320 $(document).on('touchstart mousedown', '#bigWedgeBigOperatorButton', function (e) {321 e.preventDefault();322 e.stopPropagation();323 var equation = getEquation();324 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, true, true, 'bigWedge');325 insertWrapper(bigOperator);326 });327 $(document).on('touchstart mousedown', '#bigWedgeBigOperatorNoUpperButton', function (e) {328 e.preventDefault();329 e.stopPropagation();330 var equation = getEquation();331 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, true, 'bigWedge');332 insertWrapper(bigOperator);333 });334 $(document).on('touchstart mousedown', '#bigWedgeBigOperatorNoUpperNoLowerButton', function (e) {335 e.preventDefault();336 e.stopPropagation();337 var equation = getEquation();338 var bigOperator = new eqEd.BigOperatorWrapper(equation, false, false, false, 'bigWedge');339 insertWrapper(bigOperator);340 });341 $(document).on('touchstart mousedown', '#inlineSumBigOperatorButton', function (e) {342 e.preventDefault();343 e.stopPropagation();344 var equation = getEquation();345 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, true, true, 'sum');346 insertWrapper(bigOperator);347 });348 $(document).on('touchstart mousedown', '#inlineSumBigOperatorNoUpperButton', function (e) {349 e.preventDefault();350 e.stopPropagation();351 var equation = getEquation();352 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, false, true, 'sum');353 insertWrapper(bigOperator);354 });355 $(document).on('touchstart mousedown', '#inlineBigCapBigOperatorButton', function (e) {356 e.preventDefault();357 e.stopPropagation();358 var equation = getEquation();359 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, true, true, 'bigCap');360 insertWrapper(bigOperator);361 });362 $(document).on('touchstart mousedown', '#inlineBigCapBigOperatorNoUpperButton', function (e) {363 e.preventDefault();364 e.stopPropagation();365 var equation = getEquation();366 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, false, true, 'bigCap');367 insertWrapper(bigOperator);368 });369 $(document).on('touchstart mousedown', '#inlineBigCupBigOperatorButton', function (e) {370 e.preventDefault();371 e.stopPropagation();372 var equation = getEquation();373 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, true, true, 'bigCup');374 insertWrapper(bigOperator);375 });376 $(document).on('touchstart mousedown', '#inlineBigCupBigOperatorNoUpperButton', function (e) {377 e.preventDefault();378 e.stopPropagation();379 var equation = getEquation();380 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, false, true, 'bigCup');381 insertWrapper(bigOperator);382 });383 $(document).on('touchstart mousedown', '#inlineBigSqCapBigOperatorButton', function (e) {384 e.preventDefault();385 e.stopPropagation();386 var equation = getEquation();387 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, true, true, 'bigSqCap');388 insertWrapper(bigOperator);389 });390 $(document).on('touchstart mousedown', '#inlineBigSqCapBigOperatorNoUpperButton', function (e) {391 e.preventDefault();392 e.stopPropagation();393 var equation = getEquation();394 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, false, true, 'bigSqCap');395 insertWrapper(bigOperator);396 });397 $(document).on('touchstart mousedown', '#inlineBigSqCupBigOperatorButton', function (e) {398 e.preventDefault();399 e.stopPropagation();400 var equation = getEquation();401 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, true, true, 'bigSqCup');402 insertWrapper(bigOperator);403 });404 $(document).on('touchstart mousedown', '#inlineBigSqCupBigOperatorNoUpperButton', function (e) {405 e.preventDefault();406 e.stopPropagation();407 var equation = getEquation();408 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, false, true, 'bigSqCup');409 insertWrapper(bigOperator);410 });411 $(document).on('touchstart mousedown', '#inlineProdBigOperatorButton', function (e) {412 e.preventDefault();413 e.stopPropagation();414 var equation = getEquation();415 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, true, true, 'prod');416 insertWrapper(bigOperator);417 });418 $(document).on('touchstart mousedown', '#inlineProdBigOperatorNoUpperButton', function (e) {419 e.preventDefault();420 e.stopPropagation();421 var equation = getEquation();422 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, false, true, 'prod');423 insertWrapper(bigOperator);424 });425 $(document).on('touchstart mousedown', '#inlineCoProdBigOperatorButton', function (e) {426 e.preventDefault();427 e.stopPropagation();428 var equation = getEquation();429 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, true, true, 'coProd');430 insertWrapper(bigOperator);431 });432 $(document).on('touchstart mousedown', '#inlineCoProdBigOperatorNoUpperButton', function (e) {433 e.preventDefault();434 e.stopPropagation();435 var equation = getEquation();436 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, false, true, 'coProd');437 insertWrapper(bigOperator);438 });439 $(document).on('touchstart mousedown', '#inlineBigVeeBigOperatorButton', function (e) {440 e.preventDefault();441 e.stopPropagation();442 var equation = getEquation();443 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, true, true, 'bigVee');444 insertWrapper(bigOperator);445 });446 $(document).on('touchstart mousedown', '#inlineBigVeeBigOperatorNoUpperButton', function (e) {447 e.preventDefault();448 e.stopPropagation();449 var equation = getEquation();450 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, false, true, 'bigVee');451 insertWrapper(bigOperator);452 });453 $(document).on('touchstart mousedown', '#inlineBigWedgeBigOperatorButton', function (e) {454 e.preventDefault();455 e.stopPropagation();456 var equation = getEquation();457 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, true, true, 'bigWedge');458 insertWrapper(bigOperator);459 });460 $(document).on('touchstart mousedown', '#inlineBigWedgeBigOperatorNoUpperButton', function (e) {461 e.preventDefault();462 e.stopPropagation();463 var equation = getEquation();464 var bigOperator = new eqEd.BigOperatorWrapper(equation, true, false, true, 'bigWedge');465 insertWrapper(bigOperator);466 });467 ////////////////////////////////////////////////////////////////468 $(document).on('touchstart mousedown', '#integralButton', function (e) {469 e.preventDefault();470 e.stopPropagation();471 var equation = getEquation();472 var integralWrapper = new eqEd.IntegralWrapper(equation, false, true, true, 'single');473 insertWrapper(integralWrapper);474 });475 $(document).on('touchstart mousedown', '#integralNoUpperButton', function (e) {476 e.preventDefault();477 e.stopPropagation();478 var equation = getEquation();479 var integralWrapper = new eqEd.IntegralWrapper(equation, false, false, true, 'single');480 insertWrapper(integralWrapper);481 });482 $(document).on('touchstart mousedown', '#integralNoUpperNoLowerButton', function (e) {483 e.preventDefault();484 e.stopPropagation();485 var equation = getEquation();486 var integralWrapper = new eqEd.IntegralWrapper(equation, false, false, false, 'single');487 insertWrapper(integralWrapper);488 });489 $(document).on('touchstart mousedown', '#doubleIntegralButton', function (e) {490 e.preventDefault();491 e.stopPropagation();492 var equation = getEquation();493 var integralWrapper = new eqEd.IntegralWrapper(equation, false, true, true, 'double');494 insertWrapper(integralWrapper);495 });496 $(document).on('touchstart mousedown', '#doubleIntegralNoUpperButton', function (e) {497 e.preventDefault();498 e.stopPropagation();499 var equation = getEquation();500 var integralWrapper = new eqEd.IntegralWrapper(equation, false, false, true, 'double');501 insertWrapper(integralWrapper);502 });503 $(document).on('touchstart mousedown', '#doubleIntegralNoUpperNoLowerButton', function (e) {504 e.preventDefault();505 e.stopPropagation();506 var equation = getEquation();507 var integralWrapper = new eqEd.IntegralWrapper(equation, false, false, false, 'double');508 insertWrapper(integralWrapper);509 });510 $(document).on('touchstart mousedown', '#tripleIntegralButton', function (e) {511 e.preventDefault();512 e.stopPropagation();513 var equation = getEquation();514 var integralWrapper = new eqEd.IntegralWrapper(equation, false, true, true, 'triple');515 insertWrapper(integralWrapper);516 });517 $(document).on('touchstart mousedown', '#tripleIntegralNoUpperButton', function (e) {518 e.preventDefault();519 e.stopPropagation();520 var equation = getEquation();521 var integralWrapper = new eqEd.IntegralWrapper(equation, false, false, true, 'triple');522 insertWrapper(integralWrapper);523 });524 $(document).on('touchstart mousedown', '#tripleIntegralNoUpperNoLowerButton', function (e) {525 e.preventDefault();526 e.stopPropagation();527 var equation = getEquation();528 var integralWrapper = new eqEd.IntegralWrapper(equation, false, false, false, 'triple');529 insertWrapper(integralWrapper);530 });531 $(document).on('touchstart mousedown', '#contourIntegralButton', function (e) {532 e.preventDefault();533 e.stopPropagation();534 var equation = getEquation();535 var integralWrapper = new eqEd.IntegralWrapper(equation, false, true, true, 'singleContour');536 insertWrapper(integralWrapper);537 });538 $(document).on('touchstart mousedown', '#contourIntegralNoUpperButton', function (e) {539 e.preventDefault();540 e.stopPropagation();541 var equation = getEquation();542 var integralWrapper = new eqEd.IntegralWrapper(equation, false, false, true, 'singleContour');543 insertWrapper(integralWrapper);544 });545 $(document).on('touchstart mousedown', '#contourIntegralNoUpperNoLowerButton', function (e) {546 e.preventDefault();547 e.stopPropagation();548 var equation = getEquation();549 var integralWrapper = new eqEd.IntegralWrapper(equation, false, false, false, 'singleContour');550 insertWrapper(integralWrapper);551 });552 $(document).on('touchstart mousedown', '#contourDoubleIntegralButton', function (e) {553 e.preventDefault();554 e.stopPropagation();555 var equation = getEquation();556 var integralWrapper = new eqEd.IntegralWrapper(equation, false, true, true, 'doubleContour');557 insertWrapper(integralWrapper);558 });559 $(document).on('touchstart mousedown', '#contourDoubleIntegralNoUpperButton', function (e) {560 e.preventDefault();561 e.stopPropagation();562 var equation = getEquation();563 var integralWrapper = new eqEd.IntegralWrapper(equation, false, false, true, 'doubleContour');564 insertWrapper(integralWrapper);565 });566 $(document).on('touchstart mousedown', '#contourDoubleIntegralNoUpperNoLowerButton', function (e) {567 e.preventDefault();568 e.stopPropagation();569 var equation = getEquation();570 var integralWrapper = new eqEd.IntegralWrapper(equation, false, false, false, 'doubleContour');571 insertWrapper(integralWrapper);572 });573 $(document).on('touchstart mousedown', '#contourTripleIntegralButton', function (e) {574 e.preventDefault();575 e.stopPropagation();576 var equation = getEquation();577 var integralWrapper = new eqEd.IntegralWrapper(equation, false, true, true, 'tripleContour');578 insertWrapper(integralWrapper);579 });580 $(document).on('touchstart mousedown', '#contourTripleIntegralNoUpperButton', function (e) {581 e.preventDefault();582 e.stopPropagation();583 var equation = getEquation();584 var integralWrapper = new eqEd.IntegralWrapper(equation, false, false, true, 'tripleContour');585 insertWrapper(integralWrapper);586 });587 $(document).on('touchstart mousedown', '#contourTripleIntegralNoUpperNoLowerButton', function (e) {588 e.preventDefault();589 e.stopPropagation();590 var equation = getEquation();591 var integralWrapper = new eqEd.IntegralWrapper(equation, false, false, false, 'tripleContour');592 insertWrapper(integralWrapper);593 });594 $(document).on('touchstart mousedown', '#inlineIntegralButton', function (e) {595 e.preventDefault();596 e.stopPropagation();597 var equation = getEquation();598 var integralWrapper = new eqEd.IntegralWrapper(equation, true, true, true, 'single');599 insertWrapper(integralWrapper);600 });601 $(document).on('touchstart mousedown', '#inlineIntegralNoUpperButton', function (e) {602 e.preventDefault();603 e.stopPropagation();604 var equation = getEquation();605 var integralWrapper = new eqEd.IntegralWrapper(equation, true, false, true, 'single');606 insertWrapper(integralWrapper);607 });608 $(document).on('touchstart mousedown', '#inlineDoubleIntegralButton', function (e) {609 e.preventDefault();610 e.stopPropagation();611 var equation = getEquation();612 var integralWrapper = new eqEd.IntegralWrapper(equation, true, true, true, 'double');613 insertWrapper(integralWrapper);614 });615 $(document).on('touchstart mousedown', '#inlineDoubleIntegralNoUpperButton', function (e) {616 e.preventDefault();617 e.stopPropagation();618 var equation = getEquation();619 var integralWrapper = new eqEd.IntegralWrapper(equation, true, false, true, 'double');620 insertWrapper(integralWrapper);621 });622 $(document).on('touchstart mousedown', '#inlineTripleIntegralButton', function (e) {623 e.preventDefault();624 e.stopPropagation();625 var equation = getEquation();626 var integralWrapper = new eqEd.IntegralWrapper(equation, true, true, true, 'triple');627 insertWrapper(integralWrapper);628 });629 $(document).on('touchstart mousedown', '#inlineTripleIntegralNoUpperButton', function (e) {630 e.preventDefault();631 e.stopPropagation();632 var equation = getEquation();633 var integralWrapper = new eqEd.IntegralWrapper(equation, true, false, true, 'triple');634 insertWrapper(integralWrapper);635 });636 $(document).on('touchstart mousedown', '#inlineContourIntegralButton', function (e) {637 e.preventDefault();638 e.stopPropagation();639 var equation = getEquation();640 var integralWrapper = new eqEd.IntegralWrapper(equation, true, true, true, 'singleContour');641 insertWrapper(integralWrapper);642 });643 $(document).on('touchstart mousedown', '#inlineContourIntegralNoUpperButton', function (e) {644 e.preventDefault();645 e.stopPropagation();646 var equation = getEquation();647 var integralWrapper = new eqEd.IntegralWrapper(equation, true, false, true, 'singleContour');648 insertWrapper(integralWrapper);649 });650 $(document).on('touchstart mousedown', '#inlineContourDoubleIntegralButton', function (e) {651 e.preventDefault();652 e.stopPropagation();653 var equation = getEquation();654 var integralWrapper = new eqEd.IntegralWrapper(equation, true, true, true, 'doubleContour');655 insertWrapper(integralWrapper);656 });657 $(document).on('touchstart mousedown', '#inlineContourDoubleIntegralNoUpperButton', function (e) {658 e.preventDefault();659 e.stopPropagation();660 var equation = getEquation();661 var integralWrapper = new eqEd.IntegralWrapper(equation, true, false, true, 'doubleContour');662 insertWrapper(integralWrapper);663 });664 $(document).on('touchstart mousedown', '#inlineContourTripleIntegralButton', function (e) {665 e.preventDefault();666 e.stopPropagation();667 var equation = getEquation();668 var integralWrapper = new eqEd.IntegralWrapper(equation, true, true, true, 'tripleContour');669 insertWrapper(integralWrapper);670 });671 $(document).on('touchstart mousedown', '#inlineContourTripleIntegralNoUpperButton', function (e) {672 e.preventDefault();673 e.stopPropagation();674 var equation = getEquation();675 var integralWrapper = new eqEd.IntegralWrapper(equation, true, false, true, 'tripleContour');676 insertWrapper(integralWrapper);677 });678 $(document).on('touchstart mousedown', '#partialDifferentialButton', function (e) {679 e.preventDefault();680 e.stopPropagation();681 var equation = getEquation();682 var differentialWrapper = new eqEd.SymbolWrapper(equation, 'Γ’ΒˆΒ‚', "MathJax_Main");683 insertWrapper(differentialWrapper);684 });685 ///////////////////////////////////////////////////////686 $(document).on('touchstart mousedown', '#logButton', function (e) {687 e.preventDefault();688 e.stopPropagation();689 var equation = getEquation();690 var functionWrapper = new eqEd.FunctionWrapper(equation, 'log', "MathJax_Main");691 insertWrapper(functionWrapper);692 });693 $(document).on('touchstart mousedown', '#lnButton', function (e) {694 e.preventDefault();695 e.stopPropagation();696 var equation = getEquation();697 var functionWrapper = new eqEd.FunctionWrapper(equation, 'ln', "MathJax_Main");698 insertWrapper(functionWrapper);699 });700 $(document).on('touchstart mousedown', '#limButton', function (e) {701 e.preventDefault();702 e.stopPropagation();703 var equation = getEquation();704 var functionWrapper = new eqEd.FunctionWrapper(equation, 'lim', "MathJax_Main");705 insertWrapper(functionWrapper);706 });707 $(document).on('touchstart mousedown', '#maxButton', function (e) {708 e.preventDefault();709 e.stopPropagation();710 var equation = getEquation();711 var functionWrapper = new eqEd.FunctionWrapper(equation, 'max', "MathJax_Main");712 insertWrapper(functionWrapper);713 });714 $(document).on('touchstart mousedown', '#minButton', function (e) {715 e.preventDefault();716 e.stopPropagation();717 var equation = getEquation();718 var functionWrapper = new eqEd.FunctionWrapper(equation, 'min', "MathJax_Main");719 insertWrapper(functionWrapper);720 });721 $(document).on('touchstart mousedown', '#supButton', function (e) {722 e.preventDefault();723 e.stopPropagation();724 var equation = getEquation();725 var functionWrapper = new eqEd.FunctionWrapper(equation, 'sup', "MathJax_Main");726 insertWrapper(functionWrapper);727 });728 $(document).on('touchstart mousedown', '#infButton', function (e) {729 e.preventDefault();730 e.stopPropagation();731 var equation = getEquation();732 var functionWrapper = new eqEd.FunctionWrapper(equation, 'inf', "MathJax_Main");733 insertWrapper(functionWrapper);734 });735 $(document).on('touchstart mousedown', '#sinButton', function (e) {736 e.preventDefault();737 e.stopPropagation();738 var equation = getEquation();739 var functionWrapper = new eqEd.FunctionWrapper(equation, 'sin', "MathJax_Main");740 insertWrapper(functionWrapper);741 });742 $(document).on('touchstart mousedown', '#cosButton', function (e) {743 e.preventDefault();744 e.stopPropagation();745 var equation = getEquation();746 var functionWrapper = new eqEd.FunctionWrapper(equation, 'cos', "MathJax_Main");747 insertWrapper(functionWrapper);748 });749 $(document).on('touchstart mousedown', '#tanButton', function (e) {750 e.preventDefault();751 e.stopPropagation();752 var equation = getEquation();753 var functionWrapper = new eqEd.FunctionWrapper(equation, 'tan', "MathJax_Main");754 insertWrapper(functionWrapper);755 });756 $(document).on('touchstart mousedown', '#cotButton', function (e) {757 e.preventDefault();758 e.stopPropagation();759 var equation = getEquation();760 var functionWrapper = new eqEd.FunctionWrapper(equation, 'cot', "MathJax_Main");761 insertWrapper(functionWrapper);762 });763 $(document).on('touchstart mousedown', '#secButton', function (e) {764 e.preventDefault();765 e.stopPropagation();766 var equation = getEquation();767 var functionWrapper = new eqEd.FunctionWrapper(equation, 'sec', "MathJax_Main");768 insertWrapper(functionWrapper);769 });770 $(document).on('touchstart mousedown', '#cscButton', function (e) {771 e.preventDefault();772 e.stopPropagation();773 var equation = getEquation();774 var functionWrapper = new eqEd.FunctionWrapper(equation, 'csc', "MathJax_Main");775 insertWrapper(functionWrapper);776 });777 $(document).on('touchstart mousedown', '#sinhButton', function (e) {778 e.preventDefault();779 e.stopPropagation();780 var equation = getEquation();781 var functionWrapper = new eqEd.FunctionWrapper(equation, 'sinh', "MathJax_Main");782 insertWrapper(functionWrapper);783 });784 $(document).on('touchstart mousedown', '#coshButton', function (e) {785 e.preventDefault();786 e.stopPropagation();787 var equation = getEquation();788 var functionWrapper = new eqEd.FunctionWrapper(equation, 'cosh', "MathJax_Main");789 insertWrapper(functionWrapper);790 });791 $(document).on('touchstart mousedown', '#tanhButton', function (e) {792 e.preventDefault();793 e.stopPropagation();794 var equation = getEquation();795 var functionWrapper = new eqEd.FunctionWrapper(equation, 'tanh', "MathJax_Main");796 insertWrapper(functionWrapper);797 });798 $(document).on('touchstart mousedown', '#cothButton', function (e) {799 e.preventDefault();800 e.stopPropagation();801 var equation = getEquation();802 var functionWrapper = new eqEd.FunctionWrapper(equation, 'coth', "MathJax_Main");803 insertWrapper(functionWrapper);804 });805 $(document).on('touchstart mousedown', '#sechButton', function (e) {806 e.preventDefault();807 e.stopPropagation();808 var equation = getEquation();809 var functionWrapper = new eqEd.FunctionWrapper(equation, 'sech', "MathJax_Main");810 insertWrapper(functionWrapper);811 });812 $(document).on('touchstart mousedown', '#cschButton', function (e) {813 e.preventDefault();814 e.stopPropagation();815 var equation = getEquation();816 var functionWrapper = new eqEd.FunctionWrapper(equation, 'csch', "MathJax_Main");817 insertWrapper(functionWrapper);818 });819 $(document).on('touchstart mousedown', '#limitButton', function (e) {820 e.preventDefault();821 e.stopPropagation();822 var equation = getEquation();823 var limitWrapper = new eqEd.LimitWrapper(equation);824 insertWrapper(limitWrapper);825 });826 $(document).on('touchstart mousedown', '#maxLowerButton', function (e) {827 e.preventDefault();828 e.stopPropagation();829 var equation = getEquation();830 var functionWrapper = new eqEd.FunctionLowerWrapper(equation, 'max', "MathJax_Main");831 insertWrapper(functionWrapper);832 });833 $(document).on('touchstart mousedown', '#minLowerButton', function (e) {834 e.preventDefault();835 e.stopPropagation();836 var equation = getEquation();837 var functionWrapper = new eqEd.FunctionLowerWrapper(equation, 'min', "MathJax_Main");838 insertWrapper(functionWrapper);839 });840 $(document).on('touchstart mousedown', '#logLowerButton', function (e) {841 e.preventDefault();842 e.stopPropagation();843 var equation = getEquation();844 var functionWrapper = new eqEd.LogLowerWrapper(equation);845 insertWrapper(functionWrapper);846 });847 $(document).on('touchstart mousedown', '#matrixButton', function (e) {848 e.preventDefault();849 e.stopPropagation();850 var equation = getEquation();851 $('#rows').blur();852 $('#cols').blur();853 var rows = parseInt($('#rows').val());854 var cols = parseInt($('#cols').val());855 var matrixWrapper = new eqEd.MatrixWrapper(equation, rows, cols, 'center');856 insertWrapper(matrixWrapper);857 });858 $(document).on('touchstart mousedown', '#dotAccentButton', function (e) {859 e.preventDefault();860 e.stopPropagation();861 var equation = getEquation();862 var accentWrapper = new eqEd.AccentWrapper(equation, '˙', 'MathJax_Main');863 insertWrapper(accentWrapper);864 });865 $(document).on('touchstart mousedown', '#hatAccentButton', function (e) {866 e.preventDefault();867 e.stopPropagation();868 var equation = getEquation();869 var accentWrapper = new eqEd.AccentWrapper(equation, '^', 'MathJax_Main');870 insertWrapper(accentWrapper);871 });872 $(document).on('touchstart mousedown', '#vectorAccentButton', function (e) {873 e.preventDefault();874 e.stopPropagation();875 var equation = getEquation();876 var accentWrapper = new eqEd.AccentWrapper(equation, '҃—', 'MathJax_Main');877 insertWrapper(accentWrapper);878 });879 $(document).on('touchstart mousedown', '#barAccentButton', function (e) {880 e.preventDefault();881 e.stopPropagation();882 var equation = getEquation();883 var accentWrapper = new eqEd.AccentWrapper(equation, '¯', 'MathJax_Main');884 insertWrapper(accentWrapper);885 });886 $(document).on('touchstart mousedown', '#gammaUpperButton', function (e) {887 e.preventDefault();888 e.stopPropagation();889 var equation = getEquation();890 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'ΓŽΒ“', "MathJax_Main");891 insertWrapper(symbolWrapper);892 });893 $(document).on('touchstart mousedown', '#deltaUpperButton', function (e) {894 e.preventDefault();895 e.stopPropagation();896 var equation = getEquation();897 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'ΓŽΒ”', "MathJax_Main");898 insertWrapper(symbolWrapper);899 });900 $(document).on('touchstart mousedown', '#thetaUpperButton', function (e) {901 e.preventDefault();902 e.stopPropagation();903 var equation = getEquation();904 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'Θ', "MathJax_Main");905 insertWrapper(symbolWrapper);906 });907 $(document).on('touchstart mousedown', '#lambdaUpperButton', function (e) {908 e.preventDefault();909 e.stopPropagation();910 var equation = getEquation();911 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'ΓŽΒ›', "MathJax_Main");912 insertWrapper(symbolWrapper);913 });914 $(document).on('touchstart mousedown', '#xiUpperButton', function (e) {915 e.preventDefault();916 e.stopPropagation();917 var equation = getEquation();918 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'Ξ', "MathJax_Main");919 insertWrapper(symbolWrapper);920 });921 $(document).on('touchstart mousedown', '#piUpperButton', function (e) {922 e.preventDefault();923 e.stopPropagation();924 var equation = getEquation();925 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'Π', "MathJax_Main");926 insertWrapper(symbolWrapper);927 });928 $(document).on('touchstart mousedown', '#sigmaUpperButton', function (e) {929 e.preventDefault();930 e.stopPropagation();931 var equation = getEquation();932 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'Σ', "MathJax_Main");933 insertWrapper(symbolWrapper);934 });935 $(document).on('touchstart mousedown', '#upsilonUpperButton', function (e) {936 e.preventDefault();937 e.stopPropagation();938 var equation = getEquation();939 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'ÎΒ₯', "MathJax_Main");940 insertWrapper(symbolWrapper);941 });942 $(document).on('touchstart mousedown', '#phiUpperButton', function (e) {943 e.preventDefault();944 e.stopPropagation();945 var equation = getEquation();946 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'Φ', "MathJax_Main");947 insertWrapper(symbolWrapper);948 });949 $(document).on('touchstart mousedown', '#psiUpperButton', function (e) {950 e.preventDefault();951 e.stopPropagation();952 var equation = getEquation();953 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'Ψ', "MathJax_Main");954 insertWrapper(symbolWrapper);955 });956 $(document).on('touchstart mousedown', '#omegaUpperButton', function (e) {957 e.preventDefault();958 e.stopPropagation();959 var equation = getEquation();960 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'Ω', "MathJax_Main");961 insertWrapper(symbolWrapper);962 });963 $(document).on('touchstart mousedown', '#alphaButton', function (e) {964 e.preventDefault();965 e.stopPropagation();966 var equation = getEquation();967 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'α', "MathJax_MathItalic");968 insertWrapper(symbolWrapper);969 });970 $(document).on('touchstart mousedown', '#betaButton', function (e) {971 e.preventDefault();972 e.stopPropagation();973 var equation = getEquation();974 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'β', "MathJax_MathItalic");975 insertWrapper(symbolWrapper);976 });977 $(document).on('touchstart mousedown', '#gammaButton', function (e) {978 e.preventDefault();979 e.stopPropagation();980 var equation = getEquation();981 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'γ', "MathJax_MathItalic");982 insertWrapper(symbolWrapper);983 });984 $(document).on('touchstart mousedown', '#deltaButton', function (e) {985 e.preventDefault();986 e.stopPropagation();987 var equation = getEquation();988 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'δ', "MathJax_MathItalic");989 insertWrapper(symbolWrapper);990 });991 $(document).on('touchstart mousedown', '#varEpsilonButton', function (e) {992 e.preventDefault();993 e.stopPropagation();994 var equation = getEquation();995 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'Ρ', "MathJax_MathItalic");996 insertWrapper(symbolWrapper);997 });998 $(document).on('touchstart mousedown', '#epsilonButton', function (e) {999 e.preventDefault();1000 e.stopPropagation();1001 var equation = getEquation();1002 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'Ï¡', "MathJax_MathItalic");1003 insertWrapper(symbolWrapper);1004 });1005 $(document).on('touchstart mousedown', '#zetaButton', function (e) {1006 e.preventDefault();1007 e.stopPropagation();1008 var equation = getEquation();1009 var symbolWrapper = new eqEd.SymbolWrapper(equation, '΢', "MathJax_MathItalic");1010 insertWrapper(symbolWrapper);1011 });1012 $(document).on('touchstart mousedown', '#etaButton', function (e) {1013 e.preventDefault();1014 e.stopPropagation();1015 var equation = getEquation();1016 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'η', "MathJax_MathItalic");1017 insertWrapper(symbolWrapper);1018 });1019 $(document).on('touchstart mousedown', '#thetaButton', function (e) {1020 e.preventDefault();1021 e.stopPropagation();1022 var equation = getEquation();1023 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'θ', "MathJax_MathItalic");1024 insertWrapper(symbolWrapper);1025 });1026 $(document).on('touchstart mousedown', '#varThetaButton', function (e) {1027 e.preventDefault();1028 e.stopPropagation();1029 var equation = getEquation();1030 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'ϑ', "MathJax_MathItalic");1031 insertWrapper(symbolWrapper);1032 });1033 $(document).on('touchstart mousedown', '#iotaButton', function (e) {1034 e.preventDefault();1035 e.stopPropagation();1036 var equation = getEquation();1037 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'ι', "MathJax_MathItalic");1038 insertWrapper(symbolWrapper);1039 });1040 $(document).on('touchstart mousedown', '#kappaButton', function (e) {1041 e.preventDefault();1042 e.stopPropagation();1043 var equation = getEquation();1044 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'κ', "MathJax_MathItalic");1045 insertWrapper(symbolWrapper);1046 });1047 $(document).on('touchstart mousedown', '#lambdaButton', function (e) {1048 e.preventDefault();1049 e.stopPropagation();1050 var equation = getEquation();1051 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'λ', "MathJax_MathItalic");1052 insertWrapper(symbolWrapper);1053 });1054 $(document).on('touchstart mousedown', '#muButton', function (e) {1055 e.preventDefault();1056 e.stopPropagation();1057 var equation = getEquation();1058 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'μ', "MathJax_MathItalic");1059 insertWrapper(symbolWrapper);1060 });1061 $(document).on('touchstart mousedown', '#nuButton', function (e) {1062 e.preventDefault();1063 e.stopPropagation();1064 var equation = getEquation();1065 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'ν', "MathJax_MathItalic");1066 insertWrapper(symbolWrapper);1067 });1068 $(document).on('touchstart mousedown', '#xiButton', function (e) {1069 e.preventDefault();1070 e.stopPropagation();1071 var equation = getEquation();1072 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'ξ', "MathJax_MathItalic");1073 insertWrapper(symbolWrapper);1074 });1075 $(document).on('touchstart mousedown', '#piButton', function (e) {1076 e.preventDefault();1077 e.stopPropagation();1078 var equation = getEquation();1079 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'π', "MathJax_MathItalic");1080 insertWrapper(symbolWrapper);1081 });1082 $(document).on('touchstart mousedown', '#varPiButton', function (e) {1083 e.preventDefault();1084 e.stopPropagation();1085 var equation = getEquation();1086 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'ϖ', "MathJax_MathItalic");1087 insertWrapper(symbolWrapper);1088 });1089 $(document).on('touchstart mousedown', '#rhoButton', function (e) {1090 e.preventDefault();1091 e.stopPropagation();1092 var equation = getEquation();1093 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'ρ', "MathJax_MathItalic");1094 insertWrapper(symbolWrapper);1095 });1096 $(document).on('touchstart mousedown', '#varRhoButton', function (e) {1097 e.preventDefault();1098 e.stopPropagation();1099 var equation = getEquation();1100 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'ϱ', "MathJax_MathItalic");1101 insertWrapper(symbolWrapper);1102 });1103 $(document).on('touchstart mousedown', '#sigmaButton', function (e) {1104 e.preventDefault();1105 e.stopPropagation();1106 var equation = getEquation();1107 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'σ', "MathJax_MathItalic");1108 insertWrapper(symbolWrapper);1109 });1110 $(document).on('touchstart mousedown', '#varSigmaButton', function (e) {1111 e.preventDefault();1112 e.stopPropagation();1113 var equation = getEquation();1114 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'ς', "MathJax_MathItalic");1115 insertWrapper(symbolWrapper);1116 });1117 $(document).on('touchstart mousedown', '#tauButton', function (e) {1118 e.preventDefault();1119 e.stopPropagation();1120 var equation = getEquation();1121 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'τ', "MathJax_MathItalic");1122 insertWrapper(symbolWrapper);1123 });1124 $(document).on('touchstart mousedown', '#upsilonButton', function (e) {1125 e.preventDefault();1126 e.stopPropagation();1127 var equation = getEquation();1128 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'υ', "MathJax_MathItalic");1129 insertWrapper(symbolWrapper);1130 });1131 $(document).on('touchstart mousedown', '#varPhiButton', function (e) {1132 e.preventDefault();1133 e.stopPropagation();1134 var equation = getEquation();1135 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'φ', "MathJax_MathItalic");1136 insertWrapper(symbolWrapper);1137 });1138 $(document).on('touchstart mousedown', '#phiButton', function (e) {1139 e.preventDefault();1140 e.stopPropagation();1141 var equation = getEquation();1142 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'ϕ', "MathJax_MathItalic");1143 insertWrapper(symbolWrapper);1144 });1145 $(document).on('touchstart mousedown', '#chiButton', function (e) {1146 e.preventDefault();1147 e.stopPropagation();1148 var equation = getEquation();1149 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'χ', "MathJax_MathItalic");1150 insertWrapper(symbolWrapper);1151 });1152 $(document).on('touchstart mousedown', '#psiButton', function (e) {1153 e.preventDefault();1154 e.stopPropagation();1155 var equation = getEquation();1156 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'ψ', "MathJax_MathItalic");1157 insertWrapper(symbolWrapper);1158 });1159 $(document).on('touchstart mousedown', '#omegaButton', function (e) {1160 e.preventDefault();1161 e.stopPropagation();1162 var equation = getEquation();1163 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'ω', "MathJax_MathItalic");1164 insertWrapper(symbolWrapper);1165 });1166 $(document).on('touchstart mousedown', '#lessThanOrEqualToButton', function (e) {1167 e.preventDefault();1168 e.stopPropagation();1169 var equation = getEquation();1170 var operatorWrapper = new eqEd.OperatorWrapper(equation, '҉€', "MathJax_Main");1171 insertWrapper(operatorWrapper);1172 });1173 $(document).on('touchstart mousedown', '#greaterThanOrEqualToButton', function (e) {1174 e.preventDefault();1175 e.stopPropagation();1176 var equation = getEquation();1177 var operatorWrapper = new eqEd.OperatorWrapper(equation, 'Γ’Β‰Β₯', "MathJax_Main");1178 insertWrapper(operatorWrapper);1179 });1180 $(document).on('touchstart mousedown', '#circleOperatorButton', function (e) {1181 e.preventDefault();1182 e.stopPropagation();1183 var equation = getEquation();1184 var operatorWrapper = new eqEd.OperatorWrapper(equation, 'Γ’Β—Β¦', "MathJax_Main");1185 insertWrapper(operatorWrapper);1186 });1187 $(document).on('touchstart mousedown', '#approxEqualToButton', function (e) {1188 e.preventDefault();1189 e.stopPropagation();1190 var equation = getEquation();1191 var operatorWrapper = new eqEd.OperatorWrapper(equation, 'Γ’Β‰Βˆ', "MathJax_Main");1192 insertWrapper(operatorWrapper);1193 });1194 $(document).on('touchstart mousedown', '#belongsToButton', function (e) {1195 e.preventDefault();1196 e.stopPropagation();1197 var equation = getEquation();1198 var operatorWrapper = new eqEd.OperatorWrapper(equation, '҈ˆ', "MathJax_Main");1199 insertWrapper(operatorWrapper);1200 });1201 $(document).on('touchstart mousedown', '#timesButton', function (e) {1202 e.preventDefault();1203 e.stopPropagation();1204 var equation = getEquation();1205 var operatorWrapper = new eqEd.OperatorWrapper(equation, '×', "MathJax_Main");1206 insertWrapper(operatorWrapper);1207 });1208 $(document).on('touchstart mousedown', '#pmButton', function (e) {1209 e.preventDefault();1210 e.stopPropagation();1211 var equation = getEquation();1212 var operatorWrapper = new eqEd.OperatorWrapper(equation, '±', "MathJax_Main");1213 insertWrapper(operatorWrapper);1214 });1215 $(document).on('touchstart mousedown', '#wedgeButton', function (e) {1216 e.preventDefault();1217 e.stopPropagation();1218 var equation = getEquation();1219 var operatorWrapper = new eqEd.OperatorWrapper(equation, '҈§', "MathJax_Main");1220 insertWrapper(operatorWrapper);1221 });1222 $(document).on('touchstart mousedown', '#veeButton', function (e) {1223 e.preventDefault();1224 e.stopPropagation();1225 var equation = getEquation();1226 var operatorWrapper = new eqEd.OperatorWrapper(equation, '҈¨', "MathJax_Main");1227 insertWrapper(operatorWrapper);1228 });1229 $(document).on('touchstart mousedown', '#equivButton', function (e) {1230 e.preventDefault();1231 e.stopPropagation();1232 var equation = getEquation();1233 var operatorWrapper = new eqEd.OperatorWrapper(equation, '҉‘', "MathJax_Main");1234 insertWrapper(operatorWrapper);1235 });1236 $(document).on('touchstart mousedown', '#congButton', function (e) {1237 e.preventDefault();1238 e.stopPropagation();1239 var equation = getEquation();1240 var operatorWrapper = new eqEd.OperatorWrapper(equation, '҉…', "MathJax_Main");1241 insertWrapper(operatorWrapper);1242 });1243 $(document).on('touchstart mousedown', '#neqButton', function (e) {1244 e.preventDefault();1245 e.stopPropagation();1246 var equation = getEquation();1247 var operatorWrapper = new eqEd.OperatorWrapper(equation, '҉ ', "MathJax_Main");1248 insertWrapper(operatorWrapper);1249 });1250 $(document).on('touchstart mousedown', '#simButton', function (e) {1251 e.preventDefault();1252 e.stopPropagation();1253 var equation = getEquation();1254 var operatorWrapper = new eqEd.OperatorWrapper(equation, '҈¼', "MathJax_Main");1255 insertWrapper(operatorWrapper);1256 });1257 $(document).on('touchstart mousedown', '#proptoButton', function (e) {1258 e.preventDefault();1259 e.stopPropagation();1260 var equation = getEquation();1261 var operatorWrapper = new eqEd.OperatorWrapper(equation, '҈', "MathJax_Main");1262 insertWrapper(operatorWrapper);1263 });1264 $(document).on('touchstart mousedown', '#precButton', function (e) {1265 e.preventDefault();1266 e.stopPropagation();1267 var equation = getEquation();1268 var operatorWrapper = new eqEd.OperatorWrapper(equation, '҉º', "MathJax_Main");1269 insertWrapper(operatorWrapper);1270 });1271 $(document).on('touchstart mousedown', '#precEqButton', function (e) {1272 e.preventDefault();1273 e.stopPropagation();1274 var equation = getEquation();1275 var operatorWrapper = new eqEd.OperatorWrapper(equation, 'Γ’ΒͺΒ―', "MathJax_Main");1276 insertWrapper(operatorWrapper);1277 });1278 $(document).on('touchstart mousedown', '#subsetButton', function (e) {1279 e.preventDefault();1280 e.stopPropagation();1281 var equation = getEquation();1282 var operatorWrapper = new eqEd.OperatorWrapper(equation, 'Γ’ΒŠΒ‚', "MathJax_Main");1283 insertWrapper(operatorWrapper);1284 });1285 $(document).on('touchstart mousedown', '#subsetEqButton', function (e) {1286 e.preventDefault();1287 e.stopPropagation();1288 var equation = getEquation();1289 var operatorWrapper = new eqEd.OperatorWrapper(equation, 'Γ’ΒŠΒ†', "MathJax_Main");1290 insertWrapper(operatorWrapper);1291 });1292 $(document).on('touchstart mousedown', '#succButton', function (e) {1293 e.preventDefault();1294 e.stopPropagation();1295 var equation = getEquation();1296 var operatorWrapper = new eqEd.OperatorWrapper(equation, '҉»', "MathJax_Main");1297 insertWrapper(operatorWrapper);1298 });1299 $(document).on('touchstart mousedown', '#succEqButton', function (e) {1300 e.preventDefault();1301 e.stopPropagation();1302 var equation = getEquation();1303 var operatorWrapper = new eqEd.OperatorWrapper(equation, 'Γ’ΒͺΒ°', "MathJax_Main");1304 insertWrapper(operatorWrapper);1305 });1306 $(document).on('touchstart mousedown', '#perpButton', function (e) {1307 e.preventDefault();1308 e.stopPropagation();1309 var equation = getEquation();1310 var operatorWrapper = new eqEd.OperatorWrapper(equation, 'ҊΒ₯', "MathJax_Main");1311 insertWrapper(operatorWrapper);1312 });1313 $(document).on('touchstart mousedown', '#midButton', function (e) {1314 e.preventDefault();1315 e.stopPropagation();1316 var equation = getEquation();1317 var operatorWrapper = new eqEd.OperatorWrapper(equation, '҈£', "MathJax_Main");1318 insertWrapper(operatorWrapper);1319 });1320 $(document).on('touchstart mousedown', '#parallelButton', function (e) {1321 e.preventDefault();1322 e.stopPropagation();1323 var equation = getEquation();1324 var operatorWrapper = new eqEd.OperatorWrapper(equation, '҈Β₯', "MathJax_Main");1325 insertWrapper(operatorWrapper);1326 });1327 $(document).on('touchstart mousedown', '#colonButton', function (e) {1328 e.preventDefault();1329 e.stopPropagation();1330 var equation = getEquation();1331 var operatorWrapper = new eqEd.OperatorWrapper(equation, ':', "MathJax_Main");1332 insertWrapper(operatorWrapper);1333 });1334 $(document).on('touchstart mousedown', '#partialButton', function (e) {1335 e.preventDefault();1336 e.stopPropagation();1337 var equation = getEquation();1338 var symbolWrapper = new eqEd.SymbolWrapper(equation, 'Γ’ΒˆΒ‚', "MathJax_Main");1339 insertWrapper(symbolWrapper);1340 });1341 $(document).on('touchstart mousedown', '#infinityButton', function (e) {1342 e.preventDefault();1343 e.stopPropagation();1344 var equation = getEquation();1345 var symbolWrapper = new eqEd.SymbolWrapper(equation, '҈ž', "MathJax_Main");1346 insertWrapper(symbolWrapper);1347 });1348};1349$(document).on('click', '.tabs .tab-links a', function(e) {1350 var currentAttrValue = $(this).attr('href');1351 // Show/Hide Tabs1352 $('.tabs ' + currentAttrValue).show().siblings().hide();1353 // Change/remove current tab to active1354 $(this).parent('li').addClass('active').siblings().removeClass('active');1355 e.preventDefault();...

Full Screen

Full Screen

python_object_representation.py

Source:python_object_representation.py Github

copy

Full Screen

1# Copyright 2017-2020 typed_python Authors2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14import threading15import _thread16from typed_python.compiler.typed_expression import TypedExpression17import typed_python.compiler.native_ast as native_ast18from typed_python.type_function import TypeFunction19from typed_python.compiler.type_wrappers.wrapper import Wrapper20from typed_python.compiler.type_wrappers.compilable_builtin import CompilableBuiltin21from typed_python.compiler.type_wrappers.none_wrapper import NoneWrapper22from typed_python.compiler.type_wrappers.method_descriptor_wrapper import MethodDescriptorWrapper23from typed_python.compiler.type_wrappers.python_type_object_wrapper import PythonTypeObjectWrapper24from typed_python.compiler.type_wrappers.module_wrapper import ModuleWrapper25from typed_python.compiler.type_wrappers.typed_cell_wrapper import TypedCellWrapper26from typed_python.compiler.type_wrappers.unresolved_forward_type_wrapper import UnresolvedForwardTypeWrapper27from typed_python.compiler.type_wrappers.python_free_function_wrapper import PythonFreeFunctionWrapper28from typed_python.compiler.type_wrappers.python_free_object_wrapper import PythonFreeObjectWrapper29from typed_python.compiler.type_wrappers.python_typed_function_wrapper import PythonTypedFunctionWrapper30from typed_python.compiler.type_wrappers.value_wrapper import ValueWrapper31from typed_python.compiler.type_wrappers.tuple_of_wrapper import TupleOfWrapper32from typed_python.compiler.type_wrappers.pointer_to_wrapper import PointerToWrapper, PointerToObjectWrapper33from typed_python.compiler.type_wrappers.ref_to_wrapper import RefToWrapper, RefToObjectWrapper34from typed_python.compiler.type_wrappers.list_of_wrapper import ListOfWrapper35from typed_python.compiler.type_wrappers.isinstance_wrapper import IsinstanceWrapper36from typed_python.compiler.type_wrappers.issubclass_wrapper import IssubclassWrapper37from typed_python.compiler.type_wrappers.subclass_of_wrapper import SubclassOfWrapper38from typed_python.compiler.type_wrappers.one_of_wrapper import OneOfWrapper39from typed_python.compiler.type_wrappers.class_wrapper import ClassWrapper40from typed_python.compiler.type_wrappers.held_class_wrapper import HeldClassWrapper41from typed_python.compiler.type_wrappers.const_dict_wrapper import ConstDictWrapper42from typed_python.compiler.type_wrappers.dict_wrapper import DictWrapper43from typed_python.compiler.type_wrappers.set_wrapper import SetWrapper44from typed_python.compiler.type_wrappers.tuple_wrapper import TupleWrapper, NamedTupleWrapper45from typed_python.compiler.type_wrappers.slice_type_object_wrapper import SliceWrapper46from typed_python.compiler.type_wrappers.alternative_wrapper import makeAlternativeWrapper47from typed_python.compiler.type_wrappers.alternative_wrapper import AlternativeMatcherWrapper48from typed_python.compiler.type_wrappers.bound_method_wrapper import BoundMethodWrapper49from typed_python.compiler.type_wrappers.len_wrapper import LenWrapper50from typed_python.compiler.type_wrappers.hash_wrapper import HashWrapper51from typed_python.compiler.type_wrappers.range_wrapper import range as compilableRange52from typed_python.compiler.type_wrappers.print_wrapper import PrintWrapper53from typed_python.compiler.type_wrappers.super_wrapper import SuperWrapper54from typed_python.compiler.type_wrappers.compiler_introspection_wrappers import (55 IsCompiledWrapper,56 TypeKnownToCompiler,57 LocalVariableTypesKnownToCompiler,58)59from typed_python.compiler.type_wrappers.make_named_tuple_wrapper import MakeNamedTupleWrapper60from typed_python.compiler.type_wrappers.math_wrappers import MathFunctionWrapper61from typed_python.compiler.type_wrappers.builtin_wrappers import BuiltinWrapper62from typed_python.compiler.type_wrappers.bytecount_wrapper import BytecountWrapper63from typed_python.compiler.type_wrappers.arithmetic_wrapper import IntWrapper, FloatWrapper, BoolWrapper64from typed_python.compiler.type_wrappers.string_wrapper import StringWrapper, StringMaketransWrapper65from typed_python.compiler.type_wrappers.bytes_wrapper import BytesWrapper, BytesMaketransWrapper66from typed_python.compiler.type_wrappers.python_object_of_type_wrapper import PythonObjectOfTypeWrapper67from typed_python.compiler.type_wrappers.abs_wrapper import AbsWrapper68from typed_python.compiler.type_wrappers.min_max_wrapper import MinWrapper, MaxWrapper69from typed_python.compiler.type_wrappers.repr_wrapper import ReprWrapper70from types import ModuleType71from typed_python._types import (72 TypeFor, bytecount, prepareArgumentToBePassedToCompiler, allForwardTypesResolved73)74from typed_python import (75 Type, Int32, Int16, Int8, UInt64, UInt32, UInt16,76 UInt8, Float32, makeNamedTuple,77 ListOf, isCompiled,78 typeKnownToCompiler,79 localVariableTypesKnownToCompiler,80 pointerTo, refTo81)82# the type of bound C methods on types.83method_descriptor = type(ListOf(int).append)84_type_to_type_wrapper_cache = {}85def typedPythonTypeToTypeWrapper(t):86 if isinstance(t, Wrapper):87 return t88 if t not in _type_to_type_wrapper_cache:89 _type_to_type_wrapper_cache[t] = _typedPythonTypeToTypeWrapper(t)90 return _type_to_type_wrapper_cache[t]91_concreteWrappers = {92 Int8: IntWrapper(Int8),93 Int16: IntWrapper(Int16),94 Int32: IntWrapper(Int32),95 int: IntWrapper(int),96 UInt8: IntWrapper(UInt8),97 UInt16: IntWrapper(UInt16),98 UInt32: IntWrapper(UInt32),99 UInt64: IntWrapper(UInt64),100 Float32: FloatWrapper(Float32),101 float: FloatWrapper(float),102 bool: BoolWrapper(),103 None: NoneWrapper(),104 type(None): NoneWrapper(),105 str: StringWrapper(),106 bytes: BytesWrapper()107}108def functionIsCompilable(f):109 """Is a python function 'f' compilable?110 Specifically, we try to cordon off the functions we know are not going to compile111 so that we can just represent them as python objects.112 """113 # we know we can't compile standard numpy and scipy functions114 if f.__module__ == "numpy" or f.__module__.startswith("numpy."):115 return False116 if f.__module__ == "scipy" or f.__module__.startswith("scipy."):117 return False118 return True119def _typedPythonTypeToTypeWrapper(t):120 if isinstance(t, Wrapper):121 return t122 if t in _concreteWrappers:123 return _concreteWrappers[t]124 if not hasattr(t, '__typed_python_category__'):125 t = TypeFor(t)126 assert isinstance(t, type), t127 if not allForwardTypesResolved(t):128 return UnresolvedForwardTypeWrapper(t)129 if not hasattr(t, '__typed_python_category__'):130 # this is will be a PythonObjectOfType, but we never actually return such an object131 # to the interpreter132 if t is threading.RLock:133 t = _thread.RLock134 elif t is threading.Lock:135 t = _thread.LockType136 return PythonObjectOfTypeWrapper(t)137 if t.__typed_python_category__ == "Class":138 return ClassWrapper(t)139 if t.__typed_python_category__ == "HeldClass":140 return HeldClassWrapper(t)141 if t.__typed_python_category__ == "Alternative":142 return makeAlternativeWrapper(t)143 if t.__typed_python_category__ == "ConstDict":144 return ConstDictWrapper(t)145 if t.__typed_python_category__ == "Dict":146 return DictWrapper(t)147 if t.__typed_python_category__ == "ConcreteAlternative":148 return makeAlternativeWrapper(t)149 if t.__typed_python_category__ == "NamedTuple":150 return NamedTupleWrapper(t)151 if t.__typed_python_category__ == "Tuple":152 return TupleWrapper(t)153 if t.__typed_python_category__ == "ListOf":154 return ListOfWrapper(t)155 if t.__typed_python_category__ == "PointerTo":156 return PointerToWrapper(t)157 if t.__typed_python_category__ == "RefTo":158 return RefToWrapper(t)159 if t.__typed_python_category__ == "Function":160 return PythonTypedFunctionWrapper(t)161 if t.__typed_python_category__ == "BoundMethod":162 return BoundMethodWrapper(t)163 if t.__typed_python_category__ == "AlternativeMatcher":164 return AlternativeMatcherWrapper(t)165 if t.__typed_python_category__ == "TupleOf":166 return TupleOfWrapper(t)167 if t.__typed_python_category__ == "OneOf":168 return OneOfWrapper(t)169 if t.__typed_python_category__ == "TypedCell":170 return TypedCellWrapper(t)171 if t.__typed_python_category__ == "SubclassOf":172 return SubclassOfWrapper(t)173 if t.__typed_python_category__ == "Value":174 if type(t.Value) in _concreteWrappers or type(t.Value) in (str, int, float, bool):175 return ValueWrapper(t)176 return pythonObjectRepresentation(None, t.Value).expr_type177 if t.__typed_python_category__ == "Set":178 return SetWrapper(t)179 assert False, (t, getattr(t, '__typed_python_category__', None))180def pythonObjectRepresentation(context, f, owningGlobalScopeAndName=None):181 """Create a representation for a python constant.182 Args:183 context - the ExpressionConversionContext184 f - the constant185 owningGlobalScopeAndName - either None, or a pair (dict, name)186 where the object is equivalent to dict[name]187 """188 if isinstance(f, CompilableBuiltin):189 return TypedExpression(context, native_ast.nullExpr, f, False)190 if f is len:191 return TypedExpression(context, native_ast.nullExpr, LenWrapper(), False)192 if f is hash:193 return TypedExpression(context, native_ast.nullExpr, HashWrapper(), False)194 if f is slice:195 return TypedExpression(context, native_ast.nullExpr, SliceWrapper(), False)196 if f is abs:197 return TypedExpression(context, native_ast.nullExpr, AbsWrapper(), False)198 if f is min:199 return TypedExpression(context, native_ast.nullExpr, MinWrapper(), False)200 if f is max:201 return TypedExpression(context, native_ast.nullExpr, MaxWrapper(), False)202 if f is repr:203 return TypedExpression(context, native_ast.nullExpr, ReprWrapper(), False)204 if f is range:205 return pythonObjectRepresentation(context, compilableRange, owningGlobalScopeAndName)206 if f is bytes.maketrans:207 return TypedExpression(context, native_ast.nullExpr, BytesMaketransWrapper(), False)208 if f is str.maketrans:209 return TypedExpression(context, native_ast.nullExpr, StringMaketransWrapper(), False)210 if f is isinstance:211 return TypedExpression(context, native_ast.nullExpr, IsinstanceWrapper(), False)212 if f is issubclass:213 return TypedExpression(context, native_ast.nullExpr, IssubclassWrapper(), False)214 if f is bytecount:215 return TypedExpression(context, native_ast.nullExpr, BytecountWrapper(), False)216 if f is print:217 return TypedExpression(context, native_ast.nullExpr, PrintWrapper(), False)218 if f is super:219 return TypedExpression(context, native_ast.nullExpr, SuperWrapper(), False)220 if f is pointerTo:221 return TypedExpression(context, native_ast.nullExpr, PointerToObjectWrapper(), False)222 if f is refTo:223 return TypedExpression(context, native_ast.nullExpr, RefToObjectWrapper(), False)224 if f is isCompiled:225 return TypedExpression(context, native_ast.nullExpr, IsCompiledWrapper(), False)226 if f is typeKnownToCompiler:227 return TypedExpression(context, native_ast.nullExpr, TypeKnownToCompiler(), False)228 if f is localVariableTypesKnownToCompiler:229 return TypedExpression(context, native_ast.nullExpr, LocalVariableTypesKnownToCompiler(), False)230 if f is makeNamedTuple:231 return TypedExpression(context, native_ast.nullExpr, MakeNamedTupleWrapper(), False)232 if f in MathFunctionWrapper.SUPPORTED_FUNCTIONS:233 return TypedExpression(context, native_ast.nullExpr, MathFunctionWrapper(f), False)234 if f in BuiltinWrapper.SUPPORTED_FUNCTIONS:235 return TypedExpression(context, native_ast.nullExpr, BuiltinWrapper(f), False)236 if f is None:237 return TypedExpression(238 context,239 native_ast.Expression.Constant(240 val=native_ast.Constant.Void()241 ),242 NoneWrapper(),243 False244 )245 if isinstance(f, bool):246 return TypedExpression(247 context,248 native_ast.Expression.Constant(249 val=native_ast.Constant.Int(val=f, bits=1, signed=False)250 ),251 BoolWrapper(),252 False,253 constantValue=f254 )255 if isinstance(f, int):256 return TypedExpression(257 context,258 native_ast.Expression.Constant(259 val=native_ast.Constant.Int(val=f, bits=64, signed=True)260 ),261 IntWrapper(int),262 False,263 constantValue=f264 )265 if isinstance(f, float):266 return TypedExpression(267 context,268 native_ast.Expression.Constant(269 val=native_ast.Constant.Float(val=f, bits=64)270 ),271 FloatWrapper(float),272 False,273 constantValue=f274 )275 if isinstance(f, str):276 return StringWrapper().constant(context, f)277 if isinstance(f, bytes):278 return BytesWrapper().constant(context, f)279 if isinstance(f, type(pythonObjectRepresentation)):280 if functionIsCompilable(f):281 return TypedExpression(282 context,283 native_ast.nullExpr,284 PythonFreeFunctionWrapper(f),285 False286 )287 else:288 return context.constantPyObject(f, owningGlobalScopeAndName)289 if isinstance(f, method_descriptor):290 return TypedExpression(291 context,292 native_ast.nullExpr,293 MethodDescriptorWrapper(f),294 False295 )296 if hasattr(f, '__typed_python_category__') and not isinstance(f, type):297 if f.__typed_python_category__ == "Function":298 f = prepareArgumentToBePassedToCompiler(f)299 if bytecount(f.ClosureType):300 raise Exception(f"Function {f} has nonempty closure {f.ClosureType}")301 return TypedExpression(302 context,303 typedPythonTypeToTypeWrapper(f.ClosureType).getNativeLayoutType().zero(),304 PythonTypedFunctionWrapper(f),305 False306 )307 if f.__typed_python_category__ == "Class":308 # global class instances get held as constants309 return context.constantTypedPythonObject(f, owningGlobalScopeAndName)310 if isinstance(f, type) and issubclass(f, TypeFunction) and len(f.MRO) == 2:311 return TypedExpression(context, native_ast.nullExpr, PythonFreeObjectWrapper(f, False), False)312 if isinstance(f, type):313 return TypedExpression(context, native_ast.nullExpr, PythonTypeObjectWrapper(f), False)314 if isinstance(f, ModuleType):315 return TypedExpression(context, native_ast.nullExpr, ModuleWrapper(f), False)316 if isinstance(f, Type):317 # it's a typed python object at module level scope318 return context.constantTypedPythonObject(f, owningGlobalScopeAndName)319 return context.constantPyObject(f, owningGlobalScopeAndName)320def pythonObjectRepresentationType(f):321 if isinstance(f, str):322 return StringWrapper()323 if isinstance(f, bytes):324 return BytesWrapper()...

Full Screen

Full Screen

idl_gen_wrapper.py

Source:idl_gen_wrapper.py Github

copy

Full Screen

1# Copyright (c) 2012 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4"""Base class for generating wrapper functions for PPAPI methods.5"""6from datetime import datetime7import os8import sys9from idl_c_proto import CGen10from idl_generator import Generator11from idl_log import ErrOut, InfoOut, WarnOut12from idl_option import GetOption13from idl_outfile import IDLOutFile14class PPKind(object):15 @staticmethod16 def ChoosePPFunc(iface, ppb_func, ppp_func):17 name = iface.node.GetName()18 if name.startswith("PPP"):19 return ppp_func20 elif name.startswith("PPB"):21 return ppb_func22 else:23 raise Exception('Unknown PPKind for ' + name)24class Interface(object):25 """Tracks information about a particular interface version.26 - struct_name: the struct type used by the ppapi headers to hold the27 method pointers (the vtable).28 - needs_wrapping: True if a method in the interface needs wrapping.29 - header_file: the name of the header file that defined this interface.30 """31 def __init__(self, interface_node, release, version,32 struct_name, needs_wrapping, header_file):33 self.node = interface_node34 self.release = release35 self.version = version36 self.struct_name = struct_name37 # We may want finer grained filtering (method level), but it is not38 # yet clear how to actually do that.39 self.needs_wrapping = needs_wrapping40 self.header_file = header_file41class WrapperGen(Generator):42 """WrapperGen - An abstract class that generates wrappers for PPAPI methods.43 This generates a wrapper PPB and PPP GetInterface, which directs users44 to wrapper PPAPI methods. Wrapper PPAPI methods may perform arbitrary45 work before invoking the real PPAPI method (supplied by the original46 GetInterface functions).47 Subclasses must implement GenerateWrapperForPPBMethod (and PPP).48 """49 def __init__(self, wrapper_prefix, s1, s2, s3):50 Generator.__init__(self, s1, s2, s3)51 self.wrapper_prefix = wrapper_prefix52 self._skip_opt = False53 self.output_file = None54 self.cgen = CGen()55 def SetOutputFile(self, fname):56 self.output_file = fname57 def GenerateRelease(self, ast, release, options):58 return self.GenerateRange(ast, [release], options)59 @staticmethod60 def GetHeaderName(name):61 """Get the corresponding ppapi .h file from each IDL filename.62 """63 name = os.path.splitext(name)[0] + '.h'64 name = name.replace(os.sep, '/')65 return 'ppapi/c/' + name66 def WriteCopyright(self, out):67 now = datetime.now()68 c = """/* Copyright (c) %s The Chromium Authors. All rights reserved.69 * Use of this source code is governed by a BSD-style license that can be70 * found in the LICENSE file.71 */72/* NOTE: this is auto-generated from IDL */73""" % now.year74 out.Write(c)75 def GetWrapperMetadataName(self):76 return '__%sWrapperInfo' % self.wrapper_prefix77 def GenerateHelperFunctions(self, out):78 """Generate helper functions to avoid dependencies on libc.79 """80 out.Write("""/* Use local strcmp to avoid dependency on libc. */81static int mystrcmp(const char* s1, const char *s2) {82 while (1) {83 if (*s1 == 0) break;84 if (*s2 == 0) break;85 if (*s1 != *s2) break;86 ++s1;87 ++s2;88 }89 return (int)(*s1) - (int)(*s2);90}\n91""")92 def GenerateFixedFunctions(self, out):93 """Write out the set of constant functions (those that do not depend on94 the current Pepper IDL).95 """96 out.Write("""97static PPB_GetInterface __real_PPBGetInterface;98static PPP_GetInterface_Type __real_PPPGetInterface;99void __set_real_%(wrapper_prefix)s_PPBGetInterface(PPB_GetInterface real) {100 __real_PPBGetInterface = real;101}102void __set_real_%(wrapper_prefix)s_PPPGetInterface(PPP_GetInterface_Type real) {103 __real_PPPGetInterface = real;104}105/* Map interface string -> wrapper metadata */106static struct %(wrapper_struct)s *%(wrapper_prefix)sPPBShimIface(107 const char *name) {108 struct %(wrapper_struct)s **next = s_ppb_wrappers;109 while (*next != NULL) {110 if (mystrcmp(name, (*next)->iface_macro) == 0) return *next;111 ++next;112 }113 return NULL;114}115/* Map interface string -> wrapper metadata */116static struct %(wrapper_struct)s *%(wrapper_prefix)sPPPShimIface(117 const char *name) {118 struct %(wrapper_struct)s **next = s_ppp_wrappers;119 while (*next != NULL) {120 if (mystrcmp(name, (*next)->iface_macro) == 0) return *next;121 ++next;122 }123 return NULL;124}125const void *__%(wrapper_prefix)s_PPBGetInterface(const char *name) {126 struct %(wrapper_struct)s *wrapper = %(wrapper_prefix)sPPBShimIface(name);127 if (wrapper == NULL) {128 /* We did not generate a wrapper for this, so return the real interface. */129 return (*__real_PPBGetInterface)(name);130 }131 /* Initialize the real_iface if it hasn't been. The wrapper depends on it. */132 if (wrapper->real_iface == NULL) {133 const void *iface = (*__real_PPBGetInterface)(name);134 if (NULL == iface) return NULL;135 wrapper->real_iface = iface;136 }137 return wrapper->wrapped_iface;138}139const void *__%(wrapper_prefix)s_PPPGetInterface(const char *name) {140 struct %(wrapper_struct)s *wrapper = %(wrapper_prefix)sPPPShimIface(name);141 if (wrapper == NULL) {142 /* We did not generate a wrapper for this, so return the real interface. */143 return (*__real_PPPGetInterface)(name);144 }145 /* Initialize the real_iface if it hasn't been. The wrapper depends on it. */146 if (wrapper->real_iface == NULL) {147 const void *iface = (*__real_PPPGetInterface)(name);148 if (NULL == iface) return NULL;149 wrapper->real_iface = iface;150 }151 return wrapper->wrapped_iface;152}153""" % { 'wrapper_struct' : self.GetWrapperMetadataName(),154 'wrapper_prefix' : self.wrapper_prefix,155 } )156 ############################################################157 def OwnHeaderFile(self):158 """Return the header file that specifies the API of this wrapper.159 We do not generate the header files. """160 raise Exception('Child class must implement this')161 ############################################################162 def DetermineInterfaces(self, ast, releases):163 """Get a list of interfaces along with whatever metadata we need.164 """165 iface_releases = []166 for filenode in ast.GetListOf('File'):167 # If this file has errors, skip it168 if filenode in self.skip_list:169 if GetOption('verbose'):170 InfoOut.Log('WrapperGen: Skipping %s due to errors\n' %171 filenode.GetName())172 continue173 file_name = self.GetHeaderName(filenode.GetName())174 ifaces = filenode.GetListOf('Interface')175 for iface in ifaces:176 releases_for_iface = iface.GetUniqueReleases(releases)177 for release in releases_for_iface:178 version = iface.GetVersion(release)179 struct_name = self.cgen.GetStructName(iface, release,180 include_version=True)181 needs_wrap = self.InterfaceVersionNeedsWrapping(iface, version)182 if not needs_wrap:183 if GetOption('verbose'):184 InfoOut.Log('Interface %s ver %s does not need wrapping' %185 (struct_name, version))186 iface_releases.append(187 Interface(iface, release, version,188 struct_name, needs_wrap, file_name))189 return iface_releases190 def GenerateIncludes(self, iface_releases, out):191 """Generate the list of #include that define the original interfaces.192 """193 self.WriteCopyright(out)194 # First include own header.195 out.Write('#include "%s"\n\n' % self.OwnHeaderFile())196 # Get typedefs for PPB_GetInterface.197 out.Write('#include "%s"\n' % self.GetHeaderName('ppb.h'))198 # Only include headers where *some* interface needs wrapping.199 header_files = set()200 for iface in iface_releases:201 if iface.needs_wrapping:202 header_files.add(iface.header_file)203 for header in sorted(header_files):204 out.Write('#include "%s"\n' % header)205 out.Write('\n')206 def WrapperMethodPrefix(self, iface, release):207 return '%s_%s_%s_' % (self.wrapper_prefix, release, iface.GetName())208 def GenerateWrapperForPPBMethod(self, iface, member):209 result = []210 func_prefix = self.WrapperMethodPrefix(iface.node, iface.release)211 sig = self.cgen.GetSignature(member, iface.release, 'store',212 func_prefix, False)213 result.append('static %s {\n' % sig)214 result.append(' while(1) { /* Not implemented */ } \n')215 result.append('}\n')216 return result217 def GenerateWrapperForPPPMethod(self, iface, member):218 result = []219 func_prefix = self.WrapperMethodPrefix(iface.node, iface.release)220 sig = self.cgen.GetSignature(member, iface.release, 'store',221 func_prefix, False)222 result.append('static %s {\n' % sig)223 result.append(' while(1) { /* Not implemented */ } \n')224 result.append('}\n')225 return result226 def GenerateWrapperForMethods(self, iface_releases, comments=True):227 """Return a string representing the code for each wrapper method228 (using a string rather than writing to the file directly for testing.)229 """230 result = []231 for iface in iface_releases:232 if not iface.needs_wrapping:233 if comments:234 result.append('/* Not generating wrapper methods for %s */\n\n' %235 iface.struct_name)236 continue237 if comments:238 result.append('/* Begin wrapper methods for %s */\n\n' %239 iface.struct_name)240 generator = PPKind.ChoosePPFunc(iface,241 self.GenerateWrapperForPPBMethod,242 self.GenerateWrapperForPPPMethod)243 for member in iface.node.GetListOf('Member'):244 # Skip the method if it's not actually in the release.245 if not member.InReleases([iface.release]):246 continue247 result.extend(generator(iface, member))248 if comments:249 result.append('/* End wrapper methods for %s */\n\n' %250 iface.struct_name)251 return ''.join(result)252 def GenerateWrapperInterfaces(self, iface_releases, out):253 for iface in iface_releases:254 if not iface.needs_wrapping:255 out.Write('/* Not generating wrapper interface for %s */\n\n' %256 iface.struct_name)257 continue258 out.Write('static const struct %s %s_Wrappers_%s = {\n' % (259 iface.struct_name, self.wrapper_prefix, iface.struct_name))260 methods = []261 for member in iface.node.GetListOf('Member'):262 # Skip the method if it's not actually in the release.263 if not member.InReleases([iface.release]):264 continue265 prefix = self.WrapperMethodPrefix(iface.node, iface.release)266 # Casts are necessary for the PPB_* wrappers because we must267 # cast away "__attribute__((pnaclcall))". The PPP_* wrappers268 # must match the default calling conventions and so don't have269 # the attribute, so omitting casts for them provides a little270 # extra type checking.271 if iface.node.GetName().startswith('PPB_'):272 cast = '(%s)' % self.cgen.GetSignature(273 member, iface.release, 'return',274 prefix='',275 func_as_ptr=True,276 include_name=False)277 else:278 cast = ''279 methods.append(' .%s = %s&%s%s' % (member.GetName(),280 cast,281 prefix,282 member.GetName()))283 out.Write(' ' + ',\n '.join(methods) + '\n')284 out.Write('};\n\n')285 def GetWrapperInfoName(self, iface):286 return '%s_WrapperInfo_%s' % (self.wrapper_prefix, iface.struct_name)287 def GenerateWrapperInfoAndCollection(self, iface_releases, out):288 for iface in iface_releases:289 iface_macro = self.cgen.GetInterfaceMacro(iface.node, iface.version)290 if iface.needs_wrapping:291 wrap_iface = '(const void *) &%s_Wrappers_%s' % (self.wrapper_prefix,292 iface.struct_name)293 out.Write("""static struct %s %s = {294 .iface_macro = %s,295 .wrapped_iface = %s,296 .real_iface = NULL297};\n\n""" % (self.GetWrapperMetadataName(),298 self.GetWrapperInfoName(iface),299 iface_macro,300 wrap_iface))301 # Now generate NULL terminated arrays of the above wrapper infos.302 ppb_wrapper_infos = []303 ppp_wrapper_infos = []304 for iface in iface_releases:305 if iface.needs_wrapping:306 appender = PPKind.ChoosePPFunc(iface,307 ppb_wrapper_infos.append,308 ppp_wrapper_infos.append)309 appender(' &%s' % self.GetWrapperInfoName(iface))310 ppb_wrapper_infos.append(' NULL')311 ppp_wrapper_infos.append(' NULL')312 out.Write(313 'static struct %s *s_ppb_wrappers[] = {\n%s\n};\n\n' %314 (self.GetWrapperMetadataName(), ',\n'.join(ppb_wrapper_infos)))315 out.Write(316 'static struct %s *s_ppp_wrappers[] = {\n%s\n};\n\n' %317 (self.GetWrapperMetadataName(), ',\n'.join(ppp_wrapper_infos)))318 def DeclareWrapperInfos(self, iface_releases, out):319 """The wrapper methods usually need access to the real_iface, so we must320 declare these wrapper infos ahead of time (there is a circular dependency).321 """322 out.Write('/* BEGIN Declarations for all Wrapper Infos */\n\n')323 for iface in iface_releases:324 if iface.needs_wrapping:325 out.Write('static struct %s %s;\n' %326 (self.GetWrapperMetadataName(),327 self.GetWrapperInfoName(iface)))328 out.Write('/* END Declarations for all Wrapper Infos. */\n\n')329 def GenerateRange(self, ast, releases, options):330 """Generate shim code for a range of releases.331 """332 # Remember to set the output filename before running this.333 out_filename = self.output_file334 if out_filename is None:335 ErrOut.Log('Did not set filename for writing out wrapper\n')336 return 1337 InfoOut.Log("Generating %s for %s" % (out_filename, self.wrapper_prefix))338 out = IDLOutFile(out_filename)339 # Get a list of all the interfaces along with metadata.340 iface_releases = self.DetermineInterfaces(ast, releases)341 # Generate the includes.342 self.GenerateIncludes(iface_releases, out)343 # Write out static helper functions (mystrcmp).344 self.GenerateHelperFunctions(out)345 # Declare list of WrapperInfo before actual wrapper methods, since346 # they reference each other.347 self.DeclareWrapperInfos(iface_releases, out)348 # Generate wrapper functions for each wrapped method in the interfaces.349 result = self.GenerateWrapperForMethods(iface_releases)350 out.Write(result)351 # Collect all the wrapper functions into interface structs.352 self.GenerateWrapperInterfaces(iface_releases, out)353 # Generate a table of the wrapped interface structs that can be looked up.354 self.GenerateWrapperInfoAndCollection(iface_releases, out)355 # Write out the IDL-invariant functions.356 self.GenerateFixedFunctions(out)357 out.Close()...

Full Screen

Full Screen

caching-client-wrapper.ts

Source:caching-client-wrapper.ts Github

copy

Full Screen

1import * as chai from 'chai';2import { default as sinon } from 'ts-sinon';3import * as sinonChai from 'sinon-chai';4import 'mocha';5import { CachingClientWrapper } from '../../src/client/caching-client-wrapper';6chai.use(sinonChai);7describe('CachingClientWrapper', () => {8 const expect = chai.expect;9 let cachingClientWrapperUnderTest: CachingClientWrapper;10 let clientWrapperStub: any;11 let redisClientStub: any;12 let idMap: any;13 beforeEach(() => {14 clientWrapperStub = {15 getContactByEmail: sinon.spy(),16 getContactById: sinon.spy(),17 getContactListById: sinon.spy(),18 getContactsInContactListById: sinon.spy(),19 deleteContactByEmail: sinon.spy(),20 deleteContactById: sinon.spy(),21 findWorkflowByName: sinon.spy(),22 createOrUpdateContact: sinon.spy(),23 updateContactById: sinon.spy(),24 enrollContactToWorkflow: sinon.spy(),25 currentContactWorkflows: sinon.spy(),26 isDate: sinon.spy(),27 toDate: sinon.spy(),28 toEpoch: sinon.spy(),29 };30 redisClientStub = {31 get: sinon.spy(),32 setex: sinon.spy(),33 del: sinon.spy(),34 };35 idMap = {36 requestId: '1',37 scenarioId: '2',38 requestorId: '3',39 };40 });41 it('getContactByEmail using original function', (done) => {42 const expectedEmail = 'test@example.com';43 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);44 cachingClientWrapperUnderTest.getAsync = sinon.stub().returns(false);45 cachingClientWrapperUnderTest.getContactByEmail(expectedEmail);46 setTimeout(() => {47 expect(clientWrapperStub.getContactByEmail).to.have.been.calledWith(expectedEmail);48 done();49 });50 });51 it('getContactByEmail using cache', (done) => {52 const expectedEmail = 'test@example.com';53 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);54 cachingClientWrapperUnderTest.getAsync = sinon.stub().returns('"expectedCachedValue"');55 let actualCachedValue: string;56 (async () => {57 actualCachedValue = await cachingClientWrapperUnderTest.getContactByEmail(expectedEmail);58 })();59 setTimeout(() => {60 expect(clientWrapperStub.getContactByEmail).to.not.have.been.called;61 expect(actualCachedValue).to.equal('expectedCachedValue');62 done();63 });64 });65 it('getContactById using original function', (done) => {66 const expectedId = 'test@example.com';67 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);68 cachingClientWrapperUnderTest.getAsync = sinon.stub().returns(false);69 cachingClientWrapperUnderTest.getContactById(expectedId);70 setTimeout(() => {71 expect(clientWrapperStub.getContactById).to.have.been.calledWith(expectedId);72 done();73 });74 });75 it('getContactById using cache', (done) => {76 const expectedId = 'test@example.com';77 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);78 cachingClientWrapperUnderTest.getAsync = sinon.stub().returns('"expectedCachedValue"');79 let actualCachedValue: string;80 (async () => {81 actualCachedValue = await cachingClientWrapperUnderTest.getContactById(expectedId);82 })();83 setTimeout(() => {84 expect(clientWrapperStub.getContactById).to.not.have.been.called;85 expect(actualCachedValue).to.equal('expectedCachedValue');86 done();87 });88 });89 it('getContactsInContactListById using original function', (done) => {90 const expectedId = '123123';91 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);92 cachingClientWrapperUnderTest.getAsync = sinon.stub().returns(false);93 cachingClientWrapperUnderTest.getContactsInContactListById(expectedId);94 setTimeout(() => {95 expect(clientWrapperStub.getContactsInContactListById).to.have.been.calledWith(expectedId);96 done();97 });98 });99 it('getContactsInContactListById using cache', (done) => {100 const expectedId = '123123';101 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);102 cachingClientWrapperUnderTest.getAsync = sinon.stub().returns('"expectedCachedValue"');103 let actualCachedValue: string;104 (async () => {105 actualCachedValue = await cachingClientWrapperUnderTest.getContactsInContactListById(expectedId);106 })();107 setTimeout(() => {108 expect(clientWrapperStub.getContactsInContactListById).to.not.have.been.called;109 expect(actualCachedValue).to.equal('expectedCachedValue');110 done();111 });112 });113 it('deleteContactByEmail', (done) => {114 const expectedEmail = 'test@example.com';115 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);116 cachingClientWrapperUnderTest.clearCache = sinon.spy();117 cachingClientWrapperUnderTest.deleteContactByEmail(expectedEmail);118 setTimeout(() => {119 expect(cachingClientWrapperUnderTest.clearCache).to.have.been.called;120 expect(clientWrapperStub.deleteContactByEmail).to.have.been.calledWith(expectedEmail);121 done();122 });123 });124 it('deleteContactById', (done) => {125 const expectedId = 'test@example.com';126 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);127 cachingClientWrapperUnderTest.clearCache = sinon.spy();128 cachingClientWrapperUnderTest.deleteContactById(expectedId);129 setTimeout(() => {130 expect(cachingClientWrapperUnderTest.clearCache).to.have.been.called;131 expect(clientWrapperStub.deleteContactById).to.have.been.calledWith(expectedId);132 done();133 });134 });135 it('findWorkflowByName using original function', (done) => {136 const name = 'anyName';137 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);138 cachingClientWrapperUnderTest.getAsync = sinon.stub().returns(false);139 cachingClientWrapperUnderTest.findWorkflowByName(name);140 setTimeout(() => {141 expect(clientWrapperStub.findWorkflowByName).to.have.been.calledWith(name);142 done();143 });144 });145 it('findWorkflowByName using cache', (done) => {146 const name = 'anyName';147 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);148 cachingClientWrapperUnderTest.getAsync = sinon.stub().returns('"expectedCachedValue"');149 let actualCachedValue: any;150 (async () => {151 actualCachedValue = await cachingClientWrapperUnderTest.findWorkflowByName(name);152 })();153 setTimeout(() => {154 expect(clientWrapperStub.findWorkflowByName).to.not.have.been.called;155 expect(actualCachedValue).to.equal('expectedCachedValue');156 done();157 });158 });159 it('createOrUpdateContact using original function', (done) => {160 const exampleObj = {a: 1};161 const email = 'any@anyEmail.com'162 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);163 cachingClientWrapperUnderTest.clearCache = sinon.spy();164 cachingClientWrapperUnderTest.createOrUpdateContact(email, exampleObj);165 setTimeout(() => {166 expect(cachingClientWrapperUnderTest.clearCache).to.have.been.called;167 expect(clientWrapperStub.createOrUpdateContact).to.have.been.calledWith(email, exampleObj);168 done();169 });170 })171 it('updateContactById using original function', (done) => {172 const exampleObj = {a: 1};173 const id = 'any@anyEmail.com'174 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);175 cachingClientWrapperUnderTest.clearCache = sinon.spy();176 cachingClientWrapperUnderTest.updateContactById(id, exampleObj);177 setTimeout(() => {178 expect(cachingClientWrapperUnderTest.clearCache).to.have.been.called;179 expect(clientWrapperStub.updateContactById).to.have.been.calledWith(id, exampleObj);180 done();181 });182 })183 it('getCache', (done) => {184 redisClientStub.get = sinon.stub().yields();185 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);186 cachingClientWrapperUnderTest.getCache('expectedKey');187 setTimeout(() => {188 expect(redisClientStub.get).to.have.been.calledWith('expectedKey');189 done();190 });191 });192 it('setCache', (done) => {193 redisClientStub.setex = sinon.stub().yields(); 194 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);195 cachingClientWrapperUnderTest.getCache = sinon.stub().returns(null);196 cachingClientWrapperUnderTest.cachePrefix = 'testPrefix';197 cachingClientWrapperUnderTest.setCache('expectedKey', 'expectedValue');198 setTimeout(() => {199 expect(redisClientStub.setex).to.have.been.calledWith('expectedKey', 55, '"expectedValue"');200 expect(redisClientStub.setex).to.have.been.calledWith('cachekeys|testPrefix', 55, '["expectedKey"]');201 done();202 });203 });204 it('delCache', (done) => {205 redisClientStub.del = sinon.stub().yields();206 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);207 cachingClientWrapperUnderTest.delCache('expectedKey');208 setTimeout(() => {209 expect(redisClientStub.del).to.have.been.calledWith('expectedKey');210 done();211 });212 });213 it('clearCache', (done) => {214 redisClientStub.del = sinon.stub().yields();215 cachingClientWrapperUnderTest = new CachingClientWrapper(clientWrapperStub, redisClientStub, idMap);216 cachingClientWrapperUnderTest.cachePrefix = 'testPrefix';217 cachingClientWrapperUnderTest.getCache = sinon.stub().returns(['testKey1', 'testKey2'])218 cachingClientWrapperUnderTest.clearCache();219 setTimeout(() => {220 expect(redisClientStub.del).to.have.been.calledWith('testKey1');221 expect(redisClientStub.del).to.have.been.calledWith('testKey2');222 expect(redisClientStub.setex).to.have.been.calledWith('cachekeys|testPrefix');223 done();224 });225 });...

Full Screen

Full Screen

rnn_cell_wrapper_v2_test.py

Source:rnn_cell_wrapper_v2_test.py Github

copy

Full Screen

...91 def testWrapperKerasStyle(self, wrapper, wrapper_v2):92 """Tests if wrapper cell is instantiated in keras style scope."""93 wrapped_cell_v2 = wrapper_v2(rnn_cell_impl.BasicRNNCell(1))94 self.assertIsNone(getattr(wrapped_cell_v2, "_keras_style", None))95 wrapped_cell = wrapper(rnn_cell_impl.BasicRNNCell(1))96 self.assertFalse(wrapped_cell._keras_style)97 @parameterized.parameters(98 [rnn_cell_wrapper_v2.DropoutWrapper, rnn_cell_wrapper_v2.ResidualWrapper])99 def testWrapperWeights(self, wrapper):100 """Tests that wrapper weights contain wrapped cells weights."""101 base_cell = layers.SimpleRNNCell(1, name="basic_rnn_cell")102 rnn_cell = wrapper(base_cell)103 rnn_layer = layers.RNN(rnn_cell)104 inputs = ops.convert_to_tensor_v2([[[1]]], dtype=dtypes.float32)105 rnn_layer(inputs)106 wrapper_name = generic_utils.to_snake_case(wrapper.__name__)107 expected_weights = ["rnn/" + wrapper_name + "/" + var for var in108 ("kernel:0", "recurrent_kernel:0", "bias:0")]109 self.assertLen(rnn_cell.weights, 3)110 self.assertCountEqual([v.name for v in rnn_cell.weights], expected_weights)111 self.assertCountEqual([v.name for v in rnn_cell.trainable_variables],112 expected_weights)113 self.assertCountEqual([v.name for v in rnn_cell.non_trainable_variables],114 [])115 self.assertCountEqual([v.name for v in rnn_cell.cell.weights],116 expected_weights)117 @parameterized.parameters(118 [rnn_cell_wrapper_v2.DropoutWrapper, rnn_cell_wrapper_v2.ResidualWrapper])119 def testWrapperV2Caller(self, wrapper):120 """Tests that wrapper V2 is using the LayerRNNCell's caller."""121 with base_layer.keras_style_scope():122 base_cell = rnn_cell_impl.MultiRNNCell(123 [rnn_cell_impl.BasicRNNCell(1) for _ in range(2)])124 rnn_cell = wrapper(base_cell)125 inputs = ops.convert_to_tensor_v2([[1]], dtype=dtypes.float32)126 state = ops.convert_to_tensor_v2([[1]], dtype=dtypes.float32)127 _ = rnn_cell(inputs, [state, state])128 weights = base_cell._cells[0].weights129 self.assertLen(weights, expected_len=2)130 self.assertTrue(all("_wrapper" in v.name for v in weights))131 @parameterized.parameters(132 [rnn_cell_wrapper_v2.DropoutWrapper, rnn_cell_wrapper_v2.ResidualWrapper])133 def testWrapperV2Build(self, wrapper):134 cell = rnn_cell_impl.LSTMCell(10)135 wrapper = wrapper(cell)136 wrapper.build((1,))137 self.assertTrue(cell.built)138 def testDeviceWrapperSerialization(self):139 wrapper_cls = rnn_cell_wrapper_v2.DeviceWrapper140 cell = layers.LSTMCell(10)141 wrapper = wrapper_cls(cell, "/cpu:0")142 config = wrapper.get_config()143 reconstructed_wrapper = wrapper_cls.from_config(config)144 self.assertDictEqual(config, reconstructed_wrapper.get_config())145 self.assertIsInstance(reconstructed_wrapper, wrapper_cls)146 def testResidualWrapperSerialization(self):147 wrapper_cls = rnn_cell_wrapper_v2.ResidualWrapper148 cell = layers.LSTMCell(10)149 wrapper = wrapper_cls(cell)...

Full Screen

Full Screen

button.py

Source:button.py Github

copy

Full Screen

1"""Button for Shelly."""2from __future__ import annotations3from collections.abc import Callable4from dataclasses import dataclass5from typing import Final, cast6from homeassistant.components.button import (7 ButtonDeviceClass,8 ButtonEntity,9 ButtonEntityDescription,10)11from homeassistant.config_entries import ConfigEntry12from homeassistant.core import HomeAssistant13from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC14from homeassistant.helpers.entity import DeviceInfo, EntityCategory15from homeassistant.helpers.entity_platform import AddEntitiesCallback16from homeassistant.util import slugify17from . import BlockDeviceWrapper, RpcDeviceWrapper18from .const import BLOCK, DATA_CONFIG_ENTRY, DOMAIN, RPC, SHELLY_GAS_MODELS19from .utils import get_block_device_name, get_device_entry_gen, get_rpc_device_name20@dataclass21class ShellyButtonDescriptionMixin:22 """Mixin to describe a Button entity."""23 press_action: Callable24@dataclass25class ShellyButtonDescription(ButtonEntityDescription, ShellyButtonDescriptionMixin):26 """Class to describe a Button entity."""27 supported: Callable = lambda _: True28BUTTONS: Final = [29 ShellyButtonDescription(30 key="ota_update",31 name="OTA Update",32 device_class=ButtonDeviceClass.UPDATE,33 entity_category=EntityCategory.CONFIG,34 press_action=lambda wrapper: wrapper.async_trigger_ota_update(),35 ),36 ShellyButtonDescription(37 key="ota_update_beta",38 name="OTA Update Beta",39 device_class=ButtonDeviceClass.UPDATE,40 entity_registry_enabled_default=False,41 entity_category=EntityCategory.CONFIG,42 press_action=lambda wrapper: wrapper.async_trigger_ota_update(beta=True),43 ),44 ShellyButtonDescription(45 key="reboot",46 name="Reboot",47 device_class=ButtonDeviceClass.RESTART,48 entity_category=EntityCategory.CONFIG,49 press_action=lambda wrapper: wrapper.device.trigger_reboot(),50 ),51 ShellyButtonDescription(52 key="self_test",53 name="Self Test",54 icon="mdi:progress-wrench",55 entity_category=EntityCategory.DIAGNOSTIC,56 press_action=lambda wrapper: wrapper.device.trigger_shelly_gas_self_test(),57 supported=lambda wrapper: wrapper.device.model in SHELLY_GAS_MODELS,58 ),59 ShellyButtonDescription(60 key="mute",61 name="Mute",62 icon="mdi:volume-mute",63 entity_category=EntityCategory.CONFIG,64 press_action=lambda wrapper: wrapper.device.trigger_shelly_gas_mute(),65 supported=lambda wrapper: wrapper.device.model in SHELLY_GAS_MODELS,66 ),67 ShellyButtonDescription(68 key="unmute",69 name="Unmute",70 icon="mdi:volume-high",71 entity_category=EntityCategory.CONFIG,72 press_action=lambda wrapper: wrapper.device.trigger_shelly_gas_unmute(),73 supported=lambda wrapper: wrapper.device.model in SHELLY_GAS_MODELS,74 ),75]76async def async_setup_entry(77 hass: HomeAssistant,78 config_entry: ConfigEntry,79 async_add_entities: AddEntitiesCallback,80) -> None:81 """Set buttons for device."""82 wrapper: RpcDeviceWrapper | BlockDeviceWrapper | None = None83 if get_device_entry_gen(config_entry) == 2:84 if rpc_wrapper := hass.data[DOMAIN][DATA_CONFIG_ENTRY][85 config_entry.entry_id86 ].get(RPC):87 wrapper = cast(RpcDeviceWrapper, rpc_wrapper)88 else:89 if block_wrapper := hass.data[DOMAIN][DATA_CONFIG_ENTRY][90 config_entry.entry_id91 ].get(BLOCK):92 wrapper = cast(BlockDeviceWrapper, block_wrapper)93 if wrapper is not None:94 entities = []95 for button in BUTTONS:96 if not button.supported(wrapper):97 continue98 entities.append(ShellyButton(wrapper, button))99 async_add_entities(entities)100class ShellyButton(ButtonEntity):101 """Defines a Shelly base button."""102 entity_description: ShellyButtonDescription103 def __init__(104 self,105 wrapper: RpcDeviceWrapper | BlockDeviceWrapper,106 description: ShellyButtonDescription,107 ) -> None:108 """Initialize Shelly button."""109 self.entity_description = description110 self.wrapper = wrapper111 if isinstance(wrapper, RpcDeviceWrapper):112 device_name = get_rpc_device_name(wrapper.device)113 else:114 device_name = get_block_device_name(wrapper.device)115 self._attr_name = f"{device_name} {description.name}"116 self._attr_unique_id = slugify(self._attr_name)117 self._attr_device_info = DeviceInfo(118 connections={(CONNECTION_NETWORK_MAC, wrapper.mac)}119 )120 async def async_press(self) -> None:121 """Triggers the Shelly button press service."""...

Full Screen

Full Screen

Collapses.test.js

Source:Collapses.test.js Github

copy

Full Screen

1import React from 'react';2import ReactDOM from 'react-dom';3import Collapses from './Collapses';4import {mount} from 'enzyme/build';5it('renders without crashing', () => {6 const div = document.createElement('div');7 ReactDOM.render(<Collapses />, div);8 ReactDOM.unmountComponentAtNode(div);9});10describe('toggle clicks', function() {11 it('collapse without crashing', () => {12 const wrapper = mount(<Collapses />);13 let collapse = wrapper.find('#toggleCollapse1').at(0);14 collapse.simulate('click');15 expect(wrapper.state().collapse).toEqual(true);16 collapse.simulate('click');17 expect(wrapper.state().collapse).toEqual(false);18 collapse.simulate('click');19 expect(wrapper.state().collapse).toEqual(true);20 wrapper.unmount()21 });22 it('fade without crashing', () => {23 const wrapper = mount(<Collapses />);24 let fade = wrapper.find('#toggleFade1').at(0);25 fade.simulate('click');26 expect(wrapper.state().fadeIn).toEqual(false);27 fade.simulate('click');28 expect(wrapper.state().fadeIn).toEqual(true);29 wrapper.unmount()30 });31 it('accordion without crashing', () => {32 const wrapper = mount(<Collapses />);33 let accordion = wrapper.find('[aria-controls="collapseOne"]').at(0);34 accordion.simulate('click');35 expect(wrapper.state().accordion[0]).toEqual(false);36 expect(wrapper.state().accordion[1]).toEqual(false);37 expect(wrapper.state().accordion[2]).toEqual(false);38 accordion = wrapper.find('[aria-controls="collapseTwo"]').at(0);39 accordion.simulate('click');40 expect(wrapper.state().accordion[0]).toEqual(false);41 expect(wrapper.state().accordion[1]).toEqual(true);42 expect(wrapper.state().accordion[2]).toEqual(false);43 accordion = wrapper.find('[aria-controls="collapseThree"]').at(0);44 accordion.simulate('click');45 expect(wrapper.state().accordion[0]).toEqual(false);46 expect(wrapper.state().accordion[1]).toEqual(false);47 expect(wrapper.state().accordion[2]).toEqual(true);48 accordion = wrapper.find('[aria-controls="collapseOne"]').at(0);49 accordion.simulate('click');50 expect(wrapper.state().accordion[0]).toEqual(true);51 expect(wrapper.state().accordion[1]).toEqual(false);52 expect(wrapper.state().accordion[2]).toEqual(false);53 wrapper.unmount()54 });55 it('custom without crashing', () => {56 const wrapper = mount(<Collapses />);57 let accordion = wrapper.find('[aria-controls="exampleAccordion1"]').at(0);58 accordion.simulate('click');59 expect(wrapper.state().custom[0]).toEqual(false);60 expect(wrapper.state().custom[1]).toEqual(false);61 accordion = wrapper.find('[aria-controls="exampleAccordion1"]').at(0);62 accordion.simulate('click');63 expect(wrapper.state().custom[0]).toEqual(true);64 expect(wrapper.state().custom[1]).toEqual(false);65 accordion = wrapper.find('[aria-controls="exampleAccordion2"]').at(0);66 accordion.simulate('click');67 expect(wrapper.state().custom[0]).toEqual(false);68 expect(wrapper.state().custom[1]).toEqual(true);69 wrapper.unmount()70 });...

Full Screen

Full Screen

functools.py

Source:functools.py Github

copy

Full Screen

...6# Written by Nick Coghlan <ncoghlan at gmail.com>7# Copyright (C) 2006 Python Software Foundation.8# See C source code for _functools credits/copyright9from _functools import partial, reduce10# update_wrapper() and wraps() are tools to help write11# wrapper functions that can handle naive introspection12WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__')13WRAPPER_UPDATES = ('__dict__',)14def update_wrapper(wrapper,15 wrapped,16 assigned = WRAPPER_ASSIGNMENTS,17 updated = WRAPPER_UPDATES):18 """Update a wrapper function to look like the wrapped function19 wrapper is the function to be updated20 wrapped is the original function21 assigned is a tuple naming the attributes assigned directly22 from the wrapped function to the wrapper function (defaults to23 functools.WRAPPER_ASSIGNMENTS)24 updated is a tuple naming the attributes of the wrapper that25 are updated with the corresponding attribute from the wrapped26 function (defaults to functools.WRAPPER_UPDATES)27 """28 for attr in assigned:29 setattr(wrapper, attr, getattr(wrapped, attr))30 for attr in updated:31 getattr(wrapper, attr).update(getattr(wrapped, attr, {}))32 # Return the wrapper so this can be used as a decorator via partial()33 return wrapper34def wraps(wrapped,35 assigned = WRAPPER_ASSIGNMENTS,36 updated = WRAPPER_UPDATES):37 """Decorator factory to apply update_wrapper() to a wrapper function38 Returns a decorator that invokes update_wrapper() with the decorated39 function as the wrapper argument and the arguments to wraps() as the40 remaining arguments. Default arguments are as for update_wrapper().41 This is a convenience function to simplify applying partial() to42 update_wrapper().43 """44 return partial(update_wrapper, wrapped=wrapped,...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import withRootDecorator from 'storybook-root-decorator'2import { withRootDecorator } from 'storybook-addon-root-decorator'3import withRootDecorator from 'storybook-decorator-root'4import { withRootDecorator } from 'storybook-decorator-root'5import withRootDecorator from 'storybook-root-decorator'6import { withRootDecorator } from 'storybook-addon-root-decorator'7import withRootDecorator from 'storybook-decorator-root'8import { withRootDecorator } from 'storybook-decorator-root'9import withRootDecorator from 'storybook-root-decorator'10import { withRootDecorator } from 'storybook-addon-root-decorator'11import withRootDecorator from 'storybook-decorator-root'12import { withRootDecorator } from 'storybook-decorator-root'13import withRootDecorator from 'storybook-root-decorator'14import { withRootDecorator } from 'storybook-addon-root-decorator'15import withRootDecorator from 'storybook-decorator-root'16import { withRootDecorator } from 'storybook-decorator-root'17import withRootDecorator from 'storybook-root-decorator'18import { withRootDecorator } from 'storybook-addon-root-decorator'

Full Screen

Using AI Code Generation

copy

Full Screen

1import { withRootDecorator } from 'storybook-root-decorator';2import { withInfo } from '@storybook/addon-info';3import { withKnobs } from '@storybook/addon-knobs';4import { storiesOf } from '@storybook/react';5import { action } from '@storybook/addon-actions';6import Button from './Button';7const stories = storiesOf('Button', module);8stories.addDecorator(withInfo);9stories.addDecorator(withKnobs);10stories.addDecorator(withRootDecorator);11stories.add('with text', () => (12 <Button onClick={action('clicked')}>Hello Button</Button>13));14stories.add('with some emoji', () => (15 <Button onClick={action('clicked')}>πŸ˜€ 😎 πŸ‘ πŸ’―</Button>16));17stories.add('with some emoji and info', () => (18 <Button onClick={action('clicked')}>πŸ˜€ 😎 πŸ‘ πŸ’―</Button>19), {20 info: {21 },22});23stories.add('with some emoji and info and knobs', () => (24 <Button onClick={action('clicked')}>πŸ˜€ 😎 πŸ‘ πŸ’―</Button>25), {26 info: {27 },28});29import { withRootDecorator } from 'storybook-root-decorator';30export const decorators = [withRootDecorator];31import { withRootDecorator } from 'storybook-root-decorator';32withRootDecorator({33});34import { withRootDecorator } from 'storybook-root-decorator';35import { withInfo } from '@storybook/addon-info';36import { withKnobs } from '@storybook/addon-knobs';37withRootDecorator({38 rootDecorator: story => withInfo()(withKnobs()(story)),39});40import { withRootDecorator } from 'storybook-root-decorator';41import { withInfo } from '@storybook/addon-info';42import { withKnobs } from '@storybook/addon-knobs';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { addDecorator } from '@storybook/react';2import { withRoot } from 'storybook-root-decorator';3addDecorator(withRoot);4import { addDecorator } from '@storybook/react';5import { withRoot } from 'storybook-root-decorator';6addDecorator(withRoot);7import { addDecorator } from '@storybook/react';8import { withRoot } from 'storybook-root-decorator';9addDecorator(withRoot);10import { addDecorator } from '@storybook/react';11import { withRoot } from 'storybook-root-decorator';12addDecorator(withRoot);13MIT Β© [siddharthkp](

Full Screen

Using AI Code Generation

copy

Full Screen

1import { withRootDecorator } from 'storybook-root-decorator';2import { ThemeProvider } from 'styled-components';3import theme from '../src/theme';4 withRootDecorator(ThemeProvider, { theme }),5];6MIT Β© [siddharthkp](

Full Screen

Using AI Code Generation

copy

Full Screen

1import { withRootDecorator } from 'storybook-root-decorator'2export default {3}4import React from 'react';5import { storiesOf } from '@storybook/react';6import { withRootDecorator } from 'storybook-root-decorator'7storiesOf('Welcome', module)8 .addDecorator(withRootDecorator)9 .add('to Storybook', () => <div>Hello</div>);10import React from 'react';11import { storiesOf } from '@storybook/react';12import { withRootDecorator } from 'storybook-root-decorator'13storiesOf('Welcome', module)14 .addDecorator(withRootDecorator)15 .add('to Storybook', () => <div>Hello</div>);16import React from 'react';17import { storiesOf } from '@storybook/react';18import { withRootDecorator } from 'storybook-root-decorator'19storiesOf('Welcome', module)20 .addDecorator(withRootDecorator)21 .add('to Storybook', () => <div>Hello</div>);22import React from 'react';23import { storiesOf } from '@storybook/react';24import { withRootDecorator } from 'storybook-root-decorator'25storiesOf('Welcome', module)26 .addDecorator(withRootDecorator)27 .add('to Storybook', () => <div>Hello</div>);28import React from 'react';29import { storiesOf } from '@storybook/react';30import { withRootDecorator } from 'storybook-root-decorator'31storiesOf('Welcome', module)32 .addDecorator(withRootDecorator)33 .add('to Storybook', () => <div>Hello</div>);34import React from 'react';35import { storiesOf } from '@storybook/react';36import { withRootDecorator }

Full Screen

Using AI Code Generation

copy

Full Screen

1import { withRoot } from "storybook-root-wrapper";2import { configure } from "@storybook/react";3import { addDecorator } from "@storybook/react";4import { addParameters } from "@storybook/react";5import { themes } from "@storybook/theming";6addDecorator(withRoot);7addParameters({8 options: {9 },10});11function loadStories() {12 require("../src/stories");13}14configure(loadStories, module);15module.exports = {16};17Then, in your `gatsby-browser.js` file, import the `withRoot` function from `storybook-root-wrapper` and wrap your `wrapRootElement` function with it:18import React from "react";19import { withRoot } from "storybook-root-wrapper";20export const wrapRootElement = withRoot(({ element }) => <>{element}</>);21module.exports = {22 webpack: (config, options) => {23 config.plugins.push(24 new options.webpack.DefinePlugin({25 "process.env.NODE_ENV": JSON.stringify(26 })27 );28 return config;29 },30};31Then, in your `_app.js` file, import the `withRoot` function from `storybook-root-wrapper` and wrap your `App` component with it:32import React from "react";33import { withRoot } from "storybook-root-wrapper";34function App({ Component, pageProps }) {35 return <Component {...pageProps} />;36}37export default withRoot(App);38import React from "react";39import ReactDOM from "react-dom";40import { withRoot } from "storybook-root-wrapper";41import "./index.css";42import App from "./App";43const Root = withRoot(({ children }) => <>{children

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderStory } from 'storybook-root'2import { stories } from './stories'3stories.forEach(story => {4 renderStory(story)5})6import { storiesOf } from '@storybook/react'7import React from 'react'8import { Button } from 'antd'9 {10 story: () => (11 }12stories.forEach(story => {13 storiesOf(story.name, module).add(story.name, story.story)14})15import { configure } from '@storybook/react'16import '../stories'17const req = require.context('../stories', true, /.stories.js$/)18function loadStories() {19 req.keys().forEach(filename => req(filename))20}21configure(loadStories, module)22module.exports = (baseConfig, env, defaultConfig) => {23 defaultConfig.module.rules.push({24 test: /\.(js|jsx)$/,25 use: {26 options: {27 }28 }29 })30 defaultConfig.resolve.extensions.push('.js', '.jsx')31}32import '@storybook/addon-actions/register'33import '@storybook/addon-links/register'34import '@storybook/addon-knobs/register'35import React from 'react'36import { withKnobs } from '@storybook/addon-knobs/react'

Full Screen

Using AI Code Generation

copy

Full Screen

1import 'storybook-root';2import { shallow, mount } from 'enzyme';3import React from 'react';4import { MyComponent } from './MyComponent';5describe('MyComponent', () => {6 it('renders without crashing', () => {7 const wrapper = shallow(<MyComponent />);8 expect(wrapper).toMatchSnapshot();9 });10});11import { configure } from '@storybook/react';12configure(require.context('../src', true, /\.stories\.js$/), module);13const path = require('path');14const rootPath = path.resolve(__dirname, '../');15module.exports = {16 resolve: {17 },18};19{20 "dependencies": {21 },22 "devDependencies": {23 },24 "scripts": {25 }26}

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 storybook-root 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