From 0adb2c6439a33b9128c2f49fbb3b187caba50936 Mon Sep 17 00:00:00 2001 From: kio-watanabe Date: Mon, 11 Nov 2024 02:20:49 +0000 Subject: [PATCH 1/2] [WIP] Fix getSign() --- .../opensourcecobol/libcobj/data/CobolNumericField.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java index 8cefebec..fff889d1 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java @@ -479,7 +479,8 @@ public int getSign() { return 1; } if (value == 0x20) { - this.getDataStorage().setByte(p, (byte) 0x30); + // System.out.println("dbg: getSign() setByte"); + // this.getDataStorage().setByte(p, (byte) 0x30); return 1; } From c19677c8682cfab4db1e75d824729872449f2a09 Mon Sep 17 00:00:00 2001 From: kio-watanabe Date: Tue, 12 Nov 2024 08:50:17 +0000 Subject: [PATCH 2/2] Fix getSign() and add a test case --- .../libcobj/data/CobolNumericField.java | 7 +--- tests/Makefile.am | 3 +- tests/Makefile.in | 3 +- tests/misc.at | 1 + .../misc.src/display-numeric-NUMERIC-class.at | 32 +++++++++++++++++++ 5 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 tests/misc.src/display-numeric-NUMERIC-class.at diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java index fff889d1..b05705b0 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java @@ -475,12 +475,7 @@ public int getSign() { if (attr.isFlagSignSeparate()) { return value == 0x2b ? 1 : -1; } else { - if (0x30 <= value && value <= 0x39) { - return 1; - } - if (value == 0x20) { - // System.out.println("dbg: getSign() setByte"); - // this.getDataStorage().setByte(p, (byte) 0x30); + if (value == 0x20 || (0x30 <= value && value <= 0x39)) { return 1; } diff --git a/tests/Makefile.am b/tests/Makefile.am index 484aee23..32c2049f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -223,7 +223,8 @@ misc_DEPENDENCIES = \ misc.src/file-handler-japanese.at \ misc.src/perform-until-div.at \ misc.src/search-occurs-depending.at \ - misc.src/fix-subtract.at + misc.src/fix-subtract.at \ + misc.src/display-numeric-NUMERIC-class.at EXTRA_DIST = $(srcdir)/package.m4 \ $(TESTS) \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 3ed18bdd..9c1bfa5c 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -762,7 +762,8 @@ misc_DEPENDENCIES = \ misc.src/file-handler-japanese.at \ misc.src/perform-until-div.at \ misc.src/search-occurs-depending.at \ - misc.src/fix-subtract.at + misc.src/fix-subtract.at \ + misc.src/display-numeric-NUMERIC-class.at EXTRA_DIST = $(srcdir)/package.m4 \ $(TESTS) \ diff --git a/tests/misc.at b/tests/misc.at index 93fa8085..1ac799e7 100644 --- a/tests/misc.at +++ b/tests/misc.at @@ -53,3 +53,4 @@ m4_include([file-handler-japanese.at]) m4_include([perform-until-div.at]) m4_include([search-occurs-depending.at]) m4_include([fix-subtract.at]) +m4_include([display-numeric-NUMERIC-class.at]) diff --git a/tests/misc.src/display-numeric-NUMERIC-class.at b/tests/misc.src/display-numeric-NUMERIC-class.at new file mode 100644 index 00000000..b3273abf --- /dev/null +++ b/tests/misc.src/display-numeric-NUMERIC-class.at @@ -0,0 +1,32 @@ +AT_SETUP([DISPLAY numeric after NUMERIC class testing]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 N-REC. + 03 N-VAL PIC 9. + PROCEDURE DIVISION. + MAIN-PROC. + ************************************************************* + MOVE SPACE TO N-REC. + DISPLAY "N-VAL: '" N-VAL "'". + + IF N-VAL NUMERIC + DISPLAY "N-VAL is numeric" + ELSE + DISPLAY "N-VAL is not numeric" + END-IF. + + DISPLAY "N-VAL: '" N-VAL "'". +]) + +AT_CHECK([${COBJ} prog.cbl]) +AT_CHECK([java prog], [0], +[N-VAL: ' ' +N-VAL is not numeric +N-VAL: ' ' +]) + +AT_CLEANUP \ No newline at end of file