@@ -42,6 +42,67 @@ const runStrTests = (setup: () => Kit) => {
4242 }
4343 } ) ;
4444 } ) ;
45+
46+ describe ( '.attr()' , ( ) => {
47+ test ( 'returns all STACK annotations of a slice' , ( ) => {
48+ const { peritext} = setup ( ) ;
49+ const overlay = peritext . overlay ;
50+ peritext . editor . cursor . setAt ( 3 , 3 ) ;
51+ peritext . editor . saved . insStack ( 'bold' , 1 ) ;
52+ peritext . editor . saved . insStack ( 'bold' , 2 ) ;
53+ peritext . editor . saved . insStack ( 'em' , 1 ) ;
54+ overlay . refresh ( ) ;
55+ const [ start , end ] = [ ...overlay . points ( ) ] ;
56+ const inline = Inline . create ( peritext , start , end ) ;
57+ const attr = inline . attr ( ) ;
58+ expect ( attr . bold ) . toEqual ( [ 1 , 2 ] ) ;
59+ expect ( attr . em ) . toEqual ( [ 1 ] ) ;
60+ } ) ;
61+
62+ test ( 'returns latest OVERWRITE annotation' , ( ) => {
63+ const { peritext} = setup ( ) ;
64+ const overlay = peritext . overlay ;
65+ peritext . editor . cursor . setAt ( 3 , 3 ) ;
66+ peritext . editor . saved . insOverwrite ( 'bold' , 1 ) ;
67+ peritext . editor . saved . insOverwrite ( 'bold' , 2 ) ;
68+ peritext . editor . saved . insOverwrite ( 'em' , 1 ) ;
69+ overlay . refresh ( ) ;
70+ const [ start , end ] = [ ...overlay . points ( ) ] ;
71+ const inline = Inline . create ( peritext , start , end ) ;
72+ const attr = inline . attr ( ) ;
73+ expect ( attr . bold ) . toBe ( 2 ) ;
74+ expect ( attr . em ) . toBe ( 1 ) ;
75+ } ) ;
76+
77+ test ( 'hides annotation hidden with another ERASE annotation' , ( ) => {
78+ const { peritext} = setup ( ) ;
79+ const overlay = peritext . overlay ;
80+ peritext . editor . cursor . setAt ( 3 , 3 ) ;
81+ peritext . editor . saved . insOverwrite ( 'bold' ) ;
82+ peritext . editor . saved . insErase ( 'bold' ) ;
83+ peritext . editor . saved . insOverwrite ( 'em' ) ;
84+ overlay . refresh ( ) ;
85+ const [ start , end ] = [ ...overlay . points ( ) ] ;
86+ const inline = Inline . create ( peritext , start , end ) ;
87+ const attr = inline . attr ( ) ;
88+ expect ( attr . bold ) . toBe ( undefined ) ;
89+ expect ( attr . em ) . toBe ( 1 ) ;
90+ } ) ;
91+
92+ test ( 'concatenates with "," steps of nested Path type annotations' , ( ) => {
93+ const { peritext} = setup ( ) ;
94+ const overlay = peritext . overlay ;
95+ peritext . editor . cursor . setAt ( 3 , 3 ) ;
96+ peritext . editor . saved . insStack ( [ 'bold' , 'very' ] , 1 ) ;
97+ peritext . editor . saved . insStack ( [ 'bold' , 'normal' ] , 2 ) ;
98+ overlay . refresh ( ) ;
99+ const [ start , end ] = [ ...overlay . points ( ) ] ;
100+ const inline = Inline . create ( peritext , start , end ) ;
101+ const attr = inline . attr ( ) ;
102+ expect ( attr [ 'bold,very' ] ) . toEqual ( [ 1 ] ) ;
103+ expect ( attr [ 'bold,normal' ] ) . toEqual ( [ 2 ] ) ;
104+ } ) ;
105+ } ) ;
45106} ;
46107
47108describe ( 'Inline' , ( ) => {
0 commit comments