@@ -7,7 +7,7 @@ describe('IndexOf tests', () => {
77 it ( 'Test indexOf with empty buffer and empty value.' , ( ) => {
88 const buf = new DynamicBuffer ( ) ;
99
10- assert . equal ( buf . indexOf ( 'Hello ' ) , - 1 ) ;
10+ assert . equal ( buf . indexOf ( 'ABC ' ) , - 1 ) ;
1111 assert . equal ( buf . indexOf ( '' ) , 0 ) ;
1212 assert . equal ( buf . indexOf ( 0 ) , - 1 ) ;
1313 assert . equal ( buf . indexOf ( Buffer . alloc ( 0 ) ) , 0 ) ;
@@ -17,7 +17,7 @@ describe('IndexOf tests', () => {
1717
1818 it ( 'Test indexOf with empty value.' , ( ) => {
1919 const buf = new DynamicBuffer ( ) ;
20- buf . append ( 'Hello world ' ) ;
20+ buf . append ( 'ABCABCABC ' ) ;
2121
2222 assert . equal ( buf . indexOf ( '' ) , 0 ) ;
2323 assert . equal ( buf . indexOf ( 0 ) , - 1 ) ;
@@ -28,76 +28,76 @@ describe('IndexOf tests', () => {
2828
2929 it ( 'Test indexOf with string.' , ( ) => {
3030 const buf = new DynamicBuffer ( ) ;
31- buf . append ( 'Hello world ' ) ;
31+ buf . append ( 'ABCABCABC ' ) ;
3232
33- assert . equal ( buf . indexOf ( 'Hello ' ) , 0 ) ;
34- assert . equal ( buf . indexOf ( 'world ' ) , 6 ) ;
35- assert . equal ( buf . indexOf ( 'no ' ) , - 1 ) ;
33+ assert . equal ( buf . indexOf ( 'ABC ' ) , 0 ) ;
34+ assert . equal ( buf . indexOf ( 'BCA ' ) , 1 ) ;
35+ assert . equal ( buf . indexOf ( 'abc ' ) , - 1 ) ;
3636 } ) ;
3737
3838 it ( 'Test indexOf with number.' , ( ) => {
3939 const buf = new DynamicBuffer ( ) ;
40- buf . append ( 'Hello world ' ) ;
40+ buf . append ( 'ABCABCABC ' ) ;
4141
42- assert . equal ( buf . indexOf ( 72 ) , 0 ) ; // H
43- assert . equal ( buf . indexOf ( 119 ) , 6 ) ; // w
42+ assert . equal ( buf . indexOf ( 65 ) , 0 ) ; // A
43+ assert . equal ( buf . indexOf ( 67 ) , 2 ) ; // C
4444 assert . equal ( buf . indexOf ( 97 ) , - 1 ) ; // a
4545 } ) ;
4646
4747 it ( 'Test indexOf with Buffer.' , ( ) => {
4848 const buf = new DynamicBuffer ( ) ;
49- buf . append ( 'Hello world ' ) ;
49+ buf . append ( 'ABCABCABC ' ) ;
5050
51- assert . equal ( buf . indexOf ( Buffer . from ( 'Hello ' ) ) , 0 ) ;
52- assert . equal ( buf . indexOf ( Buffer . from ( 'world ' ) ) , 6 ) ;
53- assert . equal ( buf . indexOf ( Buffer . from ( 'no ' ) ) , - 1 ) ;
51+ assert . equal ( buf . indexOf ( Buffer . from ( 'ABC ' ) ) , 0 ) ;
52+ assert . equal ( buf . indexOf ( Buffer . from ( 'BCA ' ) ) , 1 ) ;
53+ assert . equal ( buf . indexOf ( Buffer . from ( 'abc ' ) ) , - 1 ) ;
5454 } ) ;
5555
5656 it ( 'Test indexOf with Uint8Array.' , ( ) => {
5757 const buf = new DynamicBuffer ( ) ;
58- buf . append ( 'Hello world ' ) ;
58+ buf . append ( 'ABCABCABC ' ) ;
5959
60- assert . equal ( buf . indexOf ( new Uint8Array ( [ 0x48 , 0x65 , 0x6c , 0x6c , 0x6f ] ) ) , 0 ) ;
61- assert . equal ( buf . indexOf ( new Uint8Array ( [ 0x77 , 0x6f , 0x72 , 0x6c , 0x64 ] ) ) , 6 ) ;
62- assert . equal ( buf . indexOf ( new Uint8Array ( [ 0x6e , 0x6c ] ) ) , - 1 ) ;
60+ assert . equal ( buf . indexOf ( new Uint8Array ( [ 0x41 , 0x42 , 0x43 ] ) ) , 0 ) ;
61+ assert . equal ( buf . indexOf ( new Uint8Array ( [ 0x42 , 0x43 , 0x41 ] ) ) , 1 ) ;
62+ assert . equal ( buf . indexOf ( new Uint8Array ( [ 0x61 , 0x62 , 0x63 ] ) ) , - 1 ) ;
6363 } ) ;
6464
6565 it ( 'Test indexOf with DynamicBuffer.' , ( ) => {
6666 const buf = new DynamicBuffer ( ) ;
67- buf . append ( 'Hello world ' ) ;
67+ buf . append ( 'ABCABCABC ' ) ;
6868
6969 const buf1 = new DynamicBuffer ( ) ;
70- buf1 . append ( 'Hello ' ) ;
70+ buf1 . append ( 'ABC ' ) ;
7171 assert . equal ( buf . indexOf ( buf1 ) , 0 ) ;
7272
7373 const buf2 = new DynamicBuffer ( ) ;
74- buf2 . append ( 'world ' ) ;
75- assert . equal ( buf . indexOf ( buf2 ) , 6 ) ;
74+ buf2 . append ( 'BCA ' ) ;
75+ assert . equal ( buf . indexOf ( buf2 ) , 1 ) ;
7676
7777 const buf3 = new DynamicBuffer ( ) ;
78- buf3 . append ( 'no ' ) ;
78+ buf3 . append ( 'abc ' ) ;
7979 assert . equal ( buf . indexOf ( buf3 ) , - 1 ) ;
8080 } ) ;
8181
8282 it ( 'Test indexOf with byteOffset parameter.' , ( ) => {
8383 const buf = new DynamicBuffer ( ) ;
84- buf . append ( 'Hello world ' ) ;
84+ buf . append ( 'ABCABCABC ' ) ;
8585
86- assert . equal ( buf . indexOf ( 'Hello ' ) , 0 ) ;
87- assert . equal ( buf . indexOf ( 'Hello ' , 0 ) , 0 ) ;
88- assert . equal ( buf . indexOf ( 'Hello ' , 1 ) , - 1 ) ;
89- assert . equal ( buf . indexOf ( 'Hello ' , - 1 ) , - 1 ) ;
90- assert . equal ( buf . indexOf ( 'Hello ' , - 11 ) , 0 ) ; // -11 equals 0
91- assert . equal ( buf . indexOf ( 'Hello ' , 32 ) , - 1 ) ;
92- assert . equal ( buf . indexOf ( '' , 32 ) , 0 ) ;
86+ assert . equal ( buf . indexOf ( 'ABC ' ) , 0 ) ;
87+ assert . equal ( buf . indexOf ( 'ABC ' , 0 ) , 0 ) ;
88+ assert . equal ( buf . indexOf ( 'ABC ' , 1 ) , 3 ) ;
89+ assert . equal ( buf . indexOf ( 'ABC ' , - 1 ) , - 1 ) ;
90+ assert . equal ( buf . indexOf ( 'ABC ' , - 9 ) , 0 ) ; // -11 equals 0
91+ assert . equal ( buf . indexOf ( 'ABC ' , 32 ) , - 1 ) ;
92+ assert . equal ( buf . indexOf ( '' , 32 ) , 9 ) ;
9393 } ) ;
9494} ) ;
9595
9696describe ( 'Includes tests' , ( ) => {
9797 it ( 'Test includes with empty buffer and empty value.' , ( ) => {
9898 const buf = new DynamicBuffer ( ) ;
9999
100- assert . equal ( buf . includes ( 'Hello ' ) , false ) ;
100+ assert . equal ( buf . includes ( 'ABC ' ) , false ) ;
101101 assert . equal ( buf . includes ( '' ) , true ) ;
102102 assert . equal ( buf . includes ( 0 ) , false ) ;
103103 assert . equal ( buf . includes ( Buffer . alloc ( 0 ) ) , true ) ;
@@ -107,7 +107,7 @@ describe('Includes tests', () => {
107107
108108 it ( 'Test includes with empty value.' , ( ) => {
109109 const buf = new DynamicBuffer ( ) ;
110- buf . append ( 'Hello world ' ) ;
110+ buf . append ( 'ABCABCABC ' ) ;
111111
112112 assert . equal ( buf . includes ( '' ) , true ) ;
113113 assert . equal ( buf . includes ( 0 ) , false ) ;
@@ -118,67 +118,67 @@ describe('Includes tests', () => {
118118
119119 it ( 'Test includes with string.' , ( ) => {
120120 const buf = new DynamicBuffer ( ) ;
121- buf . append ( 'Hello world ' ) ;
121+ buf . append ( 'ABCABCABC ' ) ;
122122
123- assert . equal ( buf . includes ( 'Hello ' ) , true ) ;
124- assert . equal ( buf . includes ( 'world ' ) , true ) ;
125- assert . equal ( buf . includes ( 'no ' ) , false ) ;
123+ assert . equal ( buf . includes ( 'ABC ' ) , true ) ;
124+ assert . equal ( buf . includes ( 'BCA ' ) , true ) ;
125+ assert . equal ( buf . includes ( 'abc ' ) , false ) ;
126126 } ) ;
127127
128128 it ( 'Test includes with number.' , ( ) => {
129129 const buf = new DynamicBuffer ( ) ;
130- buf . append ( 'Hello world ' ) ;
130+ buf . append ( 'ABCABCABC ' ) ;
131131
132- assert . equal ( buf . includes ( 72 ) , true ) ; // H
133- assert . equal ( buf . includes ( 119 ) , true ) ; // w
132+ assert . equal ( buf . includes ( 65 ) , true ) ; // A
133+ assert . equal ( buf . includes ( 67 ) , true ) ; // C
134134 assert . equal ( buf . includes ( 97 ) , false ) ; // a
135135 } ) ;
136136
137137 it ( 'Test includes with Buffer.' , ( ) => {
138138 const buf = new DynamicBuffer ( ) ;
139- buf . append ( 'Hello world ' ) ;
139+ buf . append ( 'ABCABCABC ' ) ;
140140
141- assert . equal ( buf . includes ( Buffer . from ( 'Hello ' ) ) , true ) ;
142- assert . equal ( buf . includes ( Buffer . from ( 'world ' ) ) , true ) ;
143- assert . equal ( buf . includes ( Buffer . from ( 'no ' ) ) , false ) ;
141+ assert . equal ( buf . includes ( Buffer . from ( 'ABC ' ) ) , true ) ;
142+ assert . equal ( buf . includes ( Buffer . from ( 'BCA ' ) ) , true ) ;
143+ assert . equal ( buf . includes ( Buffer . from ( 'abc ' ) ) , false ) ;
144144 } ) ;
145145
146146 it ( 'Test includes with Uint8Array.' , ( ) => {
147147 const buf = new DynamicBuffer ( ) ;
148- buf . append ( 'Hello world ' ) ;
148+ buf . append ( 'ABCABCABC ' ) ;
149149
150- assert . equal ( buf . includes ( new Uint8Array ( [ 0x48 , 0x65 , 0x6c , 0x6c , 0x6f ] ) ) , true ) ;
151- assert . equal ( buf . includes ( new Uint8Array ( [ 0x77 , 0x6f , 0x72 , 0x6c , 0x64 ] ) ) , true ) ;
152- assert . equal ( buf . includes ( new Uint8Array ( [ 0x6e , 0x6c ] ) ) , false ) ;
150+ assert . equal ( buf . includes ( new Uint8Array ( [ 0x41 , 0x42 , 0x43 ] ) ) , true ) ;
151+ assert . equal ( buf . includes ( new Uint8Array ( [ 0x42 , 0x43 , 0x41 ] ) ) , true ) ;
152+ assert . equal ( buf . includes ( new Uint8Array ( [ 0x61 , 0x62 , 0x63 ] ) ) , false ) ;
153153 } ) ;
154154
155155 it ( 'Test includes with DynamicBuffer.' , ( ) => {
156156 const buf = new DynamicBuffer ( ) ;
157- buf . append ( 'Hello world ' ) ;
157+ buf . append ( 'ABCABCABC ' ) ;
158158
159159 const buf1 = new DynamicBuffer ( ) ;
160- buf1 . append ( 'Hello ' ) ;
160+ buf1 . append ( 'ABC ' ) ;
161161 assert . equal ( buf . includes ( buf1 ) , true ) ;
162162
163163 const buf2 = new DynamicBuffer ( ) ;
164- buf2 . append ( 'world ' ) ;
164+ buf2 . append ( 'BCA ' ) ;
165165 assert . equal ( buf . includes ( buf2 ) , true ) ;
166166
167167 const buf3 = new DynamicBuffer ( ) ;
168- buf3 . append ( 'no ' ) ;
168+ buf3 . append ( 'abc ' ) ;
169169 assert . equal ( buf . includes ( buf3 ) , false ) ;
170170 } ) ;
171171
172172 it ( 'Test includes with byteOffset parameter.' , ( ) => {
173173 const buf = new DynamicBuffer ( ) ;
174- buf . append ( 'Hello world ' ) ;
174+ buf . append ( 'ABCABCABC ' ) ;
175175
176- assert . equal ( buf . includes ( 'Hello ' ) , true ) ;
177- assert . equal ( buf . includes ( 'Hello ' , 0 ) , true ) ;
178- assert . equal ( buf . includes ( 'Hello ' , 1 ) , false ) ;
179- assert . equal ( buf . includes ( 'Hello ' , - 1 ) , false ) ;
180- assert . equal ( buf . includes ( 'Hello ' , - 11 ) , true ) ; // -11 equals 0
181- assert . equal ( buf . includes ( 'Hello ' , 32 ) , false ) ;
176+ assert . equal ( buf . includes ( 'ABC ' ) , true ) ;
177+ assert . equal ( buf . includes ( 'ABC ' , 0 ) , true ) ;
178+ assert . equal ( buf . includes ( 'ABC ' , 1 ) , true ) ;
179+ assert . equal ( buf . includes ( 'ABC ' , - 1 ) , false ) ;
180+ assert . equal ( buf . includes ( 'ABC ' , - 9 ) , true ) ; // -11 equals 0
181+ assert . equal ( buf . includes ( 'ABC ' , 32 ) , false ) ;
182182 assert . equal ( buf . includes ( '' , 32 ) , true ) ;
183183 } ) ;
184184} ) ;
0 commit comments