@@ -122,6 +122,75 @@ describe('Test size operations.', () => {
122122 expect ( microbitFs . getStorageUsed ( ) ) . toEqual ( 27648 ) ;
123123 expect ( microbitFs . getStorageRemaining ( ) ) . toEqual ( 0 ) ;
124124 } ) ;
125+
126+ it ( 'Sets a maximum filesystem size via constructor' , ( ) => {
127+ const microbitFs = new MicropythonFsHex ( uPyHexFile , { maxFsSize : 1024 } ) ;
128+
129+ expect ( microbitFs . getStorageUsed ( ) ) . toEqual ( 0 ) ;
130+ expect ( microbitFs . getStorageRemaining ( ) ) . toEqual ( 1024 ) ;
131+
132+ microbitFs . create ( 'chunk1.py' , 'first 128 byte chunk' ) ;
133+ microbitFs . create ( 'chunk2.py' , 'second 128 byte chunk' ) ;
134+ microbitFs . create ( 'chunk3.py' , 'thrid 128 byte chunk' ) ;
135+ microbitFs . create ( 'chunk4.py' , 'fouth 128 byte chunk' ) ;
136+ microbitFs . create ( 'chunk5.py' , 'fifth 128 byte chunk' ) ;
137+ microbitFs . create ( 'chunk6.py' , 'sixth 128 byte chunk' ) ;
138+ microbitFs . create ( 'chunk7.py' , 'seventh 128 byte chunk' ) ;
139+ microbitFs . create ( 'chunk8.py' , 'eighth 128 byte chunk' ) ;
140+ microbitFs . getIntelHex ( ) ;
141+
142+ expect ( microbitFs . getStorageUsed ( ) ) . toEqual ( 1024 ) ;
143+ expect ( microbitFs . getStorageRemaining ( ) ) . toEqual ( 0 ) ;
144+
145+ microbitFs . create ( 'chunk9.py' , 'This file will not fit' ) ;
146+ const failCase = ( ) => {
147+ microbitFs . getIntelHex ( ) ;
148+ } ;
149+
150+ expect ( failCase ) . toThrow ( Error ) ;
151+ } ) ;
152+
153+ it ( 'Sets a maximum filesystem size via constructor' , ( ) => {
154+ const microbitFs = new MicropythonFsHex ( uPyHexFile ) ;
155+ microbitFs . setStorageSize ( 1024 ) ;
156+
157+ expect ( microbitFs . getStorageUsed ( ) ) . toEqual ( 0 ) ;
158+ expect ( microbitFs . getStorageRemaining ( ) ) . toEqual ( 1024 ) ;
159+
160+ microbitFs . create ( 'chunk1.py' , 'first 128 byte chunk' ) ;
161+ microbitFs . create ( 'chunk2.py' , 'second 128 byte chunk' ) ;
162+ microbitFs . create ( 'chunk3.py' , 'thrid 128 byte chunk' ) ;
163+ microbitFs . create ( 'chunk4.py' , 'fouth 128 byte chunk' ) ;
164+ microbitFs . create ( 'chunk5.py' , 'fifth 128 byte chunk' ) ;
165+ microbitFs . create ( 'chunk6.py' , 'sixth 128 byte chunk' ) ;
166+ microbitFs . create ( 'chunk7.py' , 'seventh 128 byte chunk' ) ;
167+ microbitFs . create ( 'chunk8.py' , 'eighth 128 byte chunk' ) ;
168+ microbitFs . getIntelHex ( ) ;
169+ microbitFs . getIntelHexBytes ( ) ;
170+
171+ expect ( microbitFs . getStorageUsed ( ) ) . toEqual ( 1024 ) ;
172+ expect ( microbitFs . getStorageRemaining ( ) ) . toEqual ( 0 ) ;
173+
174+ microbitFs . create ( 'chunk9.py' , 'This file will not fit' ) ;
175+ const failCase1 = ( ) => microbitFs . getIntelHex ( ) ;
176+ const failCase2 = ( ) => microbitFs . getIntelHexBytes ( ) ;
177+
178+ expect ( failCase1 ) . toThrow ( Error ) ;
179+ expect ( failCase2 ) . toThrow ( Error ) ;
180+ } ) ;
181+
182+ it ( 'The maximum filesystem size cannot be larger than space available' , ( ) => {
183+ const failCase1 = ( ) => {
184+ const microbitFs = new MicropythonFsHex ( uPyHexFile , {
185+ maxFsSize : 1024 * 1024 ,
186+ } ) ;
187+ } ;
188+ const microbitFs = new MicropythonFsHex ( uPyHexFile ) ;
189+ const failCase2 = ( ) => microbitFs . setStorageSize ( 1024 * 1024 ) ;
190+
191+ expect ( failCase1 ) . toThrow ( Error ) ;
192+ expect ( failCase2 ) . toThrow ( Error ) ;
193+ } ) ;
125194} ) ;
126195
127196describe ( 'Test write method.' , ( ) => {
0 commit comments