@@ -225,6 +225,58 @@ class VRLRecordReaderSpec extends AnyWordSpec {
225225
226226 assert(ex.getMessage == " The record length field LEN must be an integral type or a value mapping must be specified." )
227227 }
228+
229+ " the length mapping with default record length" in {
230+ val copybookWithLenbgthMap =
231+ """ 01 RECORD.
232+ 05 LEN_SPEC PIC X(1).
233+ 05 N PIC 9(2).
234+ 05 A PIC X(3).
235+ """
236+
237+ val records = Array (
238+ 0xC1 , 0xF1 , 0xF2 , 0xC1 ,
239+ 0xC2 , 0xF3 , 0xF4 , 0xC2 , 0xC3 ,
240+ 0xC3 , 0xF5 , 0xF6 , 0xC4 , 0xC5 , 0xC6
241+ ).map(_.toByte)
242+
243+ val streamH = new ByteStreamMock (records)
244+ val streamD = new ByteStreamMock (records)
245+ val context = RawRecordContext (0 , streamH, streamD, CopybookParser .parseSimple(copybookWithLenbgthMap), null , null , " " )
246+
247+ val readerParameters = ReaderParameters (
248+ lengthFieldExpression = Some (" LEN_SPEC" ),
249+ lengthFieldMap = Map (" A" -> 4 , " B" -> 5 , " _" -> 6 ))
250+
251+ val reader = getUseCase(
252+ copybook = copybookWithLenbgthMap,
253+ records = records,
254+ lengthFieldExpression = Some (" LEN_SPEC" ),
255+ recordExtractor = Some (new FixedWithRecordLengthExprRawRecordExtractor (context, readerParameters)))
256+
257+ assert(reader.hasNext)
258+ val (segment1, record1) = reader.next()
259+ assert(reader.hasNext)
260+ val (segment2, record2) = reader.next()
261+ assert(reader.hasNext)
262+ val (segment3, record3) = reader.next()
263+ assert(! reader.hasNext)
264+
265+ assert(segment1.isEmpty)
266+ assert(segment2.isEmpty)
267+ assert(segment3.isEmpty)
268+ assert(record1.length == 4 )
269+ assert(record2.length == 5 )
270+ assert(record3.length == 6 )
271+ assert(record1(0 ) == 0xC1 .toByte)
272+ assert(record1(1 ) == 0xF1 .toByte)
273+ assert(record1(2 ) == 0xF2 .toByte)
274+ assert(record1(3 ) == 0xC1 .toByte)
275+ assert(record2(0 ) == 0xC2 .toByte)
276+ assert(record2(1 ) == 0xF3 .toByte)
277+ assert(record3(0 ) == 0xC3 .toByte)
278+ assert(record3(1 ) == 0xF5 .toByte)
279+ }
228280 }
229281
230282 " work with record length expressions" in {
0 commit comments