Skip to content

Commit 37b1ab2

Browse files
committed
Adding tests for AttributedSpans.contractAttributions
1 parent f7b0b59 commit 37b1ab2

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

attributed_text/test/attributed_spans_test.dart

+77
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,83 @@ void main() {
632632
expect(span1 == span2, isFalse);
633633
});
634634
});
635+
636+
group('contract attributions', () {
637+
group('empty attributions', () {
638+
test('start at 0, length 0', () {
639+
final spans = AttributedSpans();
640+
final contractedSpans = spans.copy()..contractAttributions(startOffset: 0, count: 0);
641+
expect(contractedSpans, spans);
642+
});
643+
644+
test('start at 0, length 10', () {
645+
final spans = AttributedSpans();
646+
final contractedSpans = spans.copy()..contractAttributions(startOffset: 0, count: 10);
647+
expect(contractedSpans, spans);
648+
});
649+
650+
test('start at 0, length 10', () {
651+
final spans = AttributedSpans();
652+
final contractedSpans = spans.copy()..contractAttributions(startOffset: 5, count: 10);
653+
});
654+
});
655+
656+
group('single attribution', () {
657+
test('contract after of attribution', () {
658+
final spans = AttributedSpans()..addAttribution(newAttribution: ExpectedSpans.bold, start: 0, end: 5);
659+
final contractedSpans = spans.copy()..contractAttributions(startOffset: 6, count: 5);
660+
expect(contractedSpans, spans);
661+
});
662+
663+
test('contract before attribution', () {
664+
final spans = AttributedSpans()..addAttribution(newAttribution: ExpectedSpans.bold, start: 5, end: 10);
665+
final contractedSpans = spans.copy()..contractAttributions(startOffset: 0, count: 5);
666+
expect(
667+
contractedSpans,
668+
AttributedSpans()
669+
..addAttribution(
670+
newAttribution: ExpectedSpans.bold,
671+
start: 0,
672+
end: 5,
673+
),
674+
);
675+
});
676+
677+
test('contract around attribution', () {
678+
final spans = AttributedSpans()..addAttribution(newAttribution: ExpectedSpans.bold, start: 5, end: 10);
679+
final contractedSpans = spans.copy()..contractAttributions(startOffset: 5, count: 6);
680+
expect(contractedSpans.markers, isEmpty);
681+
});
682+
683+
test('contract from start to middle of attribution', () {
684+
final spans = AttributedSpans()..addAttribution(newAttribution: ExpectedSpans.bold, start: 5, end: 10);
685+
final contractedSpans = spans.copy()..contractAttributions(startOffset: 5, count: 3);
686+
expect(
687+
contractedSpans,
688+
AttributedSpans()
689+
..addAttribution(
690+
newAttribution: ExpectedSpans.bold,
691+
start: 5,
692+
end: 7,
693+
),
694+
);
695+
});
696+
697+
test('contract from middle to end of attribution', () {
698+
final spans = AttributedSpans()..addAttribution(newAttribution: ExpectedSpans.bold, start: 5, end: 10);
699+
final contractedSpans = spans.copy()..contractAttributions(startOffset: 7, count: 3);
700+
expect(
701+
contractedSpans,
702+
AttributedSpans()
703+
..addAttribution(
704+
newAttribution: ExpectedSpans.bold,
705+
start: 5,
706+
end: 7,
707+
),
708+
);
709+
});
710+
});
711+
});
635712
});
636713
}
637714

0 commit comments

Comments
 (0)