|
545 | 545 | expect(result).to.equal(testAttributedString); |
546 | 546 | }); |
547 | 547 |
|
| 548 | + it(@"last instance", ^{ |
| 549 | + NSAttributedString *result = [testString makeString:^(BOStringMaker *make) { |
| 550 | + make.last.substring(@"is", ^{ |
| 551 | + make.foregroundColor([BOSColor greenColor]); |
| 552 | + }); |
| 553 | + }]; |
| 554 | + |
| 555 | + NSMutableAttributedString *testAttributedString = [[NSMutableAttributedString alloc] initWithString:testString]; |
| 556 | + [testAttributedString addAttribute:NSForegroundColorAttributeName value:[BOSColor greenColor] range:NSMakeRange(5, 2)]; |
| 557 | + |
| 558 | + expect(result).to.equal(testAttributedString); |
| 559 | + }); |
| 560 | + |
548 | 561 | it(@"all instances", ^{ |
549 | 562 | NSAttributedString *result = [testString makeString:^(BOStringMaker *make) { |
550 | 563 | make.each.substring(@"is", ^{ |
|
565 | 578 | make.foregroundColor([BOSColor greenColor]); |
566 | 579 | }); |
567 | 580 | }]; |
568 | | - |
| 581 | + |
569 | 582 | NSMutableAttributedString *testAttributedString = [[NSMutableAttributedString alloc] initWithString:testString]; |
570 | 583 | [testAttributedString addAttribute:NSForegroundColorAttributeName value:[BOSColor greenColor] range:NSMakeRange(8, 2)]; |
571 | 584 |
|
572 | 585 | expect(result).to.equal(testAttributedString); |
573 | 586 | }); |
| 587 | + |
| 588 | + it(@"last regexp match", ^{ |
| 589 | + NSAttributedString *result = [testString makeString:^(BOStringMaker *make) { |
| 590 | + make.last.regexpMatch(@"i\\w", 0, ^{ // should highlight `in` in `string` |
| 591 | + make.foregroundColor([BOSColor greenColor]); |
| 592 | + }); |
| 593 | + }]; |
| 594 | + |
| 595 | + NSMutableAttributedString *testAttributedString = [[NSMutableAttributedString alloc] initWithString:testString]; |
| 596 | + [testAttributedString addAttribute:NSForegroundColorAttributeName value:[BOSColor greenColor] range:NSMakeRange(14, 2)]; |
| 597 | + |
| 598 | + expect(result).to.equal(testAttributedString); |
| 599 | + }); |
574 | 600 |
|
575 | 601 | it(@"all regexp matches", ^{ |
576 | 602 | NSAttributedString *result = [testString makeString:^(BOStringMaker *make) { |
|
589 | 615 |
|
590 | 616 | it(@"first regexp group", ^{ |
591 | 617 | NSAttributedString *result = [testString makeString:^(BOStringMaker *make) { |
592 | | - make.first.regexpGroup(@"\\s(i\\w)\\s", 0, ^{ // should highlight `This _is_ my string` |
| 618 | + make.first.regexpGroup(@"(i\\w)\\s", 0, ^{ // should highlight `Th_is_ is my string` |
593 | 619 | make.foregroundColor([BOSColor greenColor]); |
594 | 620 | }); |
595 | 621 | }]; |
| 622 | + |
| 623 | + NSMutableAttributedString *testAttributedString = [[NSMutableAttributedString alloc] initWithString:testString]; |
| 624 | + [testAttributedString addAttribute:NSForegroundColorAttributeName value:[BOSColor greenColor] range:NSMakeRange(2, 2)]; |
| 625 | + |
| 626 | + expect(result).to.equal(testAttributedString); |
| 627 | + }); |
596 | 628 |
|
| 629 | + it(@"last regexp group", ^{ |
| 630 | + NSAttributedString *result = [testString makeString:^(BOStringMaker *make) { |
| 631 | + make.last.regexpGroup(@"(i\\w)\\s", 0, ^{ // should highlight `This _is_ my string` |
| 632 | + make.foregroundColor([BOSColor greenColor]); |
| 633 | + }); |
| 634 | + }]; |
| 635 | + |
597 | 636 | NSMutableAttributedString *testAttributedString = [[NSMutableAttributedString alloc] initWithString:testString]; |
598 | 637 | [testAttributedString addAttribute:NSForegroundColorAttributeName value:[BOSColor greenColor] range:NSMakeRange(5, 2)]; |
599 | | - |
| 638 | + |
600 | 639 | expect(result).to.equal(testAttributedString); |
601 | 640 | }); |
602 | 641 |
|
603 | 642 | it(@"first regexp multiple groups", ^{ |
604 | 643 | NSAttributedString *result = [testString makeString:^(BOStringMaker *make) { |
605 | | - make.first.regexpGroup(@"\\s(i\\w)\\s(\\w{2})\\s", 0, ^{ // should highlight `This _is_ _my_ string` |
| 644 | + make.first.regexpGroup(@"(\\w{2})\\s(\\w{2})", 0, ^{ // should highlight `Th_is_ _is_ my string` |
606 | 645 | make.foregroundColor([BOSColor greenColor]); |
607 | 646 | }); |
608 | 647 | }]; |
609 | | - |
| 648 | + |
610 | 649 | NSMutableAttributedString *testAttributedString = [[NSMutableAttributedString alloc] initWithString:testString]; |
| 650 | + [testAttributedString addAttribute:NSForegroundColorAttributeName value:[BOSColor greenColor] range:NSMakeRange(2, 2)]; |
611 | 651 | [testAttributedString addAttribute:NSForegroundColorAttributeName value:[BOSColor greenColor] range:NSMakeRange(5, 2)]; |
| 652 | + |
| 653 | + expect(result).to.equal(testAttributedString); |
| 654 | + }); |
| 655 | + |
| 656 | + it(@"last regexp multiple groups", ^{ |
| 657 | + NSAttributedString *result = [testString makeString:^(BOStringMaker *make) { |
| 658 | + make.last.regexpGroup(@"(\\w{2})\\s(\\w{2})", 0, ^{ // should highlight `This is _my_ _st_ring` |
| 659 | + make.foregroundColor([BOSColor greenColor]); |
| 660 | + }); |
| 661 | + }]; |
| 662 | + |
| 663 | + NSMutableAttributedString *testAttributedString = [[NSMutableAttributedString alloc] initWithString:testString]; |
612 | 664 | [testAttributedString addAttribute:NSForegroundColorAttributeName value:[BOSColor greenColor] range:NSMakeRange(8, 2)]; |
| 665 | + [testAttributedString addAttribute:NSForegroundColorAttributeName value:[BOSColor greenColor] range:NSMakeRange(11, 2)]; |
613 | 666 |
|
614 | 667 | expect(result).to.equal(testAttributedString); |
615 | 668 | }); |
|
0 commit comments