From b4a79ebe6cbd5edf200b26a2f444000ff93e1808 Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Mon, 29 Jan 2024 07:18:57 +0100 Subject: [PATCH] start unit testing setup (#872) --- .github/workflows/unit.yml | 17 +++++++ .gitignore | 6 +++ .npmrc | 1 + abap_transpile.json | 60 ++++++++++++++++++++++++ package.json | 16 +++++++ test/cl_excel_test.clas.abap | 37 +++++++++++++++ test/cl_excel_test.clas.testclasses.abap | 10 ++++ test/mimetypes.tabl.xml | 34 ++++++++++++++ test/run.mjs | 9 ++++ 9 files changed, 190 insertions(+) create mode 100644 .github/workflows/unit.yml create mode 100644 .gitignore create mode 100644 .npmrc create mode 100644 abap_transpile.json create mode 100644 package.json create mode 100644 test/cl_excel_test.clas.abap create mode 100644 test/cl_excel_test.clas.testclasses.abap create mode 100644 test/mimetypes.tabl.xml create mode 100644 test/run.mjs diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml new file mode 100644 index 0000000..0cedc7a --- /dev/null +++ b/.github/workflows/unit.yml @@ -0,0 +1,17 @@ +name: unit + +on: + pull_request: + +permissions: + contents: read + +jobs: + unit: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + - run: npm install + - run: npm test \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc55a52 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +node_modules/ +package-lock.json +output +foo.zip +foo.xlsx +foo \ No newline at end of file diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..97b895e --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +ignore-scripts=true diff --git a/abap_transpile.json b/abap_transpile.json new file mode 100644 index 0000000..3bc587c --- /dev/null +++ b/abap_transpile.json @@ -0,0 +1,60 @@ +{ + "input_folder": "{src,test}", + "input_filter": [ + "src/zcl_excel_a", + "src/zcl_excel_c", + "src/zcl_excel_d", + "src/zcl_excel_fill_template", + "src/zcl_excel_font TODO, missing TDFONTSIZE", + "src/zcl_excel_g", + "src/zcl_excel_h", + "src/zcl_excel_l", + "src/zcl_excel_o", + "src/zcl_excel_r", + "src/zcl_excel_s", + "src/zcl_excel_t", + "src/zcl_excel_w", + "src/zcl_excel.clas", + "src/zcx_", + "src/zexcel_.*doma", + "src/zexcel_.*dtel", + "src/not_cloud/zexcel_.*dtel", + "src/not_cloud/zexcel_.*doma", + "src/zexcel_c", + "src/zexcel_p", + "src/zexcel_s", + "src/zexcel_t", + "src/zif_", + "test/" + ], + "output_folder": "output", + "lib": "https://github.com/open-abap/open-abap", + "write_unit_tests": true, + "write_source_map": true, + "options": { + "ignoreSyntaxCheck": false, + "addFilenames": true, + "addCommonJS": true, + "unknownTypes": "runtimeError", + "skip": [ + {"object": "ZCL_EXCEL_READER_HUGE_FILE", "class": "lcl_test", "method": "test_number", "note": "SXML in open-abap currently only handles json, todo"}, + {"object": "ZCL_EXCEL_READER_HUGE_FILE", "class": "lcl_test", "method": "test_shared_string", "note": "SXML in open-abap currently only handles json, todo"}, + {"object": "ZCL_EXCEL_READER_HUGE_FILE", "class": "lcl_test", "method": "test_shared_string_missing", "note": "??"}, + {"object": "ZCL_EXCEL_READER_HUGE_FILE", "class": "lcl_test", "method": "test_inline_string", "note": "??"}, + {"object": "ZCL_EXCEL_READER_HUGE_FILE", "class": "lcl_test", "method": "test_empty_cells", "note": "??"}, + {"object": "ZCL_EXCEL_READER_HUGE_FILE", "class": "lcl_test", "method": "test_boolean", "note": "SXML in open-abap currently only handles json, todo"}, + {"object": "ZCL_EXCEL_READER_HUGE_FILE", "class": "lcl_test", "method": "test_style", "note": "??"}, + {"object": "ZCL_EXCEL_READER_HUGE_FILE", "class": "lcl_test", "method": "test_style_missing", "note": "??"}, + {"object": "ZCL_EXCEL_READER_HUGE_FILE", "class": "lcl_test", "method": "test_formula", "note": "??"}, + {"object": "ZCL_EXCEL_READER_HUGE_FILE", "class": "lcl_test", "method": "test_read_shared_strings", "note": "??"}, + {"object": "ZCL_EXCEL_READER_HUGE_FILE", "class": "lcl_test", "method": "test_shared_string_some_empty", "note": "??"}, + {"object": "ZCL_EXCEL_READER_HUGE_FILE", "class": "lcl_test", "method": "test_shared_string_multi_style", "note": "??"}, + {"object": "ZCL_EXCEL_READER_HUGE_FILE", "class": "lcl_test", "method": "test_skip_to_inexistent", "note": "??"}, + + {"object": "ZCL_EXCEL_WRITER_2007", "class": "ltc_column_formula", "method": "one_column_formula", "note": "?? CALL TRANSFORMATION xml_header = 'no'"}, + {"object": "ZCL_EXCEL_WRITER_2007", "class": "ltc_column_formula", "method": "two_column_formulas", "note": "??"}, + + {"object": "ZCL_EXCEL_COMMON", "class": "lcl_excel_common_test", "method": "convert_column2int_oob_empty", "note": "?? sy value defaults"} + ] + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..f5817ab --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "license": "MIT", + "private": true, + "scripts": { + "test": "rm -rf output && abap_transpile abap_transpile.json && echo RUNNING && node output/index.mjs" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/abap2xlsx/abap2xlsx.git" + }, + "devDependencies": { + "@abaplint/cli": "^2.105.14", + "@abaplint/transpiler-cli": "^2.7.153", + "@abaplint/runtime": "^2.7.153" + } +} diff --git a/test/cl_excel_test.clas.abap b/test/cl_excel_test.clas.abap new file mode 100644 index 0000000..bdbe797 --- /dev/null +++ b/test/cl_excel_test.clas.abap @@ -0,0 +1,37 @@ +CLASS cl_excel_test DEFINITION PUBLIC. + PUBLIC SECTION. + CLASS-METHODS run + RETURNING VALUE(xdata) TYPE xstring + RAISING cx_static_check. +ENDCLASS. + +CLASS cl_excel_test IMPLEMENTATION. + METHOD run. + DATA lo_excel TYPE REF TO zcl_excel. + DATA lo_worksheet TYPE REF TO zcl_excel_worksheet. + DATA lo_hyperlink TYPE REF TO zcl_excel_hyperlink. + DATA lo_column TYPE REF TO zcl_excel_column. + DATA lv_date TYPE d. + DATA lv_time TYPE t. + DATA li_writer TYPE REF TO zif_excel_writer. + + CREATE OBJECT lo_excel. + lo_worksheet = lo_excel->get_active_worksheet( ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'Hello world' ). + lv_date = '20211231'. + lv_time = '055817'. + lo_worksheet->set_cell( ip_column = 'B' ip_row = 3 ip_value = lv_date ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 3 ip_value = lv_time ). + lo_hyperlink = zcl_excel_hyperlink=>create_external_link( iv_url = 'https://abap2xlsx.github.io/abap2xlsx' ). + lo_worksheet->set_cell( ip_columnrow = 'B4' ip_value = 'Click here to visit abap2xlsx homepage' ip_hyperlink = lo_hyperlink ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 6 ip_value = '你好,世界' ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 6 ip_value = '(Chinese)' ). + lo_worksheet->set_cell( ip_column = 'B' ip_row = 7 ip_value = 'नमस्ते दुनिया' ). + lo_worksheet->set_cell( ip_column = 'C' ip_row = 7 ip_value = '(Hindi)' ). + lo_column = lo_worksheet->get_column( ip_column = 'B' ). + lo_column->set_width( ip_width = 11 ). + + CREATE OBJECT li_writer TYPE zcl_excel_writer_2007. + xdata = li_writer->write_file( lo_excel ). + ENDMETHOD. +ENDCLASS. \ No newline at end of file diff --git a/test/cl_excel_test.clas.testclasses.abap b/test/cl_excel_test.clas.testclasses.abap new file mode 100644 index 0000000..7749a2e --- /dev/null +++ b/test/cl_excel_test.clas.testclasses.abap @@ -0,0 +1,10 @@ +CLASS ltcl DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. + PUBLIC SECTION. + METHODS test FOR TESTING RAISING cx_static_check. +ENDCLASS. + +CLASS ltcl IMPLEMENTATION. + METHOD test. + cl_excel_test=>run( ). + ENDMETHOD. +ENDCLASS. \ No newline at end of file diff --git a/test/mimetypes.tabl.xml b/test/mimetypes.tabl.xml new file mode 100644 index 0000000..fc048f5 --- /dev/null +++ b/test/mimetypes.tabl.xml @@ -0,0 +1,34 @@ + + + + + + MIMETYPES + E + INTTAB + MIMETYPES + 1 + + + + TYPE + 0 + C + 000256 + CHAR + 000128 + CHAR + + + EXTENSION + 0 + C + 000128 + CHAR + 000064 + CHAR + + + + + diff --git a/test/run.mjs b/test/run.mjs new file mode 100644 index 0000000..4a081f0 --- /dev/null +++ b/test/run.mjs @@ -0,0 +1,9 @@ +import {initializeABAP} from "../output/init.mjs"; +import {cl_excel_test} from "../output/cl_excel_test.clas.mjs"; +import * as fs from "node:fs"; + +await initializeABAP(); + +const test = new cl_excel_test(); +const buf = Buffer.from((await test.run()).get().toLowerCase(), "hex"); +fs.writeFileSync("foo.xlsx", buf); \ No newline at end of file