@@ -44,3 +44,47 @@ describe('Read tests', () => {
4444 } ) ;
4545 } ) ;
4646} ) ;
47+
48+ describe ( 'At tests' , ( ) => {
49+ it ( 'Test at with positive index within buffer\'s length' , ( ) => {
50+ const str = 'Hello world' ;
51+ const buffer = new DynamicBuffer ( str ) ;
52+
53+ for ( let i = 0 ; i < str . length ; i += 1 ) {
54+ assert . equal ( buffer . at ( i ) , str . charCodeAt ( i ) ) ;
55+ }
56+ } ) ;
57+
58+ it ( 'Test at with positive index greater than buffer\'s length' , ( ) => {
59+ const str = 'Hello world' ;
60+ const buffer = new DynamicBuffer ( str ) ;
61+
62+ assert . equal ( buffer . at ( str . length ) , undefined ) ;
63+ } ) ;
64+
65+ it ( 'Test at with a negative index' , ( ) => {
66+ const str = 'Hello world' ;
67+ const buffer = new DynamicBuffer ( str ) ;
68+
69+ for ( let i = 0 ; i < str . length ; i += 1 ) {
70+ assert . equal ( buffer . at ( 0 - str . length + i ) , str . charCodeAt ( i ) ) ;
71+ }
72+ } ) ;
73+
74+ it ( 'Test at with negative index more than buffer\'s length' , ( ) => {
75+ const str = 'Hello world' ;
76+ const buffer = new DynamicBuffer ( str ) ;
77+
78+ assert . equal ( buffer . at ( - str . length - 1 ) , undefined ) ;
79+ } ) ;
80+
81+ it ( 'Test at with specified buffer size and negative index' , ( ) => {
82+ const str = 'Hello world' ;
83+ const buffer = new DynamicBuffer ( str , { size : str . length } ) ;
84+
85+ for ( let i = 0 ; i < str . length ; i += 1 ) {
86+ assert . equal ( buffer . at ( 0 - str . length + i ) , str . charCodeAt ( i ) ) ;
87+ }
88+ assert . equal ( buffer . at ( - str . length - 1 ) , undefined ) ;
89+ } ) ;
90+ } ) ;
0 commit comments