Best JavaScript code snippet using storybook-root
parse-expression.js
Source:parse-expression.js
...266 if (!vs.includes(actual)) { console.trace(`Assertion failed.\n>>Expected one of ${vs}\n>>Actual: ${actual}`) }267 }268 let {evalParamFrame,preEvalParam} = require('player/eval-param')269 let ev = (i,c,d) => {return{idx:i, count:c, dur:d, _time:c, endTime:c+d, countToTime:x=>x}}270 assert(undefined, parseExpression())271 assert(undefined, parseExpression(''))272 assert(1, parseExpression('1'))273 assert(123, parseExpression('123'))274 assert(1.1, parseExpression('1.1'))275 assert(.123, parseExpression('.123'))276 assert(-1, parseExpression('-1'))277 assert(1e9, parseExpression('1e9'))278 279 assert(1, parseExpression('[1,2]')(ev(0),0,evalParamFrame))280 assert(2, parseExpression('[1,2]')(ev(1),0,evalParamFrame))281 assert(1, parseExpression('[1,2]')(ev(2),0,evalParamFrame))282 assert(1, evalParamFrame(parseExpression('[[1,2]]'),ev(0),0))283 assert(2, evalParamFrame(parseExpression('[[1,2]]'),ev(1),0))284 assert(1, evalParamFrame(parseExpression('[[1,2]]'),ev(2),0))285 assert(1, parseExpression('[1:3]')(ev(0),0,evalParamFrame))286 assert(3, parseExpression('[1:3]')(ev(1),0,evalParamFrame))287 assert(1, parseExpression('(1)'))288 let p289 p = parseExpression('(1,2)')290 assert([1,2], p)291 p = parseExpression('[1,(2,3)]')292 assert(1, p(ev(0),0,evalParamFrame))293 assert([2,3], p(ev(1),1,evalParamFrame))294 p = parseExpression('[(1,2,3),4,(5,6)]')295 assert([1,2,3], p(ev(0),0,evalParamFrame))296 assert(4, p(ev(1),1,evalParamFrame))297 assert([5,6], p(ev(2),2,evalParamFrame))298 assert([1,2,3], p(ev(3),3,evalParamFrame))299 assert(3, parseExpression('1+2'))300 assert(6, parseExpression('1+2+3'))301 p = parseExpression('[1,2]T1@f')302 assert(1, p(ev(0),0,evalParamFrame))303 assert(1, p(ev(0),1/2,evalParamFrame))304 assert(2, p(ev(0),1,evalParamFrame))305 assert(2, p(ev(0),3/2,evalParamFrame))306 assert(1, p(ev(0),2,evalParamFrame))307 p = parseExpression('[1,2]T@f')308 assert(1, p(ev(0),0,evalParamFrame))309 assert(1, p(ev(0),3.9,evalParamFrame))310 assert(2, p(ev(0),4,evalParamFrame))311 p = parseExpression('[1,2,3]t[1,2]@f')312 assert(1, p(ev(0),0,evalParamFrame))313 assert(2, p(ev(0),1,evalParamFrame))314 assert(2, p(ev(0),2,evalParamFrame))315 assert(3, p(ev(0),3,evalParamFrame))316 assert(1, p(ev(0),4,evalParamFrame))317 p = parseExpression('[0:2]t1')318 assert(0, p(ev(0,0),0,evalParamFrame))319 assert(1, p(ev(1,1),1,evalParamFrame))320 assert(2, p(ev(2,2),2,evalParamFrame))321 assert(0, p(ev(3,3),3,evalParamFrame))322 p = parseExpression('[-1:1]t1')323 assert(-1, p(ev(0,0),0,evalParamFrame))324 assert(0, p(ev(1,1),1,evalParamFrame))325 assert(1, p(ev(2,2),2,evalParamFrame))326 assert(-1, p(ev(3,3),3,evalParamFrame))327 p = parseExpression('[0:[1,2]]t1')328 assert(0, p(ev(0,0),0,evalParamFrame))329 assert(1, p(ev(1,1),1,evalParamFrame))330 assert(0, p(ev(2,2),2,evalParamFrame))331 assert(0, p(ev(3,3),3,evalParamFrame))332 assert(0, p(ev(4,4),4,evalParamFrame))333 assert(2, p(ev(5,5),5,evalParamFrame))334 assert(0, p(ev(6,6),6,evalParamFrame))335 p = parseExpression('[0:[1,2]]t[1,2]')336 assert(0, p(ev(0,0),0,evalParamFrame))337 assert(1, p(ev(1,1),1,evalParamFrame))338 assert(1, p(ev(2,2),2,evalParamFrame))339 assert(2, p(ev(3,3),3,evalParamFrame))340 assert(1, p(ev(4,4),4,evalParamFrame))341 assert(1, p(ev(5,5),5,evalParamFrame))342 assert(0, p(ev(6,6),6,evalParamFrame))343 assert(2, p(ev(7,7),7,evalParamFrame))344 assert(1, p(ev(8,8),8,evalParamFrame))345 p = parseExpression('[(0,2),(1,3)]')346 assert([0,2], p(ev(0),0,evalParamFrame))347 assert([1,3], p(ev(1),1,evalParamFrame))348 p = parseExpression('[(0,2),(1,3)]T@f')349 assert([0,2], p(ev(0,0),0,evalParamFrame))350 assert([1,3], p(ev(4,4),4,evalParamFrame))351 p = parseExpression('[(0,2),(1,3)]l2@f')352 assert([0,2], evalParamFrame(p,ev(0,0),0))353 assert([0.5,2.5], evalParamFrame(p,ev(1,1),1))354 assert([1,3], evalParamFrame(p,ev(2,2),2))355 p = parseExpression('[0,(1,2)]l2@f')356 assert([0,0], evalParamFrame(p,ev(0,0),0))357 assert([0.5,1], evalParamFrame(p,ev(1,1),1))358 assert([1,2], evalParamFrame(p,ev(2,2),2))359 p = parseExpression('[(0,2),(1,3)]s2@f')360 assert([0,2], evalParamFrame(p,ev(0,0),0))361 assert([0.5,2.5], evalParamFrame(p,ev(1,1),1))362 assert([1,3], evalParamFrame(p,ev(2,2),2))363 vars.foo = 'bar'364 p = parseExpression('foo')365 vars.foo = 'baz'366 assert('baz', p({},0,(v)=>v))367 delete vars.foo368 vars['foo.woo'] = 'bar'369 p = parseExpression('foo.woo')370 assert('bar', p({},0,(v)=>v))371 vars['foo.woo'] = undefined372 vars['foo'] = 'bar'373 p = parseExpression('FoO')374 assert('bar', p({},0,(v)=>v))375 vars['foo'] = undefined376 vars.foo = 2377 p = parseExpression('[1,foo]')378 vars.foo = 3379 assert(1, evalParamFrame(p, ev(0),0))380 assert(3, evalParamFrame(p, ev(1),1))381 delete vars.foo382 p = parseExpression('-[1,2] ')383 assert(-1, p(ev(0),0, evalParamFrame))384 assert(-2, p(ev(1),1, evalParamFrame))385 p = parseExpression('-(1,2) ')(ev(0),0, evalParamFrame)386 assert([-1,-2], p)387 assert(-1, parseExpression('-(1)'))388 p = parseExpression('[1,2]+[3,4] ')389 assert(4, p(ev(0),0, evalParamFrame))390 assert(6, p(ev(1),1, evalParamFrame))391 assert(4, p(ev(2),2, evalParamFrame))392 p = parseExpression(' [ 1 , 2 ] + 3 ')393 assert(4, p(ev(0),0, evalParamFrame))394 assert(5, p(ev(1),1, evalParamFrame))395 assert(4, p(ev(2),2, evalParamFrame))396 p = parseExpression('1+[2,3]')397 assert(3, p(ev(0),0, evalParamFrame))398 assert(4, p(ev(1),1, evalParamFrame))399 assert(3, p(ev(2),2, evalParamFrame))400 p = parseExpression('[1,2,3]+[4,5] ')401 assert(5, p(ev(0),0, evalParamFrame))402 assert(7, p(ev(1),1, evalParamFrame))403 assert(7, p(ev(2),2, evalParamFrame))404 assert(6, p(ev(3),3, evalParamFrame))405 p = parseExpression('[1,2]t1@f+3 ')406 assert(4, p(ev(0),0, evalParamFrame))407 assert(5, p(ev(0),1, evalParamFrame))408 assert(4, p(ev(0),2, evalParamFrame))409 p = parseExpression('3+[1,2]t1@f ')410 assert(4, p(ev(0),0, evalParamFrame))411 assert(5, p(ev(0),1, evalParamFrame))412 assert(4, p(ev(0),2, evalParamFrame))413 p = parseExpression('[1,2]t1@f+[3,4]t1@f')414 assert(4, p(ev(0),0, evalParamFrame))415 assert(6, p(ev(0),1, evalParamFrame))416 assert(4, p(ev(0),2, evalParamFrame))417 p = parseExpression('2+foo+2')418 vars.foo = parseExpression('[1,2]t1@f')419 assert(5, p(ev(0),0, evalParamFrame))420 assert(6, p(ev(0),1, evalParamFrame))421 assert(5, p(ev(0),2, evalParamFrame))422 vars.foo = parseExpression('5')423 assert(9, p(ev(0),3, evalParamFrame))424 delete vars.foo425 p = parseExpression('[1,[2,3]t2@e]t1@f')426 assert(1, evalParamFrame(p,ev(0,0),0,evalParamFrame))427 assert(2, evalParamFrame(p,ev(0,0),1,evalParamFrame))428 assert(1, evalParamFrame(p,ev(0,0),2,evalParamFrame))429 assert(2, evalParamFrame(p,ev(0,0),3,evalParamFrame))430 assert(1, evalParamFrame(p,ev(0,0),0,evalParamFrame))431 assert(2, evalParamFrame(p,ev(1,1),1,evalParamFrame))432 assert(1, evalParamFrame(p,ev(2,2),2,evalParamFrame))433 assert(3, evalParamFrame(p,ev(3,3),3,evalParamFrame))434 435 p = parseExpression('[1,[2,3]t2@f]t1@e')436 assert(1, evalParamFrame(p,ev(0,0),0,evalParamFrame))437 assert(1, evalParamFrame(p,ev(0,0),1,evalParamFrame))438 assert(1, evalParamFrame(p,ev(0,0),2,evalParamFrame))439 assert(1, evalParamFrame(p,ev(0,0),3,evalParamFrame))440 assert(2, evalParamFrame(p,ev(1,1),0,evalParamFrame))441 assert(2, evalParamFrame(p,ev(1,1),1,evalParamFrame))442 assert(3, evalParamFrame(p,ev(1,1),2,evalParamFrame))443 assert(3, evalParamFrame(p,ev(1,1),3,evalParamFrame))444 445 p = parseExpression('[1,[2,3]t2@e]l1@f')446 assert(1, evalParamFrame(p,ev(0,0),0,evalParamFrame))447 assert(2, evalParamFrame(p,ev(0,0),1,evalParamFrame))448 assert(1, evalParamFrame(p,ev(0,0),2,evalParamFrame))449 assert(2, evalParamFrame(p,ev(0,0),3,evalParamFrame))450 assert(1, evalParamFrame(p,ev(0,0),0,evalParamFrame))451 assert(2, evalParamFrame(p,ev(1,1),1,evalParamFrame))452 assert(1, evalParamFrame(p,ev(2,2),2,evalParamFrame))453 assert(3, evalParamFrame(p,ev(3,3),3,evalParamFrame))454 p = parseExpression('[1,[2,3]l1@f]t2@e')455 assert(1, evalParamFrame(p,ev(0,0),0,evalParamFrame))456 assert(1, evalParamFrame(p,ev(0,0),1,evalParamFrame))457 assert(2, evalParamFrame(p,ev(2,2),2,evalParamFrame))458 assert(3, evalParamFrame(p,ev(2,2),3,evalParamFrame))459 460 let p2461 p = parseExpression('[1,[2,3]l1@f]t2@e')462 p2 = preEvalParam(p,ev(0,0),0,preEvalParam)463 assert(1, evalParamFrame(p2,ev(0,0),0,evalParamFrame))464 assert(1, evalParamFrame(p2,ev(0,0),1,evalParamFrame))465 p2 = preEvalParam(p,ev(2,2),0,preEvalParam)466 assert(2, evalParamFrame(p2,ev(2,2),2,evalParamFrame))467 assert(2.5, evalParamFrame(p2,ev(2,2),2.5,evalParamFrame))468 assert(3, evalParamFrame(p2,ev(2,2),3,evalParamFrame))469 470 assert([4,5], parseExpression('(1,2)+3')(ev(0),0, evalParamFrame))471 assert([4,5], parseExpression('3+(1,2)')(ev(0),0, evalParamFrame))472 assert([8,9], parseExpression('(1,2)+3+4 ')(ev(0),0, evalParamFrame))473 assert([11,12], parseExpression('1+2+(1,2)+3+4 ')(ev(0),0, evalParamFrame))474 assert([4,6], parseExpression('(1,2)+(3,4) ')(ev(0),0, evalParamFrame))475 assert([5,7,7], parseExpression('(1,2,3)+(4,5) ')(ev(0),0, evalParamFrame))476 assert([4,6,6], parseExpression('(1,2)+(3,4,5) ')(ev(0),0, evalParamFrame))477 assert(3, parseExpression('(1)+2'))478 assert(3, parseExpression('(1+2)'))479 assert(6, parseExpression('(1+2)+3'))480 p = parseExpression('[1,2]t1@f+(3,4) ')481 assert([4,5], p(ev(0),0,evalParamFrame))482 assert([5,6], p(ev(0),1,evalParamFrame))483 assert([4,5], p(ev(0),2,evalParamFrame))484 p = parseExpression('foo + (0,2)')485 vars.foo = parseExpression('[1,2]t1@f')486 assert([1,3], p(ev(0),0,evalParamFrame))487 assert([2,4], p(ev(1),1,evalParamFrame))488 delete vars.foo489 p = parseExpression('(foo,[3,4]t1@f)')490 vars.foo = parseExpression('1')491 assert([1,3], evalParamFrame(p,ev(0),0,evalParamFrame))492 assert([1,4], evalParamFrame(p,ev(1),1,evalParamFrame))493 delete vars.foo494 p = parseExpression('[2:8]l[1,0]@f')495 assert(2, evalParamFrame(p,ev(0,0,1),0,evalParamFrame))496 assert(5, evalParamFrame(p,ev(0,0,1),0.5,evalParamFrame))497 assert(2, evalParamFrame(p,ev(1,1,1),1,evalParamFrame))498 assert(5, evalParamFrame(p,ev(1,1,1),1.5,evalParamFrame))499 500 p = parseExpression('[1:[2:8]l[1,0]@f]l1@e')501 assert(1, evalParamFrame(p,ev(0,0,1),0,evalParamFrame))502 assert(1, evalParamFrame(p,ev(0,0,1),0.5,evalParamFrame))503 assert(2, evalParamFrame(p,ev(1,1,1),1,evalParamFrame))504 assert(5, evalParamFrame(p,ev(1,1,1),1.5,evalParamFrame))505 506 p = parseExpression('foo')507 vars.foo = parseExpression('[1:[2:8]l[1,0]@f]l1@e')508 assert(1, evalParamFrame(p,ev(0,0,1),0,evalParamFrame))509 assert(1, evalParamFrame(p,ev(0,0,1),0.5,evalParamFrame))510 assert(2, evalParamFrame(p,ev(1,1,1),1,evalParamFrame))511 assert(5, evalParamFrame(p,ev(1,1,1),1.5,evalParamFrame))512 delete vars.foo513 p = parseExpression('[1,2]+(3,4) ')514 assert([4,5], p(ev(0),0,evalParamFrame))515 assert([5,6], p(ev(1),1,evalParamFrame))516 assert([4,5], p(ev(2),2,evalParamFrame))517 assert(1/2, parseExpression('1/2'))518 assert(1/2, parseExpression('(1/2)'))519 assert([1,2], parseExpression('(2,4)/2')(ev(0),0,evalParamFrame))520 assert(1, parseExpression('[2,4]/2')(ev(0),0,evalParamFrame))521 assert(2, parseExpression('[2,4]/2')(ev(1),1,evalParamFrame))522 assert(4, parseExpression('2+4/2'))523 assert(3, parseExpression('(2+4)/2'))524 assert(4, parseExpression('4/2+2'))525 assert(1, parseExpression('4/(2+2)'))526 assert(10, parseExpression('2+4*2'))527 assert(12, parseExpression('(2+4)*2'))528 assert(16, parseExpression('4*(2+2)'))529 assert(10, parseExpression('4*2+2'))530 assert(33, parseExpression('1+2*3+4*5+6'))531 assert(77, parseExpression('1+2*(3+4)*5+6'))532 assert(157, parseExpression('1+(2*3+4*5)*6'))533 assert(4, parseExpression('2*2'))534 assert([2,4], parseExpression('(1,2)*2')(ev(0),0,evalParamFrame))535 assert(100, parseExpression('[1,2]*100')(ev(0),0,evalParamFrame))536 assert(200, parseExpression('[1,2]*100')(ev(1),1,evalParamFrame))537 assert(1, parseExpression('3%2'))538 assert([1,0], parseExpression('(5,6)%2')(ev(0),0,evalParamFrame))539 assert(2, parseExpression('[5,6]%3')(ev(0),0,evalParamFrame))540 assert(0, parseExpression('[5,6]%3')(ev(1),1,evalParamFrame))541 p = parseExpression('[1,5,7]r')542 for (let i = 0; i<20; i+=1) {543 let v = p(ev(0,0),0,evalParamFrame)544 assertOneOf([1,5,7], v)545 assertInteger(v, 'v:'+v)546 }547 p = parseExpression('[0:9]r')548 for (let i = 0; i<20; i+=1) {549 assertIn(0, 9, p(ev(0,0),0,evalParamFrame))550 assertNotInteger(p(ev(0,0),0,evalParamFrame))551 }552 p = parseExpression('[[0,10]:[9,19]]r')553 for (let i = 0; i<20; i+=1) {554 assertIn(0, 9, evalParamFrame(p,ev(0),0))555 assertNotInteger(evalParamFrame(p,ev(0),0))556 }557 for (let i = 0; i<20; i+=1) {558 assertIn(10, 19, evalParamFrame(p,ev(1),1))559 assertNotInteger(evalParamFrame(p,ev(1),1))560 }561 p = parseExpression('[:9]r')562 for (let i = 0; i<20; i+=1) {563 assertIn(0, 9, evalParamFrame(p,ev(0,0),0))564 assertNotInteger(evalParamFrame(p,ev(0,0),0))565 }566 p = parseExpression('[9]r')567 for (let i = 0; i<20; i+=1) {568 assert(9, evalParamFrame(p,ev(0,0),0))569 }570 p = parseExpression('[0.1:9]r')571 for (let i = 0; i<20; i+=1) {572 assertIn(0.1, 9, evalParamFrame(p,ev(0,0),0))573 assertNotInteger(evalParamFrame(p,ev(0,0),0))574 }575 assert(1, parseExpression('2-1'))576 p = parseExpression('[0,2]l2@f')577 assert(0, evalParamFrame(p,ev(0),0))578 assert(1/2, evalParamFrame(p,ev(1/2),1/2))579 assert(1, evalParamFrame(p,ev(1),1))580 assert(2, evalParamFrame(p,ev(2),2))581 assert(1, evalParamFrame(p,ev(3),3))582 assert(0, evalParamFrame(p,ev(4),4))583 p = parseExpression('[0:2]l2@f')584 assert(0, evalParamFrame(p,ev(0),0))585 assert(1, evalParamFrame(p,ev(1),1))586 assert(2, evalParamFrame(p,ev(2),2))587 assert(1, evalParamFrame(p,ev(3),3))588 assert(0, evalParamFrame(p,ev(4),4))589 p = parseExpression('[0,1]s1@f')590 assert(0, p(ev(0),0,evalParamFrame))591 assertIn(0.1, 0.4, p(ev(1/4),1/4,evalParamFrame))592 assert(1/2, p(ev(1/2),1/2,evalParamFrame))593 assertIn(0.6, 0.9, p(ev(3/4),3/4,evalParamFrame))594 assert(1, p(ev(1),1,evalParamFrame))595 assertIn(0.6, 0.9, p(ev(5/4),5/4,evalParamFrame))596 assert(1/2, p(ev(3/2),3/2,evalParamFrame))597 assertIn(0.1, 0.4, p(ev(7/4),7/4,evalParamFrame))598 assert(0, p(ev(2),2,evalParamFrame))599 p = parseExpression('[1,2]T0.5@f')600 assert(1, p(ev(0),0,evalParamFrame))601 assert(2, p(ev(1/2),1/2,evalParamFrame))602 assert(1, p(ev(1),1,evalParamFrame))603 p = parseExpression('[1,2]T1/2@f')604 assert(1, p(ev(0),0,evalParamFrame))605 assert(2, p(ev(1/2),1/2,evalParamFrame))606 assert(1, p(ev(1),1,evalParamFrame))607 assert({x:0}, parseExpression('{x:0}'))608 assert({x:0}, parseExpression(' { x : 0 } '))609 assert({x:0}, parseExpression('{X:0}'))610 assert({x:1,y:2}, parseExpression('{x:1,y:2}'))611 assert({x:1/2}, parseExpression('{x:1/2}'))612 assert({x:2}, parseExpression('{x:1+1}'))613 p = parseExpression('{x:[1,2]}')614 assert(1, p.x(ev(0),0,evalParamFrame))615 assert(2, p.x(ev(1),1,evalParamFrame))616 assert(undefined, p.x[2])617 assert('a', parseExpression("'a'"))618 assert(' a B c ', parseExpression("' a B c '"))619 assert({r:0,g:0.2,b:0.4,a:1}, parseExpression("#036f"))620 assert({r:0,g:0.2,b:0.4,a:1}, parseExpression("#003366ff"))621 assert({r:2}, parseExpression("{r:1}*2")(ev(0,0),0,evalParamFrame))622 p = parseExpression("[1,2]t2/2@f")623 assert(1, p(ev(0),0,evalParamFrame))624 assert(2, p(ev(1),1,evalParamFrame))625 assert(1, p(ev(2),2,evalParamFrame))626 p = parseExpression("[0,1]t1/4@f")627 assert(0, p(ev(0),0/4,evalParamFrame))628 assert(1, p(ev(0),1/4,evalParamFrame))629 assert(0, p(ev(0),2/4,evalParamFrame))630 p = parseExpression("[1,2]t2@f*2")631 assert(2, p(ev(0),0,evalParamFrame))632 assert(2, p(ev(1),1,evalParamFrame))633 assert(4, p(ev(2),2,evalParamFrame))634 assert(4, p(ev(3),3,evalParamFrame))635 assert(2, p(ev(4),4,evalParamFrame))636 assert('http://a.com/Bc.mp3', parseExpression("'http://a.com/Bc.mp3'"))637 assert(2, parseExpression("[1]+1")(ev(0),0,evalParamFrame))638 assert(1, parseExpression("[1]//+1")(ev(0),0,evalParamFrame))639 p = parseExpression("[#f00f,#00ff]t1@f")640 assert({r:1,g:0,b:0,a:1}, p(ev(0),0,evalParamFrame))641 assert({r:0,g:0,b:1,a:1}, p(ev(1),1,evalParamFrame))642 p = parseExpression('[1,2]r1@f')643 let v0 = p(ev(0,0),0,evalParamFrame)644 for (let i = 0; i<20; i+=1) { assert(v0, p(ev(0),0,evalParamFrame)) }645 let v1 = p(ev(1),1,evalParamFrame)646 for (let i = 0; i<20; i+=1) { assert(v1, p(ev(1),1,evalParamFrame)) }647 assert('ab', parseExpression("'a'+'b'"))648 assert('a\nb', parseExpression("'a\\nb'"))649 assert('event', parseExpression("[0,1]r").interval)650 assert('event', parseExpression("[0:1]r").interval)651 assert('event', parseExpression("[0,1]r4").interval)652 assert('frame', parseExpression("[0,1]r@f").interval)653 assert('frame', parseExpression("[0,1]r @f").interval)654 assert('event', parseExpression("[0,1]r@e").interval)655 assert('event', parseExpression("[0:1]r@e").interval)656 assert('event', parseExpression("[0,1]").interval)657 assert('event', parseExpression("[0,1]t4").interval)658 assert('frame', parseExpression("[0,1]t4@f").interval)659 assert('frame', parseExpression("[0,1]t1/4@f").interval)660 assert('event', parseExpression("[0,1]@e").interval)661 assert('event', parseExpression("[0,1]t@e").interval)662 assert('event', parseExpression("[0,1]t4@e").interval)663 assert('event', parseExpression("[0,1]l4").interval)664 assert('frame', parseExpression("[0,1]l4@f").interval)665 assert('event', parseExpression("[0,1]l4@e").interval)666 assert('event', parseExpression("[0,1]s4").interval)667 assert('frame', parseExpression("[0,1]s4@f").interval)668 assert('event', parseExpression("[0,1]s4@e").interval)669 assert('event', parseExpression("(0,1)").interval)670 assert(undefined, parseExpression("(0,[0:1]r@f)")[0].interval)671 assert('frame', parseExpression("(0,[0:1]r@f)").interval)672 assert('frame', parseExpression("(0,[0:1]r@f)")[1].interval)673 assert(undefined, parseExpression("{a:0}").interval)674 assert(undefined, parseExpression("{a:0}@e").interval)675 assert(undefined, parseExpression("{a:0}@f").interval)676 assert(undefined, parseExpression("{a:[0,1]l@e}").interval)677 assert(undefined, parseExpression("{a:[0,1]l@f}").interval)678 p = parseExpression('foo')679 vars.foo = parseExpression('0')680 assert('frame', p.interval)681 delete vars.foo682 p = parseExpression('foo@e')683 vars.foo = parseExpression('0')684 assert('event', p.interval)685 delete vars.foo686 p = parseExpression('foo@f')687 vars.foo = parseExpression('0')688 assert('frame', p.interval)689 delete vars.foo690 assertApprox(0, parseExpression("[0,1]l0.1@f")(ev(0,0),0,evalParamFrame))691 assertApprox(1, parseExpression("[0,1]l0.1@f")(ev(0,0),0.1,evalParamFrame))692 assertApprox(0, parseExpression("[0,1]l0.1@f")(ev(0,0),1,evalParamFrame))693 assert(0, parseExpression("[0,1]t1@e")(ev(0,1),0,evalParamFrame))694 assert(1, parseExpression("[0,1]t1@f")(ev(0,0),1,evalParamFrame))695 assert(0, parseExpression("[0,1]l1@e")(ev(0,1),0,evalParamFrame))696 assert(1, parseExpression("[0,1]l1@f")(ev(0,0),1,evalParamFrame))697 assert(0, parseExpression("[0,1]s1@e")(ev(0,1),0,evalParamFrame))698 assert(1, parseExpression("[0,1]s1@f")(ev(0,0),1,evalParamFrame))699 let r700 p = parseExpression("[0:1]r1")701 r = p(ev(0,0),0,evalParamFrame)702 for (let i=0; i<20; i++) { assert(r, p(ev(0,0),0,evalParamFrame)) }703 assertNotEqual(r, p(ev(1,1),1,evalParamFrame))704 p = parseExpression("[0:1]r1@e")705 r = p(ev(0,0),0,evalParamFrame)706 for (let i=0; i<20; i++) { assert(r, p(ev(0,0),0,evalParamFrame)) }707 assertNotEqual(r, p(ev(1,1),1,evalParamFrame))708 p = parseExpression("[0:1]r1@f")709 r = p(ev(0,0),0,evalParamFrame)710 for (let i=0; i<20; i++) { assert(r, p(ev(0,0),0,evalParamFrame)) }711 assertNotEqual(r, p(ev(0,0),1,evalParamFrame))712 let e713 p = parseExpression("[0:1]e")714 e = { idx:0, count:7, countToTime:b=>b, _time:7, endTime:8 }715 assert(0, p(e,6, evalParamFrame))716 assert(0, p(e,7, evalParamFrame))717 assert(0.5, p(e,7.5, evalParamFrame))718 assert(1, p(e,8, evalParamFrame))719 assert(1, p(e,9, evalParamFrame))720 p = parseExpression("[0:1]e2")721 e = { idx:0, count:7, countToTime:b=>b, _time:7, endTime:8 }722 assert(1, p(e,6, evalParamFrame))723 assert(0, p(e,7, evalParamFrame))724 assert(0.5, p(e,8, evalParamFrame))725 assert(1, p(e,9, evalParamFrame))726 assert(1, p(e,10, evalParamFrame))727 p = parseExpression("[0,1,0]e")728 e = { idx:0, count:7, countToTime:b=>b, _time:7, endTime:8 }729 assert(0, p(e,6, evalParamFrame))730 assert(0, p(e,7, evalParamFrame))731 assert(1, p(e,7.5, evalParamFrame))732 assert(0, p(e,8, evalParamFrame))733 assert(0, p(e,9, evalParamFrame))734 p = parseExpression("[0:1]e")735 e = { idx:0, count:7, countToTime:b=>b, _time:1, endTime:3 }736 assert(0, p(e,1, evalParamFrame))737 assert(0.5, p(e,2, evalParamFrame))738 assert(1, p(e,3, evalParamFrame))739 p = parseExpression("[0,1,0]e")740 e = { idx:0, count:7, countToTime:b=>b, _time:1, endTime:3 }741 assert(0, p(e,1, evalParamFrame))742 assert(1, p(e,2, evalParamFrame))743 assert(0, p(e,3, evalParamFrame))744 p = parseExpression("[1]e")745 e = { idx:0, count:7, countToTime:b=>b, _time:1, endTime:2 }746 assert(1, p(e,0, evalParamFrame))747 assert(1, p(e,1, evalParamFrame))748 assert(1, p(e,2, evalParamFrame))749 assert(1, p(e,3, evalParamFrame))750 p = parseExpression("[]e")751 e = { idx:0, count:7, countToTime:b=>b, _time:1, endTime:2 }752 assert(0, p(e,0, evalParamFrame))753 assert(0, p(e,1, evalParamFrame))754 assert(0, p(e,2, evalParamFrame))755 assert(0, p(e,3, evalParamFrame))756 p = parseExpression("[0:1]e1/2")757 e = { idx:0, count:7, countToTime:b=>b, _time:7, endTime:8 }758 assert(0, p(e,6, evalParamFrame))759 assert(0, p(e,7, evalParamFrame))760 assert(0.5, p(e,7.25, evalParamFrame))761 assert(1, p(e,7.5, evalParamFrame))762 assert(1, p(e,8, evalParamFrame))763 assert(1, p(e,9, evalParamFrame))764 p = parseExpression("[0,1,2]e[2,1]")765 e = { idx:0, count:0, countToTime:b=>b, _time:0, endTime:3 }766 assert(0, p(e,0, evalParamFrame))767 assert(0.5, p(e,1, evalParamFrame))768 assert(1, p(e,2, evalParamFrame))769 assert(2, p(e,3, evalParamFrame))770 assert(2, p(e,4, evalParamFrame))771 p = parseExpression('[(0,2),(1,3)]e')772 e = { idx:0, count:0, countToTime:b=>b, _time:0, endTime:1 }773 assert([0,2], evalParamFrame(p,e,0,evalParamFrame))774 assert([0.5,2.5], evalParamFrame(p,e,1/2,evalParamFrame))775 assert([1,3], evalParamFrame(p,e,2,evalParamFrame))776 p = parseExpression("[0:1]e")777 let e1 = { idx:0, count:7, countToTime:b=>b, _time:7, endTime:70 }778 let e2 = { idx:0, count:7, countToTime:b=>b, _time:7, endTime:8 }779 assert(0.015873015873015872, p(e1,8, evalParamFrame))780 assert(1, p(e2,8, evalParamFrame))781 assert(1, parseExpression("[1,0]t1")(ev(0,0),0,evalParamFrame))782 assert(0, parseExpression("[1,0]t1")(ev(1,1),1,evalParamFrame))783 assert(1, parseExpression("[1,0]l1")(ev(0,0),0,evalParamFrame))784 assert(0, parseExpression("[1,0]l1")(ev(1,1),1,evalParamFrame))785 p = parseExpression("[1000:100]e")786 e = { idx:0, count:7, countToTime:b=>b, _time:7, endTime:8 }787 r = preEvalParam(p,e,7)788 assert('function', typeof(r))789 assert(550, evalParamFrame(r,e,7.5))790 let last, min, max791 p = parseExpression("[]n")792 e = ev(0,0)793 last = undefined794 for (let b= 0; b<1; b+=0.01) {795 let current = p(e,b,evalParamFrame)796 if (last === undefined) { last = current-0.01 }797 assertIn(0, 1, current)798 assertNotEqual(last, current)799 assertIn(last-0.1, last+0.1, current)800 last = current801 }802 min=1803 max=-1804 for (let b= 0; b<200; b+=0.2) {805 let current = p(e,b,evalParamFrame)806 min = Math.min(min, current)807 max = Math.max(max, current)808 }809 assertIn(0, 0.1, min)810 assertIn(0.9, 1, max)811 p = parseExpression("[-1/8:5/8]n")812 e = ev(0,0)813 last = undefined814 for (let b= 0; b<1; b+=0.01) {815 let current = p(e,b,evalParamFrame)816 if (last === undefined) { last = current-0.01 }817 assertIn(-1/8,5/8, current)818 assertNotEqual(last, current)819 assertIn(last-0.05, last+0.05, current)820 last = current821 }822 assertIn(3/8,5/8, parseExpression("[3/8:5/8]n4")(ev(0,0),0,evalParamFrame))823 p = parseExpression("[[1,5]t1:[2,6]t1]n")824 assertIn(1, 2, evalParamFrame(p,ev(0,0),0))825 assertIn(5, 6, evalParamFrame(p,ev(1,1),1))826 p = parseExpression("[1:1]r-[0:2]e")827 e = { idx:0, count:7, countToTime:b=>b, _time:7, endTime:8 }828 assert(1, evalParamFrame(p,e,7))829 assert(0, evalParamFrame(p,e,7.5))830 assert(-1, evalParamFrame(p,e,8))831 p = parseExpression("[]r")832 for (let i=0; i<20; i++) { assertIn(0,1, p(ev(0,0),0,evalParamFrame)) }833 assert(8, parseExpression('2^3'))834 assert(18, parseExpression('2*3^2'))835 assert(36, parseExpression('(2*3)^2'))836 assert(2, parseExpression('4^1/2'))837 assert(0, parseExpression('-1^1/2'))838 vars.foo = () => 5839 vars.foo.isVarFunction = true840 assert(5, parseExpression('foo{}')(ev(0,0),0,evalParamFrame))841 delete vars.foo842 vars.foo = ({val}) => val843 vars.foo.isVarFunction = true844 assert(5, evalParamFrame(parseExpression('foo{val:5}'),ev(0,0),0))845 delete vars.foo846 vars.foo = () => 5847 vars.foo.isVarFunction = true848 assert(7, parseExpression('foo{}+2')(ev(0,0),0,evalParamFrame))849 delete vars.foo850 vars.foo = ({val}) => val851 vars.foo.isVarFunction = true852 assert(6, evalParamFrame(parseExpression(' foo { x:3, val : 6 } '),ev(0,0),0))853 delete vars.foo854 assert('event', parseExpression("[0,24]r").interval)855 assert('event', parseExpression("[0:24]r").interval)856 assert('frame', parseExpression("[0,24]e").interval)857 assert('frame', parseExpression("[0,[0,24]e]r").interval)858 assert('frame', parseExpression("[0,[0,24]e]r1").interval)859 assert('frame', parseExpression("[0,[0:24]e]r").interval)860 assert('frame', parseExpression("[0,[0:24]e]r1").interval)861 assert('frame', parseExpression("[0:[0,24]e]r").interval)862 assert('frame', parseExpression("[0:[0,24]e]r1").interval)863 assert('frame', parseExpression("[0:[0:24]e]r").interval)864 assert('frame', parseExpression("[0:[0:24]e]r1").interval)865 assert('frame', parseExpression("[[0:24]e:0]r").interval)866 assert('frame', parseExpression("[[0:24]e:0]r1").interval)867 assert('frame', parseExpression("[0,[0,24]r]e").interval)868 assert('event', parseExpression("[0,[0,24]r]e@e").interval)869 assert('event', parseExpression("[0,[0,24]e]r@e").interval)870 assert('frame', parseExpression("[0,[0,24]r@e]e").interval)871 assert('event', parseExpression("[0,[0,24]e@e]r").interval)872 assert('frame', parseExpression("[0,24]r@f").interval)873 assert('frame', parseExpression("[0,[0,24]e]n").interval)874 assert('frame', parseExpression("[0,[0,24]n]e").interval)875 assert('event', parseExpression("[0,[0,24]e]n@e").interval)876 assert('event', parseExpression("[0,[0,24]n]e@e").interval)877 assert('frame', parseExpression("[0,[0,24]e]t").interval)878 assert('frame', parseExpression("[0,[0,24]t]e").interval)879 assert('event', parseExpression("[0,[0,24]e]t@e").interval)880 assert('event', parseExpression("[0,[0,24]t]e@e").interval)881 assert('frame', parseExpression("[0,[0,24]e]l").interval)882 assert('frame', parseExpression("[0,[0,24]l]e").interval)883 assert('event', parseExpression("[0,[0,24]e]l@e").interval)884 assert('event', parseExpression("[0,[0,24]l]e@e").interval)885 assert('frame', parseExpression("[0,[0,24]e]s").interval)886 assert('frame', parseExpression("[0,[0,24]s]e").interval)887 assert('event', parseExpression("[0,[0,24]e]s@e").interval)888 assert('event', parseExpression("[0,[0,24]s]e@e").interval)889 assert('event', parseExpression("[0,[0,24]e]").interval)890 assert('frame', parseExpression("[0,[0,24]]e").interval)891 assert('event', parseExpression("[0,[0,24]e]@e").interval)892 assert('event', parseExpression("[0,[0,24]e]@f").interval)893 assert('frame', parseExpression("[0.1,(0.1,5)]t1/4@f").interval)894 assert('frame', parseExpression("[0.1,(0.1,5)]l1/4@f").interval)895 assert('frame', parseExpression("[0.1,(0.1,5)]s1/4@f").interval)896 assert('frame', parseExpression("[0.1,(0.1,5)]e").interval)897 assert('frame', parseExpression("[]r@f").interval)898 assert('event', parseExpression("[]r").interval)899 assert('event', parseExpression("[]r1").interval)900 assert('event', parseExpression("[]r{seed:1}").interval)901 assert('event', parseExpression("[]r{seed:1+2}").interval)902 assert('event', parseExpression("[]r{seed:[]r}").interval)903 assert('frame', parseExpression("[]r{seed:[]e}").interval)904 assert('event', parseExpression("[]r{seed:1,per:1}").interval)905 assert('frame', parseExpression("[]r{seed:1,per:[]e}").interval)906 assert([0,0], evalParamFrame(parseExpression("[0,(0,0)]n@f"),ev(0,0),0,evalParamFrame))907 assert('frame', parseExpression("[0.1,(0.1,5)]n@f").interval)908 assert([0,0], evalParamFrame(parseExpression("[(0,0),(0,0)]r@f"), ev(0,0),0,evalParamFrame))909 assert('frame', parseExpression("[0.1,(0.1,5)]r@f").interval)910 assert({x:[1,2]}, parseExpression("{x:(1,2)}"))911 assert([1,2], parseExpression("((1,2))"))912 assert([1,[2,3]], parseExpression("(1,(2,3))"))913 assert([[1,2],3], parseExpression("((1,2),3))"))914 assert([{x:0},{x:[1,2]}], parseExpression("({x:0},{x:(1,2)})"))915 assert([{x:1},{x:2}], evalParamFrame(parseExpression("{x:(1,2)}"), ev(0,0),0))916 assert([{x:0},{x:1},{x:2}], evalParamFrame(parseExpression("({x:0},{x:(1,2)})"), ev(0,0),0))917 vars['green'] = parseExpression('{r:0,g:0.8,b:0,a:1}')918 vars['blue'] = parseExpression('{r:0,g:0.6,b:1,a:1}')919 p = parseExpression("[green:blue]r")920 r = evalParamFrame(p,ev(0,0),0)921 assert(0, r.r)922 assertIn(0, 1, r.g)923 assertIn(0, 1, r.b)924 assert(1, r.a)925 vars.foo = parseExpression("1")926 p = parseExpression("[]r{seed:foo}")927 assert(0.3853306171949953, evalParamFrame(p,ev(0,0),0))928 delete vars.foo929 p = parseExpression("[]r{seed:[1]r4,per:1}")930 assert(0.3853306171949953, evalParamFrame(p,ev(0,0),0))931 assert(0.3853306171949953, evalParamFrame(p,ev(1,1),1))932 assert(0.3853306171949953, evalParamFrame(p,ev(2,2),2))933 vars.red = parseExpression("{r:1}")934 vars.green = parseExpression("{g:1}")935 p = parseExpression("[red,green]t1")936 assert({g:1}, evalParamFrame(p,ev(1,1),1))937 delete vars.red938 delete vars.green939 p = parseExpression("[0,1]t1{per:1}")940 assert(0, evalParamFrame(p,ev(0,0),0))941 assert(0, evalParamFrame(p,ev(1,1),1))942 p = parseExpression("[0,1]l1{per:1}")943 assert(0, evalParamFrame(p,ev(0,0),0))944 assert(0, evalParamFrame(p,ev(1,1),1))945 p = parseExpression("[0,1]s1{per:1}")946 assert(0, evalParamFrame(p,ev(0,0),0))947 assert(0, evalParamFrame(p,ev(1,1),1))948 p = parseExpression("[0:1]e{per:1/2}")949 e = { idx:0, count:0, countToTime:b=>b, _time:0, endTime:1 }950 assert(0, evalParamFrame(p,e,0))951 assert(1/4, evalParamFrame(p,e,1/4))952 assert(0, evalParamFrame(p,e,1/2))953 assert(1/4, evalParamFrame(p,e,3/4))954 p = parseExpression("[0,1]{per:1}")955 assert(0, evalParamFrame(p,ev(0,0),0))956 assert(1, evalParamFrame(p,ev(1,1),1)) // idx not affected by per957 p = parseExpression('(1,2){per:1}')958 assert([1,2], evalParamFrame(p,ev(0,0),0))959 p = parseExpression('{foo:2}{per:1}')960 assert({foo:2}, evalParamFrame(p,ev(0,0),0))961 p = parseExpression('5{per:1}')962 assert(5, evalParamFrame(p,ev(0,0),0))963 p = parseExpression("'foo'{per:1}")964 assert('foo', evalParamFrame(p,ev(0,0),0))965 vars.foo = parseExpression('[0,1]t1@f')966 p = parseExpression('foo{per:1}')967 assert(0, evalParamFrame(p,ev(0,0),0))968 assert(0, evalParamFrame(p,ev(1,1),1))969 delete vars.foo970 p = parseExpression('[0,1]t1{per:1}@e')971 assert(0, evalParamFrame(p,ev(0,0),0))972 assert(0, evalParamFrame(p,ev(1,1),1))973 vars.foo = parseExpression('[0,1]t1{per:1}@e')974 p = parseExpression('foo')975 assert(0, evalParamFrame(p,ev(0,0),0))976 assert(0, evalParamFrame(p,ev(1,1),1))977 delete vars.foo978 vars.foo = parseExpression('[0,1]t1@e')979 p = parseExpression('foo{per:1}')980 assert(0, evalParamFrame(p,ev(0,0),0))981 assert(0, evalParamFrame(p,ev(1,1),1))982 delete vars.foo983 p = parseExpression('5{per:2,0:1}')984 assert(1, evalParamFrame(p,ev(0,0),0))985 assert(5, evalParamFrame(p,ev(1,1),1))986 assert(1, evalParamFrame(p,ev(2,2),2))987 assert(5, evalParamFrame(p,ev(3,3),3))988 p = parseExpression('[0:1]r{seed:1,per:2}')989 assert(0.3853306171949953, evalParamFrame(p,ev(0,0),0))990 assert(0.8534541970584542, evalParamFrame(p,ev(1,1),1))991 assert(0.3853306171949953, evalParamFrame(p,ev(2,2),2))992 assert(0.8534541970584542, evalParamFrame(p,ev(3,3),3))993 p = parseExpression('[0:1]r{seed:[1,100]t1,per:1}')994 assert(0.3853306171949953, evalParamFrame(p,ev(0,0),0))995 assert(0.19610000611282885, evalParamFrame(p,ev(1,1),1))996 assert(0.3853306171949953, evalParamFrame(p,ev(2,2),2))997 assert(0.19610000611282885, evalParamFrame(p,ev(3,3),3))998 assert(1, evalParamFrame(parseExpression('(1,2)[0]'),ev(0,0),0))999 assert(2, evalParamFrame(parseExpression('(1,2)[1]'),ev(0,0),0))1000 assert(1, evalParamFrame(parseExpression('(1,2)[2]'),ev(0,0),0))1001 assert(1, evalParamFrame(parseExpression('(1,2)[0.8]'),ev(0,0),0))1002 assert([1,2], evalParamFrame(parseExpression('(1,2,3,4)[0,1]'),ev(0,0),0))1003 assert([1,2], evalParamFrame(parseExpression('(1,2,3,4)[0,1]'),ev(0,0),0))1004 assert([2,3,4], evalParamFrame(parseExpression('(1,2,3,4)[1:3]'),ev(0,0),0))1005 assert(1, evalParamFrame(parseExpression(' ( 1 , 2 ) [ 0 ] @e'),ev(0,0),0))1006 p = parseExpression('([3,4]t1,2)[0]')1007 assert(3, evalParamFrame(p,ev(0,0),0))1008 assert(4, evalParamFrame(p,ev(1,1),1))1009 p = parseExpression('(1,2)[ [0,1]t1 ]')1010 assert(1, evalParamFrame(p,ev(0,0),0))1011 assert(2, evalParamFrame(p,ev(1,1),1))1012 p = parseExpression('(1,2,3)[ 0, [1,2]t1 ]')1013 assert([1,2], evalParamFrame(p,ev(0,0),0))1014 assert([1,3], evalParamFrame(p,ev(1,1),1))1015 p = parseExpression('(1,2,3)[ 0 : [1,2]t1 ]')1016 assert([1,2], evalParamFrame(p,ev(0,0),0))1017 assert([1,2,3], evalParamFrame(p,ev(1,1),1))1018 p = parseExpression('(1,2){per:2,0:5}@f[0]')1019 assert(5, evalParamFrame(p,ev(0,0),0))1020 assert(1, evalParamFrame(p,ev(1,1),1))1021 assert(5, evalParamFrame(p,ev(2,2),2))1022 assert(1, evalParamFrame(p,ev(3,3),3))1023 p = parseExpression('[[1,2]t2]r{seed:0,per:1}')1024 assert(1, evalParamFrame(p,ev(0,0),0))1025 assert(1, evalParamFrame(p,ev(1,1),1))1026 assert(2, evalParamFrame(p,ev(2,2),2))1027 assert(2, evalParamFrame(p,ev(3,3),3))1028 assert(1, evalParamFrame(p,ev(4,4),4))1029 p = parseExpression('[0,[2,4,7]t4]l2{per:4}')1030 assert(0, evalParamFrame(p,ev(0,0),0))1031 assert(1, evalParamFrame(p,ev(1,1),1))1032 assert(2, evalParamFrame(p,ev(2,2),2))1033 assert(1, evalParamFrame(p,ev(3,3),3))1034 assert(0, evalParamFrame(p,ev(4,4),4))1035 assert(4, evalParamFrame(p,ev(6,6),6))1036 assert(0, evalParamFrame(p,ev(8,8),8))1037 assert(7, evalParamFrame(p,ev(10,10),10))1038 assert(1, evalParamFrame(parseExpression('[1]r{}'),ev(0,0),0))1039 assert(2, evalParamFrame(parseExpression('min{2}'),ev(0,0),0))1040 assert(2, evalParamFrame(parseExpression('max{2,1}'),ev(0,0),0))1041 assert(3, evalParamFrame(parseExpression('max{(2,3),1}'),ev(0,0),0))1042 assert(1, evalParamFrame(parseExpression('min{(2,3),1}'),ev(0,0),0))1043 assert(3, evalParamFrame(parseExpression('max{1,(2,3)}'),ev(0,0),0))1044 assert(1, evalParamFrame(parseExpression('min{1,(2,3)}'),ev(0,0),0))1045 assert(2, evalParamFrame(parseExpression('min{(2,3)}'),ev(0,0),0))1046 assert(2, evalParamFrame(parseExpression('count{(0,0)}'),ev(0,0),0))1047 assert(3, evalParamFrame(parseExpression('max{(2,3)}'),ev(0,0),0))1048 assert(4, evalParamFrame(parseExpression('max{(2,[4,5]t1)}'),ev(0,0),0))1049 assert(5, evalParamFrame(parseExpression('max{(2,[4,5]t1)}'),ev(1,1),1))1050 assert(3, evalParamFrame(parseExpression('max{[(2,3),(4,5)]t1}'),ev(0,0),0))1051 assert(5, evalParamFrame(parseExpression('max{[(2,3),(4,5)]t1}'),ev(1,1),1))1052 assert(0, evalParamFrame(parseExpression('()[max]'),ev(0,0),0))1053 assert(3, evalParamFrame(parseExpression('(1,2,3)[max]'),ev(0,0),0))1054 assert([1,3], evalParamFrame(parseExpression('(1,2,3)[min,max]'),ev(0,0),0))1055 assert(3, evalParamFrame(parseExpression('(1,2,[3,4]t1)[max]'),ev(0,0),0))1056 assert(4, evalParamFrame(parseExpression('(1,2,[3,4]t1)[max]'),ev(1,1),1))1057 assert(3, evalParamFrame(parseExpression('(1,(2,3))[max]'),ev(0,0),0))1058 assert('frame', parseExpression('(0,[1,2]l1/2@f)').interval)1059 assert('frame', parseExpression('(0,[1,2]l1/2@f)[max]').interval)1060 assert('frame', parseExpression('max{(0,[1,2]l1/2@f)}').interval)1061 assert('min', evalParamFrame(parseExpression('min'),ev(0,0),0))1062 assert(1, evalParamFrame(parseExpression('[(1,2),(3,4)]t1[0]'),ev(0,0),0))1063 assert(3, evalParamFrame(parseExpression('[(1,2),(3,4)]t1[0]'),ev(1,1),1))1064 assert(2, evalParamFrame(parseExpression('[(1,2),(3,4)]t1[1]'),ev(0,0),0))1065 assert(4, evalParamFrame(parseExpression('[(1,2),(3,4)]t1[1]'),ev(1,1),1))1066 assert(3, evalParamFrame(parseExpression('((1,2),(3,4))[1][0]'),ev(0,0),0))1067 1068 vars.foo = parseExpression('3')1069 p = parseExpression('(1,(2,foo))')1070 assert([1,2,3], evalParamFrame(p,ev(0,0),0))1071 delete vars.foo1072 assert(2, evalParamFrame(parseExpression("{foo:2}['foo']"),ev(0,0),0))1073 assert(3, evalParamFrame(parseExpression("{foo:[2:3]t1}['foo']"),ev(1,1),1))1074 assert(2, evalParamFrame(parseExpression("{foo:2,bar:3}[['foo','bar']t1]"),ev(0,0),0))1075 assert(3, evalParamFrame(parseExpression("{foo:2,bar:3}[['foo','bar']t1]"),ev(1,1),1))1076 assert(0, evalParamFrame(parseExpression("{foo:2,bar:3}[max]"),ev(0,0),0))1077 assert({value:0,'#':1}, evalParamFrame(parseExpression("0#"),ev(0,0),0))1078 assert({value:2,b:1}, evalParamFrame(parseExpression("2b"),ev(0,0),0))1079 vars.e = 11080 p = parseExpression('e')1081 assert(1, p({},0,(v)=>v))1082 delete vars.e1083 assert(0, evalParamFrame(parseExpression("[0,1]t1/4{per:1}@f"),ev(0,0,1),0))1084 assert(1, evalParamFrame(parseExpression("[0,1]t1/4{per:1}@f"),ev(0,0,1),1/4))1085 assert(0, evalParamFrame(parseExpression("[0,1]t1/4{per:1}@f"),ev(0,0,1),1/2))1086 assert(1, evalParamFrame(parseExpression("[0,1]t1/4{per:1}@f"),ev(0,1,1),3/4))1087 assert(0, evalParamFrame(parseExpression("[0,1]e"),ev(0,0,1),0))1088 assert(1/4, evalParamFrame(parseExpression("[0,1]e"),ev(0,0,1),1/4))1089 assert(1/2, evalParamFrame(parseExpression("[0,1]e"),ev(0,0,1),1/2))1090 assert(3/4, evalParamFrame(parseExpression("[0,1]e"),ev(0,0,1),3/4))1091 assert(0, evalParamFrame(parseExpression("[0,1]e"),ev(0,1,1),1))1092 assert(0, evalParamFrame(parseExpression("[0,1]e{per:1}"),ev(0,0,1),0))1093 assert(1/4, evalParamFrame(parseExpression("[0,1]e{per:1}"),ev(0,0,1),1/4))1094 assert(1/2, evalParamFrame(parseExpression("[0,1]e{per:1}"),ev(0,0,1),1/2))1095 assert(3/4, evalParamFrame(parseExpression("[0,1]e{per:1}"),ev(0,0,1),3/4))1096 assert(0, evalParamFrame(parseExpression("[0,1]e{per:1}"),ev(0,1,1),1))1097 assert([0,0], evalParamFrame(parseExpression("[0,2]t1{per:(1,2)}"),ev(0,0,1),0))1098 assert([0,2], evalParamFrame(parseExpression("[0,2]t1{per:(1,2)}"),ev(0,1,1),1))1099 assert(0.8534541970584542, evalParamFrame(parseExpression("[0:1]r{per:1,seed:0}"),ev(0,0,1),0))1100 assert(0.24364092224277556, evalParamFrame(parseExpression("[0:1]r{per:1,seed:10}"),ev(0,0,1),0))1101 assert([0.8534541970584542, 0.24364092224277556], evalParamFrame(parseExpression("[0:1]r{per:1,seed:(0,10)}"),ev(0,0,1),0))1102 assert(0.1989616905192142, evalParamFrame(parseExpression("[0:1]n{per:2,seed:0}"),ev(0,1,1),1))1103 assert(0.31159096606000625, evalParamFrame(parseExpression("[0:1]n{per:2,seed:10}"),ev(0,1,1),1))1104 assert([0.1989616905192142, 0.31159096606000625], evalParamFrame(parseExpression("[0:1]n{per:2,seed:(0,10)}"),ev(0,1,1),1))1105 console.log('Parse expression tests complete')1106 }1107 return parseExpression...
predefined-vars.js
Source:predefined-vars.js
1'use strict'2define(function(require) {3 let parseExpression = require('player/parse-expression')4 let vars = require('vars')5 vars['drop4_4'] = parseExpression('[1,0]t[4,4]')6 vars['drop6_2'] = parseExpression('[1,0]t[6,2]')7 vars['drop7_1'] = parseExpression('[1,0]t[7,1]')8 vars['drop8_8'] = parseExpression('[1,0]t[8,8]')9 vars['drop12_4'] = parseExpression('[1,0]t[12,4]')10 vars['drop14_2'] = parseExpression('[1,0]t[14,2]')11 vars['drop15_1'] = parseExpression('[1,0]t[15,1]')12 vars['drop16_16'] = parseExpression('[1,0]t[16,16]')13 vars['drop24_8'] = parseExpression('[1,0]t[24,8]')14 vars['drop28_4'] = parseExpression('[1,0]t[28,4]')15 vars['drop30_2'] = parseExpression('[1,0]t[30,2]')16 vars['drop31_1'] = parseExpression('[1,0]t[31,1]')17 vars['drop32_32'] = parseExpression('[1,0]t[32,32]')18 vars['drop56_8'] = parseExpression('[1,0]t[56,8]')19 vars['drop60_4'] = parseExpression('[1,0]t[60,4]')20 vars['drop62_2'] = parseExpression('[1,0]t[62,2]')21 vars['drop63_1'] = parseExpression('[1,0]t[63,1]')22 vars['fullscreen'] = parseExpression('{x:0,y:0,w:2,h:2}')23 vars['tile_full'] = parseExpression('{x:0,y:0,w:2,h:2}')24 vars['tile_tl'] = parseExpression('{x:-1/2,y:1/2,w:1,h:1}')25 vars['tile_tr'] = parseExpression('{x:1/2,y:1/2,w:1,h:1}')26 vars['tile_bl'] = parseExpression('{x:-1/2,y:-1/2,w:1,h:1}')27 vars['tile_br'] = parseExpression('{x:1/2,y:-1/2,w:1,h:1}')28 vars['tile_t'] = parseExpression('{x:0,y:1/2,w:2,h:1}')29 vars['tile_b'] = parseExpression('{x:0,y:-1/2,w:2,h:1}')30 vars['tile_l'] = parseExpression('{x:-1/2,y:0,w:1,h:2}')31 vars['tile_r'] = parseExpression('{x:1/2,y:0,w:1,h:2}')32 vars['tile_m'] = parseExpression('{x:0,y:0,w:1,h:1}')33 vars['tile_h1'] = parseExpression('{x:0,y:3/4,w:2,h:1/2}')34 vars['tile_h2'] = parseExpression('{x:0,y:1/4,w:2,h:1/2}')35 vars['tile_h3'] = parseExpression('{x:0,y:-1/4,w:2,h:1/2}')36 vars['tile_h4'] = parseExpression('{x:0,y:-3/4,w:2,h:1/2}')37 vars['tile_v1'] = parseExpression('{x:-3/4,y:0,w:1/2,h:2}')38 vars['tile_v2'] = parseExpression('{x:-1/4,y:0,w:1/2,h:2}')39 vars['tile_v3'] = parseExpression('{x:1/4,y:0,w:1/2,h:2}')40 vars['tile_v4'] = parseExpression('{x:3/4,y:0,w:1/2,h:2}')41 vars['tile_random'] = parseExpression('{x:[-7/8:7/8]r,y:[-7/8:7/8]r,w:1/2,h:1/2}')42 vars['tile_rand'] = parseExpression('{x:[-7/8:7/8]r,y:[-7/8:7/8]r,w:1/2,h:1/2}')43 vars['_random_per_event'] = parseExpression('[0:1]r@e')44 vars['sparkle'] = parseExpression('{x:5/6*[-5/6:5/6]r@e,y:[-5/6:5/6]r@e,w:1/3,h:1/3}')45 vars['fireworks'] = parseExpression('{x:[-5/6:5/6]r@e,y:[-5/6:5/6]r@e,w:0.5+_random_per_event,h:0.5+_random_per_event}')46 vars['droplet'] = parseExpression('{w:1/4,h:1/4,x:[-15/16:15/16]r,y:[0.8:1.2]r-[0:2]e}')47 vars['gravity'] = parseExpression('{y:[0:-3/2]e*[0:3/2]e}')48 vars['spark'] = parseExpression('{w:1/8,h:1/8, x:[0,[-1.01:1]r]e, y:[0,[-1.01:1]r]e}')49 vars['firefly'] = parseExpression('{x:[-1/4:1/4]n{seed:[]r}, y:[-1/4:1/4]n{seed:[]r}}')50 vars['transparent'] = parseExpression('{r:0,g:0,b:0,a:0}')51 vars['black'] = parseExpression('{r:0,g:0,b:0,a:1}')52 vars['darkgray'] = parseExpression('{r:0.2,g:0.2,b:0.2,a:1}')53 vars['gray'] = parseExpression('{r:0.4,g:0.4,b:0.4,a:1}')54 vars['lightgray'] = parseExpression('{r:0.8,g:0.8,b:0.8,a:1}')55 vars['white'] = parseExpression('{r:1,g:1,b:1,a:1}')56 vars['red'] = parseExpression('{r:1,g:0,b:0,a:1}')57 vars['orange'] = parseExpression('{r:1,g:0.3,b:0,a:1}')58 vars['yellow'] = parseExpression('{r:1,g:0.9,b:0,a:1}')59 vars['green'] = parseExpression('{r:0,g:0.8,b:0,a:1}')60 vars['blue'] = parseExpression('{r:0,g:0.6,b:1,a:1}')61 vars['indigo'] = parseExpression('{r:0,g:0,b:0.8,a:1}')62 vars['violet'] = parseExpression('{r:0.4,g:0,b:0.8,a:1}')63 vars['purple'] = parseExpression('{r:0.6,g:0,b:0.8,a:1}')64 vars['neonpink'] = parseExpression('{r:1,g:0,b:1,a:1}')65 vars['neongreen'] = parseExpression('{r:0,g:0.7,b:1,a:1}')66 vars['rainbow'] = parseExpression('{r:[0.8,0,0]l6@f,g:[0,0.7,0]l6@f,b:[0,0,1]l6@f,a:1}')67 vars['rainbow_slow'] = parseExpression('{r:[0.8,0,0]l12@f,g:[0,0.7,0]l12@f,b:[0,0,1]l12@f,a:1}')68 vars['rainbow_fast'] = parseExpression('{r:[0.8,0,0]l2@f,g:[0,0.7,0]l2@f,b:[0,0,1]l2@f,a:1}')69 vars['random'] = parseExpression('{r:[0:0.8]n4,g:[0:0.7]n4,b:[0.1:0.9]n4,a:1}')70 vars['oil'] = parseExpression('1')71 vars['hue'] = parseExpression('2')72 vars['fire'] = parseExpression('3')73 vars['sunset'] = parseExpression('4')74 vars['neon'] = parseExpression('5')75 vars['titanium'] = parseExpression('6')76 vars['full'] = 'full'77 vars['simple'] = 'simple'78 vars['pad'] = 'pad'79 vars['sine'] = 'sine'80 vars['square'] = 'square'81 vars['triangle'] = 'triangle'82 vars['tri'] = 'triangle'83 vars['sawtooth'] = 'sawtooth'84 vars['saw'] = 'sawtooth'85 vars['additive'] = 'additive'86 vars['subtractive'] = 'subtractive'87 vars['invert'] = 'invert'88 vars['average'] = 'average'89 vars['multiply'] = 'multiply'90 vars['max'] = 'max'91 vars['min'] = 'min'92 vars['wow'] = parseExpression('[-0.3:0.3]n2')...
lpo.spec.ts
Source:lpo.spec.ts
...6 const lpo = new LexicographicPathOrdering(["-", "!", "*", "^", "+"])78 describe("lpo", () => {9 it("a > a: false", () => {10 const a = parseExpression("a")11 expect(lpo.greaterThan(a, a)).false12 })1314 it("a > b: false", () => {15 const a = parseExpression("a")16 const b = parseExpression("b")17 expect(lpo.greaterThan(a, b)).false18 })1920 it("b > a: true", () => {21 const a = parseExpression("a")22 const b = parseExpression("b")23 expect(lpo.greaterThan(b, a)).true24 })2526 it("a + c > a + b: false", () => {27 const aPlusC = parseExpression("a + c")28 const aPlusB = parseExpression("a + b")29 expect(lpo.greaterThan(aPlusC, aPlusB)).true30 })3132 it("a + b > a * b: false", () => {33 const aPlusB = parseExpression("a + b")34 const aTimesB = parseExpression("a * b")35 expect(lpo.greaterThan(aPlusB, aTimesB)).false36 })3738 it("(a + b) * c > a * c + b * c: true", () => {39 const lhs = parseExpression("(a + b) * c")40 const rhs = parseExpression("a * c + b * c")41 expect(lpo.greaterThan(lhs, rhs)).true42 })4344 it("a * c + b * c > (a + b) * c: false", () => {45 const lhs = parseExpression("a * c + b * c")46 const rhs = parseExpression("(a + b) * c")47 expect(lpo.greaterThan(lhs, rhs)).false48 })4950 it("(a + b) * d > (a + b) * c: false", () => {51 const lhs = parseExpression("(a + b) * d")52 const rhs = parseExpression("(a + b) * c")53 expect(lpo.greaterThan(lhs, rhs)).false54 })5556 it("(a + b) * c > (a + b) * c: false", () => {57 const lhs = parseExpression("(a + b) * c")58 const rhs = parseExpression("(a + b) * c")59 expect(lpo.greaterThan(lhs, rhs)).false60 })6162 it("0 ! scalar > 0 ! scalar * $x: false", () => {63 const lhs = parseExpression("0 ! scalar")64 const rhs = parseExpression("0 ! scalar * $x")65 expect(lpo.greaterThan(lhs, rhs)).false66 })6768 it("0 ! scalar * $x > 0 ! scalar: false", () => {69 const lhs = parseExpression("0 ! scalar * $x")70 const rhs = parseExpression("0 ! scalar")71 expect(lpo.greaterThan(lhs, rhs)).false72 })7374 it("($x + $y) ! $f > $x ! $f + $y ! $f: true", () => {75 const lhs = parseExpression("($x + $y) ! $f")76 const rhs = parseExpression("$x ! $f + $y ! $f")77 expect(lpo.greaterThan(lhs, rhs)).true78 })7980 it("-$x + $x > 0: true", () => {81 const lhs = parseExpression("-$x + $x")82 const rhs = parseExpression("0")83 expect(lpo.greaterThan(lhs, rhs)).true84 })8586 it("a + b > a: true", () => {87 const lhs = parseExpression("a + b")88 const rhs = parseExpression("a")89 expect(lpo.greaterThan(lhs, rhs)).true90 })9192 it("a ! c * b ! c > a ! c ^ b ! c: true", () => {93 const lhs = parseExpression("a ! c * b ! c")94 const rhs = parseExpression("a ! c ^ b ! c")95 expect(lpo.greaterThan(lhs, rhs)).true96 })9798 it("a ! c * b ! c > a ! c + b ! c: true", () => {99 const lhs = parseExpression("a ! c * b ! c")100 const rhs = parseExpression("a ! c + b ! c")101 expect(lpo.greaterThan(lhs, rhs)).true102 })103 })
...
Using AI Code Generation
1import { parseExpression } from 'storybook-root-attribute'2const App = () => {3 const [data, setData] = useState(null)4 useEffect(() => {5 .then(response => response.json())6 .then(json => setData(json))7 }, [])8 return (9 {data && parseExpression(data, 'title')}10}11import { parseExpression } from 'storybook-root-attribute'12const App = () => {13 const [data, setData] = useState(null)14 useEffect(() => {15 .then(response => response.json())16 .then(json => setData(json))17 }, [])18 return (19 {data && parseExpression(data, 'title')}20}21import { parseExpression } from 'storybook-root-attribute'22const App = () => {23 const [data, setData] = useState(null)24 useEffect(() => {25 .then(response => response.json())26 .then(json => setData(json))27 }, [])28 return (29 {data && parseExpression(data, 'title')}30}31import { parseExpression } from 'storybook-root-attribute'32const App = () => {33 const [data, setData] = useState(null)34 useEffect(() => {35 .then(response => response.json())36 .then(json => setData(json))37 }, [])38 return (
Using AI Code Generation
1const { parseExpression } = require('storybook-root-element');2const parsedExpression = parseExpression('some expression');3console.log(parsedExpression);4import { parseExpression } from 'storybook-root-element';5const parsedExpression = parseExpression('some expression');6console.log(parsedExpression);7const { parseExpression } = require('storybook-root-element');8const parsedExpression = parseExpression('some expression');9console.log(parsedExpression);10import { parseExpression } from 'storybook-root-element';11const parsedExpression = parseExpression('some expression');12console.log(parsedExpression);13const { parseExpression } = require('storybook-root-element');14const parsedExpression = parseExpression('some expression');15console.log(parsedExpression);16import { parseExpression } from 'storybook-root-element';17const parsedExpression = parseExpression('some expression');18console.log(parsedExpression);19const { parseExpression } = require('storybook-root-element');20const parsedExpression = parseExpression('some expression');21console.log(parsedExpression);22import { parseExpression } from 'storybook-root-element';23const parsedExpression = parseExpression('some expression');24console.log(parsedExpression);25import { parseExpression } from 'storybook-root-element';26const parsedExpression = parseExpression('some expression');27console.log(parsedExpression);28const { parseExpression } = require('storybook-root-element');29const parsedExpression = parseExpression('some expression');30console.log(parsedExpression);31const { parseExpression } = require('storybook-root-element');32const parsedExpression = parseExpression('some expression');33console.log(parsedExpression);34const { parseExpression } =
Using AI Code Generation
1import { parseExpression } from "storybook-root-attribute";2const story = parseExpression("story");3const storyA = parseExpression("storyA");4const storyB = parseExpression("storyB");5const storyC = parseExpression("storyC");6const storyD = parseExpression("storyD");7const storyE = parseExpression("storyE");8import { parseStory } from "storybook-root-attribute";9const story = parseStory("story");10const storyA = parseStory("storyA");11const storyB = parseStory("storyB");12const storyC = parseStory("storyC");13const storyD = parseStory("storyD");14const storyE = parseStory("storyE");15import { parseStories } from "storybook-root-attribute";16const story = parseStories("story");17const storyA = parseStories("storyA");18const storyB = parseStories("storyB");19const storyC = parseStories("storyC");20const storyD = parseStories("storyD");21const storyE = parseStories("storyE");22import { parseStoryPath } from "storybook-root-attribute";23const story = parseStoryPath("story");24const storyA = parseStoryPath("storyA");25const storyB = parseStoryPath("storyB");26const storyC = parseStoryPath("storyC");27const storyD = parseStoryPath("storyD");28const storyE = parseStoryPath("storyE");29import { parseStoriesPath } from "storybook-root-attribute";30const story = parseStoriesPath("story");31const storyA = parseStoriesPath("storyA");32const storyB = parseStoriesPath("storyB");33const storyC = parseStoriesPath("storyC");34const storyD = parseStoriesPath("storyD");35const storyE = parseStoriesPath("storyE");36import { parseStoryPathArray } from "storybook-root-attribute";37const story = parseStoryPathArray("story");38const storyA = parseStoryPathArray("storyA");39const storyB = parseStoryPathArray("storyB");40const storyC = parseStoryPathArray("storyC
Using AI Code Generation
1import { parseExpression } from '@storybook/addon-docs/blocks';2const codeString = parseExpression('const a = 1');3export default codeString;4import { Source } from '@storybook/addon-docs/blocks';5import test from './test.js';6<Source language="javascript" code={test} />7import { Source } from '@storybook/components';
Using AI Code Generation
1const { parseExpression } = require('storybook-root-elements');2const result = parseExpression('1 + 1');3console.log(result);4import { parseExpression } from 'storybook-root-elements';5const result = parseExpression('1 + 1');6console.log(result);7import { parseExpression } from 'storybook-root-elements';8const result = parseExpression('1 + 1');9console.log(result);10import { parseExpression } from 'storybook-root-elements';11const result = parseExpression('1 + 1');12console.log(result);13import { parseExpression } from 'storybook-root-elements';14const result = parseExpression('1 + 1');15console.log(result);16import { parseExpression } from 'storybook-root-elements';17const result = parseExpression('1 + 1');18console.log(result);19import { parseExpression } from 'storybook-root-elements';20const result = parseExpression('1 + 1');21console.log(result);22import { parseExpression } from 'storybook-root-elements';23const result = parseExpression('1 + 1');24console.log(result);
Using AI Code Generation
1var logger = require('storybook-root-logger');2var storybook = require('storybook');3var story = new storybook.Story();4var expression = '1+2';5var result = logger.parseExpression(expression, story);6console.log(result);7var storybook = require('storybook');8var story = new storybook.Story();9var expression = '1+2';10var result = storybook.Story.parseExpression(expression, story);11console.log(result);12var storybook = require('storybook');13var story = new storybook.Story();14var expression = '1+2';15var result = story.parseExpression(expression);16console.log(result);17var storybook = require('storybook');18var story = new storybook.Story();19var expression = '1+2';20var result = storybook.Story.parseExpression(expression, story);21console.log(result);22var storybook = require('storybook');23var story = new storybook.Story();24var expression = '1+2';25var result = story.parseExpression(expression);26console.log(result);27var storybook = require('storybook');28var story = new storybook.Story();29var expression = '1+2';30var result = storybook.Story.parseExpression(expression, story);31console.log(result);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!