Codebase list golang-github-vbauerster-mpb / 6d3a6a8
more draw tests Vladimir Bauer 4 years ago
1 changed file(s) with 415 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
450450 },
451451 99: {
452452 {
453 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
454 name: `t,c{100,1}Tip("だ")`,
453 style: BarStyle(),
454 name: "t,c{100,1}",
455455 total: 100,
456456 current: 1,
457 want: " [だつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
458 },
459 {
460 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
461 name: `t,c{100,2}Tip("だ")`,
462 total: 100,
463 current: 2,
464 want: " [だつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
465 },
466 {
467 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
468 name: `t,c{100,99}Tip("だ")`,
457 want: " [>----------------------------------------------------------------------------------------------] ",
458 },
459 {
460 style: BarStyle(),
461 name: "t,c{100,1}trim",
462 total: 100,
463 current: 1,
464 trim: true,
465 want: "[>------------------------------------------------------------------------------------------------]",
466 },
467 {
468 style: BarStyle(),
469 name: "t,c,r{100,40,33}",
470 total: 100,
471 current: 40,
472 refill: 33,
473 want: " [+++++++++++++++++++++++++++++++======>---------------------------------------------------------] ",
474 },
475 {
476 style: BarStyle(),
477 name: "t,c,r{100,40,33}trim",
478 total: 100,
479 current: 40,
480 refill: 33,
481 trim: true,
482 want: "[++++++++++++++++++++++++++++++++======>----------------------------------------------------------]",
483 },
484 {
485 style: BarStyle().Tip("<").Reverse(),
486 name: "t,c,r{100,40,33},rev",
487 total: 100,
488 current: 40,
489 refill: 33,
490 want: " [---------------------------------------------------------<======+++++++++++++++++++++++++++++++] ",
491 },
492 {
493 style: BarStyle().Tip("<").Reverse(),
494 name: "t,c,r{100,40,33}trim,rev",
495 total: 100,
496 current: 40,
497 refill: 33,
498 trim: true,
499 want: "[----------------------------------------------------------<======++++++++++++++++++++++++++++++++]",
500 },
501 {
502 style: BarStyle(),
503 name: "t,c{100,99}",
469504 total: 100,
470505 current: 99,
471 want: " [ののののののののののののののののののののののののののののののののののののののののののののののだ…] ",
472 },
473 {
474 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
475 name: `t,c{100,100}Tip("だ")`,
476 total: 100,
477 current: 100,
478 want: " [ののののののののののののののののののののののののののののののののののののののののののののののの…] ",
479 },
480 {
481 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]").Reverse(),
482 name: `t,c{100,100}Tip("だ")rev`,
483 total: 100,
484 current: 100,
485 want: " […ののののののののののののののののののののののののののののののののののののののののののののののの] ",
506 want: " [=============================================================================================>-] ",
507 },
508 {
509 style: BarStyle(),
510 name: "t,c{100,99}trim",
511 total: 100,
512 current: 99,
513 trim: true,
514 want: "[===============================================================================================>-]",
515 },
516 {
517 style: BarStyle(),
518 name: "t,c{100,100}",
519 total: 100,
520 current: 100,
521 want: " [===============================================================================================] ",
522 },
523 {
524 style: BarStyle(),
525 name: "t,c{100,100}trim",
526 total: 100,
527 current: 100,
528 trim: true,
529 want: "[=================================================================================================]",
530 },
531 {
532 style: BarStyle(),
533 name: "t,c,r{100,100,99}",
534 total: 100,
535 current: 100,
536 refill: 99,
537 want: " [++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=] ",
538 },
539 {
540 style: BarStyle(),
541 name: "t,c,r{100,100,99}trim",
542 total: 100,
543 current: 100,
544 refill: 99,
545 trim: true,
546 want: "[++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=]",
547 },
548 {
549 style: BarStyle().Tip("<").Reverse(),
550 name: "t,c,r{100,100,99}rev",
551 total: 100,
552 current: 100,
553 refill: 99,
554 want: " [=++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++] ",
555 },
556 {
557 style: BarStyle().Tip("<").Reverse(),
558 name: "t,c,r{100,100,99}trim,rev",
559 total: 100,
560 current: 100,
561 refill: 99,
562 trim: true,
563 want: "[=++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]",
564 },
565 {
566 style: BarStyle(),
567 name: "t,c,r{100,100,100}",
568 total: 100,
569 current: 100,
570 refill: 100,
571 want: " [+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++] ",
572 },
573 {
574 style: BarStyle(),
575 name: "t,c,r{100,100,100}trim",
576 total: 100,
577 current: 100,
578 refill: 100,
579 trim: true,
580 want: "[+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]",
581 },
582 {
583 style: BarStyle().Tip("<").Reverse(),
584 name: "t,c,r{100,100,100}rev",
585 total: 100,
586 current: 100,
587 refill: 100,
588 want: " [+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++] ",
589 },
590 {
591 style: BarStyle().Tip("<").Reverse(),
592 name: "t,c,r{100,100,100}trim",
593 total: 100,
594 current: 100,
595 refill: 100,
596 trim: true,
597 want: "[+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]",
486598 },
487599 },
488600 100: {
581693 want: "[++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]",
582694 },
583695 {
584 style: BarStyle().Tip("", "<").Reverse(),
696 style: BarStyle().Tip("<").Reverse(),
585697 name: "t,c,r{100,100,99}rev",
586698 total: 100,
587699 current: 100,
589701 want: " [=+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++] ",
590702 },
591703 {
592 style: BarStyle().Tip("", "<").Reverse(),
704 style: BarStyle().Tip("<").Reverse(),
593705 name: "t,c,r{100,100,99}trim,rev",
594706 total: 100,
595707 current: 100,
598710 want: "[=+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]",
599711 },
600712 {
601 style: BarStyle().Tip("", "<").Reverse(),
713 style: BarStyle().Tip("<").Reverse(),
602714 name: "t,c,r{100,100,100}rev",
603715 total: 100,
604716 current: 100,
606718 want: " [++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++] ",
607719 },
608720 {
609 style: BarStyle().Tip("", "<").Reverse(),
721 style: BarStyle().Tip("<").Reverse(),
610722 name: "t,c,r{100,100,100}trim",
611723 total: 100,
612724 current: 100,
11201232 },
11211233 99: {
11221234 {
1123 style: BarStyle().Lbound("[").Filler("の").Tip("だ").TipOnComplete("だ").Padding("つ").Rbound("]"),
1124 name: `t,c{100,99}Tip("だ").TipOnComplete("だ")`,
1235 style: BarStyle().TipOnComplete(">"),
1236 name: "t,c{100,1}",
1237 total: 100,
1238 current: 1,
1239 want: " [>----------------------------------------------------------------------------------------------] ",
1240 },
1241 {
1242 style: BarStyle().TipOnComplete(">"),
1243 name: "t,c{100,1}trim",
1244 total: 100,
1245 current: 1,
1246 trim: true,
1247 want: "[>------------------------------------------------------------------------------------------------]",
1248 },
1249 {
1250 style: BarStyle().TipOnComplete(">"),
1251 name: "t,c,r{100,40,33}",
1252 total: 100,
1253 current: 40,
1254 refill: 33,
1255 want: " [+++++++++++++++++++++++++++++++======>---------------------------------------------------------] ",
1256 },
1257 {
1258 style: BarStyle().TipOnComplete(">"),
1259 name: "t,c,r{100,40,33}trim",
1260 total: 100,
1261 current: 40,
1262 refill: 33,
1263 trim: true,
1264 want: "[++++++++++++++++++++++++++++++++======>----------------------------------------------------------]",
1265 },
1266 {
1267 style: BarStyle().Tip("<").Reverse().TipOnComplete(">"),
1268 name: "t,c,r{100,40,33},rev",
1269 total: 100,
1270 current: 40,
1271 refill: 33,
1272 want: " [---------------------------------------------------------<======+++++++++++++++++++++++++++++++] ",
1273 },
1274 {
1275 style: BarStyle().Tip("<").Reverse().TipOnComplete(">"),
1276 name: "t,c,r{100,40,33}trim,rev",
1277 total: 100,
1278 current: 40,
1279 refill: 33,
1280 trim: true,
1281 want: "[----------------------------------------------------------<======++++++++++++++++++++++++++++++++]",
1282 },
1283 {
1284 style: BarStyle().TipOnComplete(">"),
1285 name: "t,c{100,99}",
11251286 total: 100,
11261287 current: 99,
1127 want: " [ののののののののののののののののののののののののののののののののののののののののののののののだ…] ",
1128 },
1129 {
1130 style: BarStyle().Lbound("[").Filler("の").Tip("だ").TipOnComplete("だ").Padding("つ").Rbound("]"),
1131 name: `t,c{100,100}Tip("だ").TipOnComplete("だ")`,
1132 total: 100,
1133 current: 100,
1134 want: " [ののののののののののののののののののののののののののののののののののののののののののののののだ…] ",
1135 },
1136 {
1137 style: BarStyle().Lbound("[").Filler("の").Tip("だ").TipOnComplete("だ").Padding("つ").Rbound("]").Reverse(),
1138 name: `t,c{100,100}Tip("だ").TipOnComplete("だ")rev`,
1139 total: 100,
1140 current: 100,
1141 want: " […だのののののののののののののののののののののののののののののののののののののののののののののの] ",
1288 want: " [=============================================================================================>-] ",
1289 },
1290 {
1291 style: BarStyle().TipOnComplete(">"),
1292 name: "t,c{100,99}trim",
1293 total: 100,
1294 current: 99,
1295 trim: true,
1296 want: "[===============================================================================================>-]",
1297 },
1298 {
1299 style: BarStyle().TipOnComplete(">"),
1300 name: "t,c{100,100}",
1301 total: 100,
1302 current: 100,
1303 want: " [==============================================================================================>] ",
1304 },
1305 {
1306 style: BarStyle().TipOnComplete(">"),
1307 name: "t,c{100,100}trim",
1308 total: 100,
1309 current: 100,
1310 trim: true,
1311 want: "[================================================================================================>]",
1312 },
1313 {
1314 style: BarStyle().TipOnComplete(">"),
1315 name: "t,c,r{100,100,99}",
1316 total: 100,
1317 current: 100,
1318 refill: 99,
1319 want: " [++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>] ",
1320 },
1321 {
1322 style: BarStyle().TipOnComplete(">"),
1323 name: "t,c,r{100,100,99}trim",
1324 total: 100,
1325 current: 100,
1326 refill: 99,
1327 trim: true,
1328 want: "[++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>]",
1329 },
1330 {
1331 style: BarStyle().TipOnComplete("<").Reverse(),
1332 name: `t,c,r{100,100,99}TipOnComplete("<").Reverse()`,
1333 total: 100,
1334 current: 100,
1335 refill: 99,
1336 want: " [<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++] ",
1337 },
1338 {
1339 style: BarStyle().TipOnComplete("<").Reverse(),
1340 name: `t,c,r{100,100,99}TipOnComplete("<").Reverse()trim`,
1341 total: 100,
1342 current: 100,
1343 refill: 99,
1344 trim: true,
1345 want: "[<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]",
1346 },
1347 {
1348 style: BarStyle().TipOnComplete(">"),
1349 name: "t,c,r{100,100,100}",
1350 total: 100,
1351 current: 100,
1352 refill: 100,
1353 want: " [++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>] ",
1354 },
1355 {
1356 style: BarStyle().TipOnComplete(">"),
1357 name: "t,c,r{100,100,100}trim",
1358 total: 100,
1359 current: 100,
1360 refill: 100,
1361 trim: true,
1362 want: "[++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>]",
1363 },
1364 {
1365 style: BarStyle().Tip("<").TipOnComplete("<").Reverse(),
1366 name: `t,c,r{100,100,100}Tip("<").TipOnComplete("<").Reverse()`,
1367 total: 100,
1368 current: 100,
1369 refill: 100,
1370 want: " [<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++] ",
1371 },
1372 {
1373 style: BarStyle().Tip("<").Reverse().TipOnComplete("<"),
1374 name: "t,c,r{100,100,100}trim",
1375 total: 100,
1376 current: 100,
1377 refill: 100,
1378 trim: true,
1379 want: "[<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]",
11421380 },
11431381 },
11441382 100: {
13031541 refill: 33,
13041542 trim: true,
13051543 want: "[-----------------------------------------------------------<======++++++++++++++++++++++++++++++++]",
1544 },
1545 },
1546 }
1547
1548 var tmpBuf bytes.Buffer
1549 for tw, cases := range testSuite {
1550 for _, tc := range cases {
1551 s := newTestState(NewBarFiller(tc.style))
1552 s.reqWidth = tc.barWidth
1553 s.total = tc.total
1554 s.current = tc.current
1555 s.trimSpace = tc.trim
1556 s.refill = tc.refill
1557 tmpBuf.Reset()
1558 tmpBuf.ReadFrom(s.draw(newStatistics(tw, s)))
1559 by := tmpBuf.Bytes()
1560
1561 got := string(by[:len(by)-1])
1562 if !utf8.ValidString(got) {
1563 t.Fail()
1564 }
1565 if got != tc.want {
1566 t.Errorf("termWidth:%d %q want: %q %d, got: %q %d\n", tw, tc.name, tc.want, utf8.RuneCountInString(tc.want), got, utf8.RuneCountInString(got))
1567 }
1568 }
1569 }
1570 }
1571
1572 func TestDrawDoubleWidth(t *testing.T) {
1573 // key is termWidth
1574 testSuite := map[int][]struct {
1575 style BarStyleComposer
1576 name string
1577 total int64
1578 current int64
1579 refill int64
1580 barWidth int
1581 trim bool
1582 want string
1583 }{
1584 99: {
1585 {
1586 style: BarStyle().Lbound("の").Rbound("の"),
1587 name: `t,c{100,1}.Lbound("の").Rbound("の")`,
1588 total: 100,
1589 current: 1,
1590 want: " の>--------------------------------------------------------------------------------------------の ",
1591 },
1592 {
1593 style: BarStyle().Lbound("の").Rbound("の"),
1594 name: `t,c{100,1}.Lbound("の").Rbound("の")`,
1595 total: 100,
1596 current: 2,
1597 want: " の=>-------------------------------------------------------------------------------------------の ",
1598 },
1599 {
1600 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
1601 name: `t,c{100,1}Tip("だ")`,
1602 total: 100,
1603 current: 1,
1604 want: " [だつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
1605 },
1606 {
1607 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
1608 name: `t,c{100,2}Tip("だ")`,
1609 total: 100,
1610 current: 2,
1611 want: " [だつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
1612 },
1613 {
1614 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
1615 name: `t,c{100,99}Tip("だ")`,
1616 total: 100,
1617 current: 99,
1618 want: " [ののののののののののののののののののののののののののののののののののののののののののののののだ…] ",
1619 },
1620 {
1621 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
1622 name: `t,c{100,100}Tip("だ")`,
1623 total: 100,
1624 current: 100,
1625 want: " […ののののののののののののののののののののののののののののののののののののののののののののののの] ",
1626 },
1627 {
1628 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]").Reverse(),
1629 name: `t,c{100,100}Tip("だ")rev`,
1630 total: 100,
1631 current: 100,
1632 want: " [ののののののののののののののののののののののののののののののののののののののののののののののの…] ",
1633 },
1634 {
1635 style: BarStyle().Lbound("[").Filler("の").Tip("だ").TipOnComplete("だ").Padding("つ").Rbound("]"),
1636 name: `t,c{100,99}Tip("だ").TipOnComplete("だ")`,
1637 total: 100,
1638 current: 99,
1639 want: " [ののののののののののののののののののののののののののののののののののののののののののののののだ…] ",
1640 },
1641 {
1642 style: BarStyle().Lbound("[").Filler("の").Tip("だ").TipOnComplete("だ").Padding("つ").Rbound("]"),
1643 name: `t,c{100,100}Tip("だ").TipOnComplete("だ")`,
1644 total: 100,
1645 current: 100,
1646 want: " […ののののののののののののののののののののののののののののののののののののののののののののののだ] ",
1647 },
1648 {
1649 style: BarStyle().Lbound("[").Filler("の").Tip("だ").TipOnComplete("だ").Padding("つ").Rbound("]").Reverse(),
1650 name: `t,c{100,100}Tip("だ").TipOnComplete("だ")rev`,
1651 total: 100,
1652 current: 100,
1653 want: " [だのののののののののののののののののののののののののののののののののののののののののののののの…] ",
1654 },
1655 {
1656 style: BarStyle().Refiller("の"),
1657 name: `t,c,r{100,100,99}Refiller("の")`,
1658 total: 100,
1659 current: 100,
1660 refill: 99,
1661 want: " [ののののののののののののののののののののののののののののののののののののののののののののののの=] ",
1662 },
1663 {
1664 style: BarStyle().Refiller("の"),
1665 name: `t,c,r{100,100,99}Refiller("の")trim`,
1666 total: 100,
1667 current: 100,
1668 refill: 99,
1669 trim: true,
1670 want: "[のののののののののののののののののののののののののののののののののののののののののののののののの=]",
13061671 },
13071672 },
13081673 }