88 lines
2.4 KiB
Python
88 lines
2.4 KiB
Python
# tests/test_copy_parser.py
|
|
import os
|
|
import tempfile
|
|
from agent.input_parser import InputParser
|
|
|
|
FIXTURE_DIR = os.path.join(os.path.dirname(__file__), 'test_data')
|
|
|
|
|
|
def test_parse_single_copybook():
|
|
parser = InputParser(
|
|
design_md_path='dummy.md', source_cbl_path='dummy.cbl',
|
|
file_db_md_path='dummy.md', cpy_dir=FIXTURE_DIR,
|
|
db_md_path='dummy_db.md'
|
|
)
|
|
fields = parser._parse_single_copybook(
|
|
os.path.join(FIXTURE_DIR, 'ZAN01REC.cpy'),
|
|
prefix='R01'
|
|
)
|
|
|
|
assert len(fields) == 8
|
|
|
|
f0 = fields[0]
|
|
assert f0.name == 'R01-APPL-ID'
|
|
assert f0.raw_name == '(A)APPL-ID'
|
|
assert 'X' in f0.pic_type
|
|
assert f0.pic_bytes == 8
|
|
|
|
f1 = fields[1]
|
|
assert f1.name == 'R01-EMP-ID'
|
|
assert '9' in f1.pic_type
|
|
assert f1.pic_bytes == 8
|
|
|
|
f3 = fields[3]
|
|
assert f3.name == 'R01-START-TIME'
|
|
assert f3.pic_bytes == 4
|
|
|
|
f7 = fields[7]
|
|
assert 'FILLER' in f7.name
|
|
assert f7.pic_bytes == 46
|
|
|
|
|
|
def test_extract_copy_replacing():
|
|
source_text = """
|
|
FD R01INNFIL.
|
|
01 R01INNREC.
|
|
COPY ZAN01REC REPLACING ==(A)== BY ==R01==.
|
|
FD R02INNFIL.
|
|
01 R02INNREC.
|
|
COPY ZAN04REC REPLACING ==(A)== BY ==R02==.
|
|
"""
|
|
|
|
parser = InputParser(
|
|
design_md_path='dummy.md', source_cbl_path='dummy.cbl',
|
|
file_db_md_path='dummy.md', cpy_dir=FIXTURE_DIR,
|
|
db_md_path='dummy_db.md'
|
|
)
|
|
parser._source_text = source_text
|
|
|
|
result = parser._extract_copy_replacing()
|
|
assert len(result) == 2
|
|
assert result[0] == ('ZAN01REC', 'R01')
|
|
assert result[1] == ('ZAN04REC', 'R02')
|
|
|
|
|
|
def test_calculate_pic_bytes_x():
|
|
assert InputParser._calculate_pic_bytes('X(008)') == 8
|
|
assert InputParser._calculate_pic_bytes('X(10)') == 10
|
|
|
|
|
|
def test_calculate_pic_bytes_9():
|
|
assert InputParser._calculate_pic_bytes('9(008)') == 8
|
|
assert InputParser._calculate_pic_bytes('9(004)') == 4
|
|
|
|
|
|
def test_calculate_pic_bytes_comp3():
|
|
assert InputParser._calculate_pic_bytes('S9(009) COMP-3') == 5
|
|
assert InputParser._calculate_pic_bytes('S9(7) COMP-3') == 4
|
|
assert InputParser._calculate_pic_bytes('9(7) COMP-3') == 4
|
|
|
|
|
|
def test_calculate_pic_bytes_comp():
|
|
assert InputParser._calculate_pic_bytes('S9(4) COMP') == 2
|
|
assert InputParser._calculate_pic_bytes('S9(9) COMP') == 4
|
|
|
|
|
|
def test_calculate_pic_bytes_decimal():
|
|
assert InputParser._calculate_pic_bytes('S9(7)V9(2)') == 9
|