@@ -60,96 +60,96 @@ describe('splitByAbbreviations', () => {
6060
6161 it ( 'returns a single plain segment when the map is empty' , ( ) => {
6262 expect ( splitByAbbreviations ( 'hello FOSS world' , new Map ( ) ) ) . toEqual ( [
63- { text : 'hello FOSS world' } ,
63+ { id : 'txt-0' , text : 'hello FOSS world' } ,
6464 ] ) ;
6565 } ) ;
6666
6767 it ( 'returns a single plain segment when there are no matches' , ( ) => {
68- expect ( splitByAbbreviations ( 'hello world' , map ) ) . toEqual ( [ { text : 'hello world' } ] ) ;
68+ expect ( splitByAbbreviations ( 'hello world' , map ) ) . toEqual ( [ { id : 'txt-0' , text : 'hello world' } ] ) ;
6969 } ) ;
7070
7171 it ( 'returns a single plain segment for an empty string' , ( ) => {
72- expect ( splitByAbbreviations ( '' , map ) ) . toEqual ( [ { text : '' } ] ) ;
72+ expect ( splitByAbbreviations ( '' , map ) ) . toEqual ( [ { id : 'txt-0' , text : '' } ] ) ;
7373 } ) ;
7474
7575 it ( 'splits a term match in the middle of a string' , ( ) => {
7676 expect ( splitByAbbreviations ( 'Use FOSS software' , map ) ) . toEqual ( [
77- { text : 'Use ' } ,
78- { text : 'FOSS' , termKey : 'foss' } ,
79- { text : ' software' } ,
77+ { id : 'txt-0' , text : 'Use ' } ,
78+ { id : 'txt-1' , text : 'FOSS' , termKey : 'foss' } ,
79+ { id : 'txt-2' , text : ' software' } ,
8080 ] ) ;
8181 } ) ;
8282
8383 it ( 'splits a term match at the start of a string' , ( ) => {
8484 expect ( splitByAbbreviations ( 'FOSS is great' , map ) ) . toEqual ( [
85- { text : 'FOSS' , termKey : 'foss' } ,
86- { text : ' is great' } ,
85+ { id : 'txt-0' , text : 'FOSS' , termKey : 'foss' } ,
86+ { id : 'txt-1' , text : ' is great' } ,
8787 ] ) ;
8888 } ) ;
8989
9090 it ( 'splits a term match at the end of a string' , ( ) => {
9191 expect ( splitByAbbreviations ( 'I love FOSS' , map ) ) . toEqual ( [
92- { text : 'I love ' } ,
93- { text : 'FOSS' , termKey : 'foss' } ,
92+ { id : 'txt-0' , text : 'I love ' } ,
93+ { id : 'txt-1' , text : 'FOSS' , termKey : 'foss' } ,
9494 ] ) ;
9595 } ) ;
9696
9797 it ( 'handles multiple terms in the same string' , ( ) => {
9898 expect ( splitByAbbreviations ( 'FOSS and RTFM' , map ) ) . toEqual ( [
99- { text : 'FOSS' , termKey : 'foss' } ,
100- { text : ' and ' } ,
101- { text : 'RTFM' , termKey : 'rtfm' } ,
99+ { id : 'txt-0' , text : 'FOSS' , termKey : 'foss' } ,
100+ { id : 'txt-1' , text : ' and ' } ,
101+ { id : 'txt-2' , text : 'RTFM' , termKey : 'rtfm' } ,
102102 ] ) ;
103103 } ) ;
104104
105105 it ( 'matches case-insensitively (termKey is always lowercase)' , ( ) => {
106106 expect ( splitByAbbreviations ( 'I like foss and Foss' , map ) ) . toEqual ( [
107- { text : 'I like ' } ,
108- { text : 'foss' , termKey : 'foss' } ,
109- { text : ' and ' } ,
110- { text : 'Foss' , termKey : 'foss' } ,
107+ { id : 'txt-0' , text : 'I like ' } ,
108+ { id : 'txt-1' , text : 'foss' , termKey : 'foss' } ,
109+ { id : 'txt-2' , text : ' and ' } ,
110+ { id : 'txt-3' , text : 'Foss' , termKey : 'foss' } ,
111111 ] ) ;
112112 } ) ;
113113
114114 it ( 'does not match a term that is a prefix of a longer word (word boundary)' , ( ) => {
115115 // OSS is in the map, but should not match inside FOSS because the F provides no boundary
116116 const ossOnlyMap = buildAbbreviationsMap ( [ { term : 'OSS' , definition : 'Open Source Software' } ] ) ;
117- expect ( splitByAbbreviations ( 'FOSS rocks' , ossOnlyMap ) ) . toEqual ( [ { text : 'FOSS rocks' } ] ) ;
117+ expect ( splitByAbbreviations ( 'FOSS rocks' , ossOnlyMap ) ) . toEqual ( [ { id : 'txt-0' , text : 'FOSS rocks' } ] ) ;
118118 } ) ;
119119
120120 it ( 'does not match a term embedded inside a longer word' , ( ) => {
121121 // OSS should not match inside CROSS or GLOSS
122122 const ossOnlyMap = buildAbbreviationsMap ( [ { term : 'OSS' , definition : 'Open Source Software' } ] ) ;
123123 expect ( splitByAbbreviations ( 'CROSS the GLOSS' , ossOnlyMap ) ) . toEqual ( [
124- { text : 'CROSS the GLOSS' } ,
124+ { id : 'txt-0' , text : 'CROSS the GLOSS' } ,
125125 ] ) ;
126126 } ) ;
127127
128128 it ( 'matches a shorter term standalone when the longer overlapping term is also defined' , ( ) => {
129129 // OSS is a suffix of FOSS; when standalone it should still match
130130 expect ( splitByAbbreviations ( 'OSS is related to FOSS' , map ) ) . toEqual ( [
131- { text : 'OSS' , termKey : 'oss' } ,
132- { text : ' is related to ' } ,
133- { text : 'FOSS' , termKey : 'foss' } ,
131+ { id : 'txt-0' , text : 'OSS' , termKey : 'oss' } ,
132+ { id : 'txt-1' , text : ' is related to ' } ,
133+ { id : 'txt-2' , text : 'FOSS' , termKey : 'foss' } ,
134134 ] ) ;
135135 } ) ;
136136
137137 it ( 'prefers the longer term when a shorter one is a suffix of it' , ( ) => {
138138 // FOSS contains OSS; FOSS should win and OSS should not be matched separately
139139 expect ( splitByAbbreviations ( 'Use FOSS today' , map ) ) . toEqual ( [
140- { text : 'Use ' } ,
141- { text : 'FOSS' , termKey : 'foss' } ,
142- { text : ' today' } ,
140+ { id : 'txt-0' , text : 'Use ' } ,
141+ { id : 'txt-1' , text : 'FOSS' , termKey : 'foss' } ,
142+ { id : 'txt-2' , text : ' today' } ,
143143 ] ) ;
144144 } ) ;
145145
146146 it ( 'preserves plain text between two consecutive matches' , ( ) => {
147147 expect ( splitByAbbreviations ( 'FOSS, RTFM, OSS' , map ) ) . toEqual ( [
148- { text : 'FOSS' , termKey : 'foss' } ,
149- { text : ', ' } ,
150- { text : 'RTFM' , termKey : 'rtfm' } ,
151- { text : ', ' } ,
152- { text : 'OSS' , termKey : 'oss' } ,
148+ { id : 'txt-0' , text : 'FOSS' , termKey : 'foss' } ,
149+ { id : 'txt-1' , text : ', ' } ,
150+ { id : 'txt-2' , text : 'RTFM' , termKey : 'rtfm' } ,
151+ { id : 'txt-3' , text : ', ' } ,
152+ { id : 'txt-4' , text : 'OSS' , termKey : 'oss' } ,
153153 ] ) ;
154154 } ) ;
155155} ) ;
0 commit comments