File: 20merge-tags.t

package info (click to toggle)
libstring-tagged-perl 0.24-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 304 kB
  • sloc: perl: 2,105; makefile: 2
file content (130 lines) | stat: -rw-r--r-- 3,058 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

use String::Tagged;

my $str = String::Tagged->new( "Hello, world" );

$str->apply_tag( 0, 6, message => 1 );
$str->apply_tag( 6, 6, message => 1 );

my @tags;
$str->iter_tags( sub { push @tags, [ @_ ] } );
is( \@tags, 
           [
              [ 0, 6, message => 1 ],
              [ 6, 6, message => 1 ],
           ],
           'tags list before merge' );

$str->merge_tags( sub { $_[1] == $_[2] } );

undef @tags;
$str->iter_tags( sub { push @tags, [ @_ ] } );
is( \@tags, 
           [
              [ 0, 12, message => 1 ],
           ],
           'tags list after merge' );

$str = String::Tagged->new( "Hello, world" );

$str->apply_tag( 0, 6, message => 1 );
$str->apply_tag( 6, 6, message => 2 );

$str->merge_tags( sub { $_[1] == $_[2] } );

undef @tags;
$str->iter_tags( sub { push @tags, [ @_ ] } );
is( \@tags, 
           [
              [ 0, 6, message => 1 ],
              [ 6, 6, message => 2 ],
           ],
           'tags list after merge differing values' );

$str = String::Tagged->new( "Hello, world" );

$str->apply_tag( 0, 6, message => 1 );
$str->apply_tag( 6, 6, others  => 1 );

$str->merge_tags( sub { $_[1] == $_[2] } );

undef @tags;
$str->iter_tags( sub { push @tags, [ @_ ] } );
is( \@tags, 
           [
              [ 0, 6, message => 1 ],
              [ 6, 6, others  => 1 ],
           ],
           'tags list after merge differing names' );

$str = String::Tagged->new( "Hello, world" );

$str->apply_tag( 0, 4, message => 1 );
$str->apply_tag( 4, 4, message => 1 );
$str->apply_tag( 8, 4, message => 1 );

$str->merge_tags( sub { $_[1] == $_[2] } );

undef @tags;
$str->iter_tags( sub { push @tags, [ @_ ] } );
is( \@tags, 
           [
              [ 0, 12, message => 1 ],
           ],
           'tags list after merge 3' );

$str = String::Tagged->new( "Hello, world" );

$str->apply_tag( 0,  4, message => 1 );
$str->apply_tag( 8, 12, message => 1 );

$str->merge_tags( sub { $_[1] == $_[2] } );

undef @tags;
$str->iter_tags( sub { push @tags, [ @_ ] } );
is( \@tags, 
           [
              [ 0, 4, message => 1 ],
              [ 8, 4, message => 1 ],
           ],
           'tags list after merge non-overlap' );

$str = String::Tagged->new( "Hello, world" );

$str->apply_tag( 0,  8, message => 1 );
$str->apply_tag( 4, 12, message => 1 );

$str->merge_tags( sub { $_[1] == $_[2] } );

undef @tags;
$str->iter_tags( sub { push @tags, [ @_ ] } );
is( \@tags, 
           [
              [ 0, 12, message => 1 ],
           ],
           'tags list after merge with overlap' );

$str = String::Tagged->new( "Hello, world" );

$str->apply_tag( 0,  5, word => 1 );
$str->apply_tag( 0,  1, message => 1 );
$str->apply_tag( 1, 11, message => 1 );

$str->merge_tags( sub { $_[1] == $_[2] } );

undef @tags;
$str->iter_tags( sub { push @tags, [ @_ ] } );
is( \@tags, 
           [
              [ 0,  5, word    => 1 ],
              [ 0, 12, message => 1 ],
           ],
           'tags list after merge with overlap' );

done_testing;