diff --git a/crates/compiler/src/tests/control.rs b/crates/compiler/src/tests/control.rs new file mode 100644 index 0000000..ac7f9a2 --- /dev/null +++ b/crates/compiler/src/tests/control.rs @@ -0,0 +1,88 @@ +use super::common::CommonTestRunner; + +/// Tests performing a single paragraph. +#[test] +fn perform_single() { + CommonTestRunner::new("perform_single") + .source(r#" +IDENTIFICATION DIVISION. +PROGRAM-ID. PERFORM-SINGLE-TEST. + +PROCEDURE DIVISION. + PERFORM TEST-PARA. + STOP RUN. + + TEST-PARA. + DISPLAY "Hello". + "#) + .expect_output("Hello\n") + .run(); +} + +/// Tests performing a set of paragraphs. +#[test] +fn perform_thru() { + CommonTestRunner::new("perform_thru") + .source(r#" +IDENTIFICATION DIVISION. +PROGRAM-ID. PERFORM-THRU-TEST. + +PROCEDURE DIVISION. + PERFORM A-PARA THRU C-PARA. + STOP RUN. + + A-PARA. + DISPLAY "Hello". + + B-PARA. + DISPLAY "COBOL". + + C-PARA. + DISPLAY "World". + "#) + .expect_output("HelloCOBOLWorld\n\n\n") + .run(); +} + +/// Tests performing until a condition is met. +#[test] +fn perform_until() { + CommonTestRunner::new("perform_until") + .source(r#" +IDENTIFICATION DIVISION. +PROGRAM-ID. PERFORM-UNTIL-TEST. + +DATA DIVISION. + WORKING-STORAGE SECTION. + 01 LIMIT-VAL PIC 9(6) COMP VALUE 0. + +PROCEDURE DIVISION. + PERFORM TEST-PARA UNTIL LIMIT-VAL >= 3. + STOP RUN. + + TEST-PARA. + DISPLAY "Hello". + ADD 1 TO LIMIT-VAL. + "#) + .expect_output("HelloHelloHello\n\n\n") + .run(); +} + +/// Tests performing a paragraph N times. +#[test] +fn perform_times() { + CommonTestRunner::new("perform_times") + .source(r#" +IDENTIFICATION DIVISION. +PROGRAM-ID. PERFORM-TIMES-TEST. + +PROCEDURE DIVISION. + PERFORM TEST-PARA 3 TIMES. + STOP RUN. + + TEST-PARA. + DISPLAY "Hello". + "#) + .expect_output("HelloHelloHello\n\n\n") + .run(); +} \ No newline at end of file diff --git a/crates/compiler/src/tests/intrinsics.rs b/crates/compiler/src/tests/intrinsics.rs index acdb863..a37a48b 100644 --- a/crates/compiler/src/tests/intrinsics.rs +++ b/crates/compiler/src/tests/intrinsics.rs @@ -1,114 +1,112 @@ use super::common::CommonTestRunner; -/// Tests that the "MOD" intrinsic functions correctly on an exact -/// divisor. +/// Tests that the MOD intrinsic for an exact divisor functions. #[test] fn mod_exact() { CommonTestRunner::new("mod_exact") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. MOD-EXACT. +PROGRAM-ID. MOD-EXACT-TEST. DATA DIVISION. WORKING-STORAGE SECTION. - 01 OUT-VAL PIC 9(4) COMP. + 01 INT-VAL PIC 9(4) COMP. PROCEDURE DIVISION. - MOVE FUNCTION MOD(4, 2) TO OUT-VAL. - DISPLAY OUT-VAL. + MOVE FUNCTION MOD(20, 2) TO INT-VAL. + DISPLAY INT-VAL. STOP RUN. "#) .expect_output("0\n") .run(); } -/// Tests that the "MOD" intrinsic functions correctly on an exact -/// divisor. +/// Tests that the MOD intrinsic for an non-exact divisor functions. #[test] -fn mod_non_divisor() { - CommonTestRunner::new("mod_non_divisor") +fn mod_non_exact() { + CommonTestRunner::new("mod_non_exact") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. MOD-NON-DIV. +PROGRAM-ID. MOD-NON-EXACT-TEST. DATA DIVISION. WORKING-STORAGE SECTION. - 01 OUT-VAL PIC 9(4) COMP. + 01 INT-VAL PIC 9(4) COMP. PROCEDURE DIVISION. - MOVE FUNCTION MOD(5, 3) TO OUT-VAL. - DISPLAY OUT-VAL. + MOVE FUNCTION MOD(16, 3) TO INT-VAL. + DISPLAY INT-VAL. STOP RUN. "#) - .expect_output("2\n") + .expect_output("1\n") .run(); } -/// Tests that the "LENGTH" intrinsic functions correctly on a zero -/// length string. +/// Tests that the LENGTH intrinsic works for a zero-length string. #[test] -fn str_length_zero() { - CommonTestRunner::new("str_length_zero") +fn length_zero() { + CommonTestRunner::new("length_zero") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. STR-LEN-ZERO. +PROGRAM-ID. LENGTH-ZERO-TEST. DATA DIVISION. WORKING-STORAGE SECTION. - 01 OUT-VAL PIC 9(4) COMP. + 01 STR-VAL PIC X(10) VALUE "". + 01 INT-VAL PIC 9(10) COMP. PROCEDURE DIVISION. - MOVE FUNCTION LENGTH("") TO OUT-VAL. - DISPLAY OUT-VAL. + MOVE FUNCTION LENGTH(STR-VAL) TO INT-VAL. + DISPLAY INT-VAL. STOP RUN. "#) .expect_output("0\n") .run(); } -/// Tests that the "LENGTH" intrinsic functions correctly on a -/// non-zero length string. +/// Tests that the LENGTH intrinsic works for a non-zero length string. #[test] -fn str_length_non_zero() { - CommonTestRunner::new("str_length_non_zero") +fn length_non_zero() { + CommonTestRunner::new("length_non_zero") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. STR-LEN-NON-ZERO. +PROGRAM-ID. LENGTH-NON-ZERO-TEST. DATA DIVISION. WORKING-STORAGE SECTION. - 01 OUT-VAL PIC 9(4) COMP. + 01 STR-VAL PIC X(10) VALUE "SomeStr". + 01 INT-VAL PIC 9(10) COMP. PROCEDURE DIVISION. - MOVE FUNCTION LENGTH("SomeLitVal") TO OUT-VAL. - DISPLAY OUT-VAL. + MOVE FUNCTION LENGTH(STR-VAL) TO INT-VAL. + DISPLAY INT-VAL. STOP RUN. "#) - .expect_output("10\n") + .expect_output("7\n") .run(); } -/// Tests that the "RANDOM" intrinsic generates different -/// values on subsequent executions. + +/// Tests that the RANDOM intrinsic differs on subsequent calls. #[test] fn random_differs() { CommonTestRunner::new("random_differs") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. RANDOM-DIFFERS. +PROGRAM-ID. RANDOM-DIFFERS-TEST. DATA DIVISION. WORKING-STORAGE SECTION. - 01 A-VAL PIC S9(4)P9(4) COMP. - 01 B-VAL PIC S9(4)P9(4) COMP. + 01 A-VAL PIC 9(4)P9(4) COMP. + 01 B-VAL PIC 9(4)P9(4) COMP. PROCEDURE DIVISION. MOVE FUNCTION RANDOM() TO A-VAL. MOVE FUNCTION RANDOM() TO B-VAL. - IF A-VAL = B-VAL THEN - DISPLAY "fail" - ELSE + IF NOT A-VAL = B-VAL THEN DISPLAY "pass" + ELSE + DISPLAY "fail" END-IF. STOP RUN. "#) @@ -116,46 +114,46 @@ STOP RUN. .run(); } -/// Tests that the "INTEGER" intrinsic correctly rounds up a given -/// floating point value. +/// Tests that the INTEGER intrinsic works for a non-integer equivalent value. #[test] -fn integer_rounds_up() { - CommonTestRunner::new("integer_rounds_up") +fn integer_converts_float() { + CommonTestRunner::new("integer_converts_float") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. INT-ROUNDS-UP. +PROGRAM-ID. INT-CONV-FLOAT-TEST. DATA DIVISION. WORKING-STORAGE SECTION. - 01 OUT-VAL PIC 9(4) COMP. + 01 FLT-VAL PIC 9(4)P9(4) COMP VALUE 20.43. + 01 INT-VAL PIC 9(10) COMP. PROCEDURE DIVISION. - MOVE FUNCTION INTEGER(2.398282) TO OUT-VAL. - DISPLAY OUT-VAL. + MOVE FUNCTION INTEGER(FLT-VAL) TO INT-VAL. + DISPLAY INT-VAL. STOP RUN. "#) - .expect_output("3\n") + .expect_output("21\n") .run(); } -/// Tests that the "INTEGER" intrinsic correctly converts an exact -/// floating point value to the equivalent integer. +/// Tests that the INTEGER intrinsic works for an integer equivalent value. #[test] -fn integer_translates_exact() { - CommonTestRunner::new("integer_translates_exact") +fn integer_converts_int() { + CommonTestRunner::new("integer_converts_int") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. INT-TRANS-EXACT. +PROGRAM-ID. INT-CONV-INT-TEST. DATA DIVISION. WORKING-STORAGE SECTION. - 01 OUT-VAL PIC 9(4) COMP. + 01 FLT-VAL PIC 9(4)P9(4) COMP VALUE 220.0. + 01 INT-VAL PIC 9(10) COMP. PROCEDURE DIVISION. - MOVE FUNCTION INTEGER(214.0) TO OUT-VAL. - DISPLAY OUT-VAL. + MOVE FUNCTION INTEGER(FLT-VAL) TO INT-VAL. + DISPLAY INT-VAL. STOP RUN. "#) - .expect_output("214\n") + .expect_output("220\n") .run(); } \ No newline at end of file diff --git a/crates/compiler/src/tests/io.rs b/crates/compiler/src/tests/io.rs index 2088cc5..c50ab60 100644 --- a/crates/compiler/src/tests/io.rs +++ b/crates/compiler/src/tests/io.rs @@ -22,7 +22,7 @@ fn int_display_test() { CommonTestRunner::new("display_int") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. DISPLAY-DATA-TEST. +PROGRAM-ID. DISPLAY-INT-DATA-TEST. DATA DIVISION. WORKING-STORAGE SECTION. @@ -42,7 +42,7 @@ fn float_display_test() { CommonTestRunner::new("display_float") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. DISPLAY-DATA-TEST. +PROGRAM-ID. DISPLAY-FLT-DATA-TEST. DATA DIVISION. WORKING-STORAGE SECTION. @@ -63,7 +63,7 @@ fn interleaved_display_test() { CommonTestRunner::new("display_interleaved") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. DISPLAY-DATA-TEST. +PROGRAM-ID. DISPLAY-INTER-DATA-TEST. DATA DIVISION. WORKING-STORAGE SECTION. @@ -108,14 +108,18 @@ PROGRAM-ID. ACCEPT-INT-TEST. DATA DIVISION. WORKING-STORAGE SECTION. +<<<<<<< HEAD 01 INT-VAL PIC 9(4) COMP. +======= + 01 INT-VAL PIC 9(8) COMP. +>>>>>>> db58ecf (ci(feat): Add additional tests for arithmetic, control.) PROCEDURE DIVISION. ACCEPT INT-VAL. DISPLAY INT-VAL. STOP RUN. "#) - .expect_output_with_input("2024\n", "2024\n") + .expect_output_with_input("9004\n", "9004\n") .run(); } @@ -129,13 +133,13 @@ PROGRAM-ID. ACCEPT-FLT-TEST. DATA DIVISION. WORKING-STORAGE SECTION. - 01 FLT-VAL PIC S9(4)P9(5) COMP. + 01 FLT-VAL PIC 9(6)P9(4) COMP. PROCEDURE DIVISION. ACCEPT FLT-VAL. DISPLAY FLT-VAL. STOP RUN. "#) - .expect_output_with_input("-1234.5678\n", "-1234.5678\n") + .expect_output_with_input("9004.21\n", "9004.21\n") .run(); } \ No newline at end of file diff --git a/crates/compiler/src/tests/maths.rs b/crates/compiler/src/tests/maths.rs new file mode 100644 index 0000000..7d53fe1 --- /dev/null +++ b/crates/compiler/src/tests/maths.rs @@ -0,0 +1,253 @@ +use super::common::CommonTestRunner; + +/// Tests that adding two integer values works as expected. +#[test] +fn add_int() { + CommonTestRunner::new("add_int") + .source(r#" +IDENTIFICATION DIVISION. +PROGRAM-ID. ADD-INT-TEST. + +DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A-VAL PIC 9(6) COMP VALUE 6. + 01 B-VAL PIC 9(6) COMP VALUE -4. + +PROCEDURE DIVISION. + ADD A-VAL TO B-VAL. + DISPLAY B-VAL. +STOP RUN. + "#) + .expect_output("2\n") + .run(); +} + +/// Tests that adding an integer value into two outputs works as expected. +#[test] +fn add_int_two_outputs() { + CommonTestRunner::new("add_int_two_outputs") + .source(r#" +IDENTIFICATION DIVISION. +PROGRAM-ID. ADD-INT-MULT-OUT-TEST. + +DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A-VAL PIC 9(6) COMP VALUE 6. + 01 B-VAL PIC 9(6) COMP VALUE 3. + 01 C-VAL PIC 9(6) COMP VALUE -4. + +PROCEDURE DIVISION. + ADD A-VAL TO B-VAL C-VAL. + DISPLAY B-VAL " " C-VAL. +STOP RUN. + "#) + .expect_output("9 2\n") + .run(); +} + +/// Tests that adding two integer values into one output resulting works as expected. +#[test] +fn add_int_resulting() { + CommonTestRunner::new("add_int_resulting") + .source(r#" +IDENTIFICATION DIVISION. +PROGRAM-ID. ADD-INT-RESULTING-TEST. + +DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A-VAL PIC 9(6) COMP VALUE 6. + 01 B-VAL PIC 9(6) COMP VALUE 2. + 01 C-VAL PIC 9(6) COMP VALUE 4. + 01 OUT-VAL PIC 9(6) COMP. + +PROCEDURE DIVISION. + ADD A-VAL B-VAL TO C-VAL GIVING OUT-VAL. + DISPLAY OUT-VAL. +STOP RUN. + "#) + .expect_output("12\n") + .run(); +} + +/// Tests that subtracting two integer values works as expected. +#[test] +fn sub_int() { + CommonTestRunner::new("sub_int") + .source(r#" +IDENTIFICATION DIVISION. +PROGRAM-ID. SUB-INT-TEST. + +DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A-VAL PIC 9(6) COMP VALUE 2. + 01 B-VAL PIC 9(6) COMP VALUE 4. + +PROCEDURE DIVISION. + SUBTRACT A-VAL FROM B-VAL. + DISPLAY B-VAL. +STOP RUN. + "#) + .expect_output("2\n") + .run(); +} + +/// Tests that subtracting an integer value into two outputs works as expected. +#[test] +fn sub_int_two_outputs() { + CommonTestRunner::new("sub_int_two_outputs") + .source(r#" +IDENTIFICATION DIVISION. +PROGRAM-ID. SUB-INT-MULT-OUT-TEST. + +DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A-VAL PIC 9(6) COMP VALUE 6. + 01 B-VAL PIC 9(6) COMP VALUE 3. + 01 C-VAL PIC 9(6) COMP VALUE 6. + +PROCEDURE DIVISION. + SUBTRACT A-VAL FROM B-VAL C-VAL. + DISPLAY B-VAL " " C-VAL. +STOP RUN. + "#) + .expect_output("-3 0\n") + .run(); +} + +/// Tests that subtracting two integer values from one output resulting works as expected. +#[test] +fn sub_int_resulting() { + CommonTestRunner::new("sub_int_resulting") + .source(r#" +IDENTIFICATION DIVISION. +PROGRAM-ID. SUB-INT-RESULTING-TEST. + +DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A-VAL PIC 9(6) COMP VALUE 6. + 01 B-VAL PIC 9(6) COMP VALUE 2. + 01 C-VAL PIC 9(6) COMP VALUE 10. + 01 OUT-VAL PIC 9(6) COMP. + +PROCEDURE DIVISION. + SUBTRACT A-VAL B-VAL FROM C-VAL GIVING OUT-VAL. + DISPLAY OUT-VAL. +STOP RUN. + "#) + .expect_output("2\n") + .run(); +} + +/// Tests that multiplying two integer values works as expected. +#[test] +fn mul_int() { + CommonTestRunner::new("mul_int") + .source(r#" +IDENTIFICATION DIVISION. +PROGRAM-ID. MUL-INT-TEST. + +DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A-VAL PIC 9(6) COMP VALUE 6. + 01 B-VAL PIC 9(6) COMP VALUE 2. + +PROCEDURE DIVISION. + MULTIPLY A-VAL BY B-VAL. + DISPLAY B-VAL. +STOP RUN. + "#) + .expect_output("12\n") + .run(); +} + +/// Tests that multiplying an integer value into two outputs works as expected. +#[test] +fn mul_int_two_outputs() { + CommonTestRunner::new("mul_int_two_outputs") + .source(r#" +IDENTIFICATION DIVISION. +PROGRAM-ID. MUL-INT-MULT-OUT-TEST. + +DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A-VAL PIC 9(6) COMP VALUE 6. + 01 B-VAL PIC 9(6) COMP VALUE 3. + 01 C-VAL PIC 9(6) COMP VALUE -4. + +PROCEDURE DIVISION. + MULTIPLY A-VAL BY B-VAL C-VAL. + DISPLAY B-VAL " " C-VAL. +STOP RUN. + "#) + .expect_output("18 -24\n") + .run(); +} + +/// Tests that multiplying two integer values into one output resulting works as expected. +#[test] +fn mul_int_resulting() { + CommonTestRunner::new("mul_int_resulting") + .source(r#" +IDENTIFICATION DIVISION. +PROGRAM-ID. MUL-INT-RESULTING-TEST. + +DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A-VAL PIC 9(6) COMP VALUE 6. + 01 B-VAL PIC 9(6) COMP VALUE 2. + 01 C-VAL PIC 9(6) COMP VALUE 4. + 01 OUT-VAL PIC 9(6) COMP. + +PROCEDURE DIVISION. + MULTIPLY A-VAL B-VAL BY C-VAL GIVING OUT-VAL. + DISPLAY OUT-VAL. +STOP RUN. + "#) + .expect_output("48\n") + .run(); +} + +/// Tests that dividing two integer values works as expected. +#[test] +fn div_int() { + CommonTestRunner::new("div_int") + .source(r#" +IDENTIFICATION DIVISION. +PROGRAM-ID. DIV-INT-TEST. + +DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A-VAL PIC 9(6) COMP VALUE 2. + 01 B-VAL PIC 9(6) COMP VALUE 6. + +PROCEDURE DIVISION. + DIVIDE A-VAL INTO B-VAL. + DISPLAY B-VAL. +STOP RUN. + "#) + .expect_output("3\n") + .run(); +} + +/// Tests that dividing two integer values into a float works as expected. +#[test] +fn div_int_into_float() { + CommonTestRunner::new("div_int_into_float") + .source(r#" +IDENTIFICATION DIVISION. +PROGRAM-ID. DIV-INT-INTO-FLT-TEST. + +DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A-VAL PIC 9(6) COMP VALUE 4. + 01 B-VAL PIC 9(6) COMP VALUE 6. + 01 OUT-VAL PIC 9(6)P9(4) COMP. + +PROCEDURE DIVISION. + DIVIDE B-VAL BY A-VAL GIVING OUT-VAL. + DISPLAY OUT-VAL. +STOP RUN. + "#) + .expect_output("1.5\n") + .run(); +} \ No newline at end of file diff --git a/crates/compiler/src/tests/memory.rs b/crates/compiler/src/tests/memory.rs index c221053..6759ccd 100644 --- a/crates/compiler/src/tests/memory.rs +++ b/crates/compiler/src/tests/memory.rs @@ -6,7 +6,7 @@ fn int_lit_move() { CommonTestRunner::new("int_lit_move") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. INT-LIT-MOV. +PROGRAM-ID. INT-MOVE-TEST. DATA DIVISION. WORKING-STORAGE SECTION. @@ -20,130 +20,127 @@ STOP RUN. .run(); } - /// Tests that a simple floating point MOVE instruction compiles. #[test] -fn float_lit_move() { - CommonTestRunner::new("float_lit_move") +fn float_move() { + CommonTestRunner::new("float_move") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. FLT-LIT-MOV. +PROGRAM-ID. FLT-MOVE-TEST. DATA DIVISION. WORKING-STORAGE SECTION. - 01 FLT-VAL PIC S9(4)P9(4) COMP. + 01 FLT-VAL PIC 9(4)P9(4) COMP. PROCEDURE DIVISION. - MOVE -1234.5678 TO FLT-VAL. + MOVE 20.04 TO FLT-VAL. STOP RUN. "#) .expect_pass() .run(); } -/// Tests that a simple string literal MOVE instruction compiles. +/// Tests that a simple string MOVE instruction compiles. #[test] -fn str_lit_move() { - CommonTestRunner::new("str_lit_move") +fn str_move() { + CommonTestRunner::new("str_move") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. STR-LIT-MOV. +PROGRAM-ID. STR-MOVE-TEST. DATA DIVISION. WORKING-STORAGE SECTION. 01 STR-VAL PIC X(10). PROCEDURE DIVISION. - MOVE "SomeString" TO STR-VAL. + MOVE "TestVal" TO STR-VAL. STOP RUN. "#) .expect_pass() .run(); } -/// Tests that an OOB string literal MOVE instruction fails to compile. +/// Tests that an overly large string MOVE instruction does not compile. #[test] -fn str_inv_lit_move() { - CommonTestRunner::new("str_inv_lit_move") +fn str_invalid_move() { + CommonTestRunner::new("str_move_invalid") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. STR-INV-LIT-MOV. +PROGRAM-ID. STR-MOVE-INV-TEST. DATA DIVISION. WORKING-STORAGE SECTION. 01 STR-VAL PIC X(10). PROCEDURE DIVISION. - MOVE "SomeTooLargeString" TO STR-VAL. + MOVE "TestValTooLongOhNo" TO STR-VAL. STOP RUN. "#) - .expect_fail(Some("move incompatible literal")) + .expect_fail(Some("incompatible literal")) .run(); } -/// Tests that a spanned source string MOVE instruction behaves as expected. +/// Tests that a simple spanned source string MOVE instruction compiles. #[test] -fn str_spanned_src_move() { - CommonTestRunner::new("str_spanned_src_move") +fn str_move_src_spanned() { + CommonTestRunner::new("str_move_src_spanned") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. STR-SPANNED-SRC-MOV. +PROGRAM-ID. STR-MOVE-SRC-SPANNED-TEST. DATA DIVISION. WORKING-STORAGE SECTION. - 01 SRC-VAL PIC X(10) VALUE "SomeString". - 01 DEST-VAL PIC X(10). + 01 SRC-VAL PIC X(10) VALUE "TestVal". + 01 STR-VAL PIC X(10). PROCEDURE DIVISION. - MOVE SRC-VAL(1:4) TO DEST-VAL. - DISPLAY DEST-VAL. + MOVE SRC-VAL(5:3) TO STR-VAL. + DISPLAY STR-VAL. STOP RUN. "#) - .expect_output("Some\n") + .expect_output("Val\n") .run(); } -/// Tests that a spanned destination MOVE instruction behaves as expected. +/// Tests that a simple spanned destination string MOVE instruction compiles. #[test] -fn str_spanned_dest_move() { - CommonTestRunner::new("str_spanned_dest_move") +fn str_move_dest_spanned() { + CommonTestRunner::new("str_move_dest_spanned") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. STR-SPANNED-DEST-MOV. +PROGRAM-ID. STR-MOVE-DEST-SPANNED-TEST. DATA DIVISION. WORKING-STORAGE SECTION. - 01 SRC-VAL PIC X(10) VALUE "SomeString". - 01 DEST-VAL PIC X(10). + 01 STR-VAL PIC X(10). PROCEDURE DIVISION. - MOVE SRC-VAL TO DEST-VAL(4:4). - DISPLAY DEST-VAL. + MOVE "TestVal" TO STR-VAL(1:4). + DISPLAY STR-VAL. STOP RUN. "#) - .expect_output(" Some\n") + .expect_output("Test\n") .run(); } -/// Tests that a spanned source and destination MOVE instruction -/// behaves as expected. +/// Tests that a simple spanned source & destination string MOVE instruction compiles. #[test] -fn str_spanned_src_dest_move() { - CommonTestRunner::new("str_spanned_src_dest_move") +fn str_move_all_spanned() { + CommonTestRunner::new("str_move_all_spanned") .source(r#" IDENTIFICATION DIVISION. -PROGRAM-ID. STR-SPANNED-SRC-DEST-MOV. +PROGRAM-ID. STR-MOVE-ALL-SPANNED-TEST. DATA DIVISION. WORKING-STORAGE SECTION. - 01 SRC-VAL PIC X(10) VALUE "SomeString". - 01 DEST-VAL PIC X(10). + 01 SRC-VAL PIC X(10) VALUE "TestVal". + 01 STR-VAL PIC X(10). PROCEDURE DIVISION. - MOVE SRC-VAL(5:6) TO DEST-VAL(2:3). - DISPLAY DEST-VAL. + MOVE SRC-VAL(2:3) TO STR-VAL(1:2). + DISPLAY STR-VAL. STOP RUN. "#) - .expect_output(" Str\n") + .expect_output("es\n") .run(); } \ No newline at end of file diff --git a/crates/compiler/src/tests/mod.rs b/crates/compiler/src/tests/mod.rs index a50dcd0..4f1d1ff 100644 --- a/crates/compiler/src/tests/mod.rs +++ b/crates/compiler/src/tests/mod.rs @@ -2,7 +2,9 @@ mod common; // Individual conformance test modules. +mod control; mod data; mod intrinsics; mod io; +mod maths; mod memory; \ No newline at end of file