|
| 1 | +package net.sf.cb2xml.zTests.numeric; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.*; |
| 4 | + |
| 5 | +import java.io.StringReader; |
| 6 | +import java.util.List; |
| 7 | + |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | + |
| 10 | +import net.sf.cb2xml.Cb2Xml3; |
| 11 | +import net.sf.cb2xml.def.IItem; |
| 12 | + |
| 13 | +/** |
| 14 | + * This class ensures trailing commas in a picture clause are ignored |
| 15 | + * ie the comma in the following picture should be treated as white space |
| 16 | + * 05 CALC-SALES PIC 9(6)V99, VALUE 0 |
| 17 | + */ |
| 18 | +class TestComma { |
| 19 | + |
| 20 | + private static String commaCobolxx = "" |
| 21 | + + " 01 CALC-COMMISSION-FIELDS.\n" |
| 22 | + + " 05 EMP-TYPE PIC X.\n" |
| 23 | + + " 05 CALC-SALES PIC 9(6)V99, VALUE 0.\n" |
| 24 | + + " 05 CALC-COMMISSION PIC 9(5)V99 COMP-3 VALUE 0."; |
| 25 | + private static String commaCobol1 = "" |
| 26 | + + " 01 CALC-COMMISSION-FIELDS.\n" |
| 27 | + + " 05 CALC-SALES PIC 9(6)V99, VALUE 0.\n"; |
| 28 | + @Test |
| 29 | + void test1() { |
| 30 | + List<? extends IItem> itemTree |
| 31 | + = Cb2Xml3.newBuilder(new StringReader(commaCobol1), "Commission") |
| 32 | + .asCobolItemTree().getChildItems(); |
| 33 | + |
| 34 | +// System.out.println(itemTree.size() + " " + itemTree.get(0).getDisplayLength() + " " + itemTree.get(0).getStorageLength()); |
| 35 | + assertEquals(1, itemTree.size()); |
| 36 | + IItem item = itemTree.get(0); |
| 37 | + assertEquals(8, item.getDisplayLength()); |
| 38 | + assertEquals(8, item.getStorageLength()); |
| 39 | + |
| 40 | + assertEquals(1, itemTree.get(0).getChildItems().size()); |
| 41 | + item = itemTree.get(0).getChildItems().get(0); |
| 42 | + assertEquals("CALC-SALES", item.getFieldName()); |
| 43 | + assertEquals(8, item.getDisplayLength()); |
| 44 | + assertEquals(8, item.getStorageLength()); |
| 45 | + |
| 46 | + } |
| 47 | + @Test |
| 48 | + void testXX() { |
| 49 | + List<? extends IItem> itemTree |
| 50 | + = Cb2Xml3.newBuilder(new StringReader(commaCobolxx), "Commission") |
| 51 | + .asCobolItemTree().getChildItems(); |
| 52 | + |
| 53 | +// System.out.println(itemTree.size() + " " + itemTree.get(0).getDisplayLength() + " " + itemTree.get(0).getStorageLength()); |
| 54 | + assertEquals(1, itemTree.size()); |
| 55 | + |
| 56 | + IItem item = itemTree.get(0); |
| 57 | + assertEquals(16, item.getDisplayLength()); |
| 58 | + assertEquals(13, item.getStorageLength()); |
| 59 | + |
| 60 | + assertEquals(3, itemTree.get(0).getChildItems().size()); |
| 61 | + item = itemTree.get(0).getChildItems().get(1); |
| 62 | + assertEquals("CALC-SALES", item.getFieldName()); |
| 63 | + assertEquals(8, item.getDisplayLength()); |
| 64 | + assertEquals(8, item.getStorageLength()); |
| 65 | + |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments