@@ -247,6 +247,34 @@ void main() {
247
247
});
248
248
});
249
249
250
+ group ("attribution queries >" , () {
251
+ test ('finds spans that exceed plain text length' , () {
252
+ final attributedText = AttributedText (
253
+ 'Hello world' ,
254
+ AttributedSpans (
255
+ attributions: [
256
+ const SpanMarker (attribution: ExpectedSpans .bold, offset: 0 , markerType: SpanMarkerType .start),
257
+ const SpanMarker (attribution: ExpectedSpans .bold, offset: 12 , markerType: SpanMarkerType .end),
258
+ ],
259
+ ),
260
+ {
261
+ 11 : const _FakePlaceholder ("trailing1" ),
262
+ 12 : const _FakePlaceholder ("trailing2" ),
263
+ },
264
+ );
265
+
266
+ final ranges = attributedText.getAttributionSpans ({ExpectedSpans .bold});
267
+
268
+ expect (ranges.length, 1 );
269
+ expect (
270
+ ranges,
271
+ [
272
+ const AttributionSpan (attribution: ExpectedSpans .bold, start: 0 , end: 12 ),
273
+ ],
274
+ );
275
+ });
276
+ });
277
+
250
278
group ("full copy >" , () {
251
279
test ("only a single placeholder" , () {
252
280
expect (
@@ -463,6 +491,66 @@ void main() {
463
491
}),
464
492
);
465
493
});
494
+
495
+ test ("at end of text (with attributions) with leading placeholder" , () {
496
+ // Note: We include attributions in this test because in a client app the presence
497
+ // of attributions unearthed a bug where we were still using the plain text
498
+ // length, when we should have been using the text + placeholders length.
499
+ expect (
500
+ AttributedText (
501
+ "Hello" ,
502
+ AttributedSpans (attributions: const [
503
+ SpanMarker (attribution: ExpectedSpans .bold, offset: 1 , markerType: SpanMarkerType .start),
504
+ SpanMarker (attribution: ExpectedSpans .bold, offset: 5 , markerType: SpanMarkerType .end),
505
+ ]),
506
+ {
507
+ 0 : const _FakePlaceholder ("leading" ),
508
+ },
509
+ ).copyAndAppend (
510
+ AttributedText (", world!" ),
511
+ ),
512
+ AttributedText (
513
+ "Hello, world!" ,
514
+ AttributedSpans (attributions: const [
515
+ SpanMarker (attribution: ExpectedSpans .bold, offset: 1 , markerType: SpanMarkerType .start),
516
+ SpanMarker (attribution: ExpectedSpans .bold, offset: 5 , markerType: SpanMarkerType .end),
517
+ ]),
518
+ {
519
+ 0 : const _FakePlaceholder ("leading" ),
520
+ },
521
+ ),
522
+ );
523
+ });
524
+
525
+ test ("at end of text (with attributions) with trailing placeholder" , () {
526
+ // Note: We include attributions in this test because in a client app the presence
527
+ // of attributions unearthed a bug where we were still using the plain text
528
+ // length, when we should have been using the text + placeholders length.
529
+ expect (
530
+ AttributedText (
531
+ "Hello" ,
532
+ AttributedSpans (attributions: const [
533
+ SpanMarker (attribution: ExpectedSpans .bold, offset: 0 , markerType: SpanMarkerType .start),
534
+ SpanMarker (attribution: ExpectedSpans .bold, offset: 4 , markerType: SpanMarkerType .end),
535
+ ]),
536
+ {
537
+ 5 : const _FakePlaceholder ("trailing" ),
538
+ },
539
+ ).copyAndAppend (
540
+ AttributedText (", world!" ),
541
+ ),
542
+ AttributedText (
543
+ "Hello, world!" ,
544
+ AttributedSpans (attributions: const [
545
+ SpanMarker (attribution: ExpectedSpans .bold, offset: 0 , markerType: SpanMarkerType .start),
546
+ SpanMarker (attribution: ExpectedSpans .bold, offset: 4 , markerType: SpanMarkerType .end),
547
+ ]),
548
+ {
549
+ 5 : const _FakePlaceholder ("trailing" ),
550
+ },
551
+ ),
552
+ );
553
+ });
466
554
});
467
555
468
556
test ("insert attributed text >" , () {
@@ -576,6 +664,38 @@ void main() {
576
664
),
577
665
);
578
666
});
667
+
668
+ group ("collapses spans >" , () {
669
+ test ("when placeholders sit beyond plain text" , () {
670
+ final attributedText = AttributedText (
671
+ 'Hello world' ,
672
+ AttributedSpans (
673
+ attributions: [
674
+ const SpanMarker (attribution: ExpectedSpans .bold, offset: 0 , markerType: SpanMarkerType .start),
675
+ const SpanMarker (attribution: ExpectedSpans .bold, offset: 11 , markerType: SpanMarkerType .end),
676
+ const SpanMarker (attribution: ExpectedSpans .underline, offset: 12 , markerType: SpanMarkerType .start),
677
+ const SpanMarker (attribution: ExpectedSpans .underline, offset: 12 , markerType: SpanMarkerType .end),
678
+ ],
679
+ ),
680
+ {
681
+ 11 : const _FakePlaceholder ("trailing1" ),
682
+ 12 : const _FakePlaceholder ("trailing2" ),
683
+ },
684
+ );
685
+
686
+ final spans = attributedText.computeAttributionSpans ().toList ();
687
+
688
+ expect (spans.length, 2 );
689
+
690
+ expect (spans[0 ].attributions, {ExpectedSpans .bold});
691
+ expect (spans[0 ].start, 0 );
692
+ expect (spans[0 ].end, 11 );
693
+
694
+ expect (spans[1 ].attributions, {ExpectedSpans .underline});
695
+ expect (spans[1 ].start, 12 );
696
+ expect (spans[1 ].end, 12 );
697
+ });
698
+ });
579
699
});
580
700
}
581
701
0 commit comments