From 2844a2c3365df6f2e271221543da7cb262e79954 Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Wed, 29 Jan 2025 13:11:58 +0100 Subject: [PATCH] lit: Some more tests --- src/lowering/property.rs | 2 +- .../called_inside_pou_where_defined.st | 20 +++++++ .../multiply_properties_single_pou.st | 58 +++++++++++++++++++ tests/lit/single/property/recursion.st | 2 +- 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 tests/lit/single/property/called_inside_pou_where_defined.st create mode 100644 tests/lit/single/property/multiply_properties_single_pou.st diff --git a/src/lowering/property.rs b/src/lowering/property.rs index 960ae4e941..ab97e37537 100644 --- a/src/lowering/property.rs +++ b/src/lowering/property.rs @@ -289,7 +289,7 @@ mod tests { use crate::{ lowering::property::PropertyLowerer, resolver::AstAnnotations, - test_utils::tests::{annotate_with_ids, index_unit_with_id, index_with_ids, parse}, + test_utils::tests::{annotate_with_ids, index_unit_with_id, parse}, }; #[test] diff --git a/tests/lit/single/property/called_inside_pou_where_defined.st b/tests/lit/single/property/called_inside_pou_where_defined.st new file mode 100644 index 0000000000..a1a5443f4c --- /dev/null +++ b/tests/lit/single/property/called_inside_pou_where_defined.st @@ -0,0 +1,20 @@ +// RUN: (%COMPILE %s && %RUN) | %CHECK %s + +FUNCTION_BLOCK A + PROPERTY sayCheese : DINT + GET + printf('Cheese'); + END_GET + END_PROPERTY + + sayCheese; +END_FUNCTION_BLOCK + +FUNCTION main + VAR + instanceA : A; + END_VAR + + // CHECK: Cheese + instanceA(); +END_FUNCTION \ No newline at end of file diff --git a/tests/lit/single/property/multiply_properties_single_pou.st b/tests/lit/single/property/multiply_properties_single_pou.st new file mode 100644 index 0000000000..2bcf516479 --- /dev/null +++ b/tests/lit/single/property/multiply_properties_single_pou.st @@ -0,0 +1,58 @@ +// RUN: (%COMPILE %s && %RUN) | %CHECK %s + +FUNCTION_BLOCK A + VAR + foo : DINT; + END_VAR + + PROPERTY increaseFooBy10 : DINT + GET + printf('Inside increaseFooBy10$N'); + foo := foo + 10; + END_GET + END_PROPERTY + + PROPERTY increaseFooBy20 : DINT + GET + printf('Inside increaseFooBy20$N'); + foo := foo + 20; + END_GET + END_PROPERTY + + PROPERTY increaseFooBy30 : DINT + GET + printf('Inside increaseFooBy30$N'); + increaseFooBy20; + increaseFooBy10; + END_GET + END_PROPERTY + + PROPERTY readFoo : DINT + GET + printf('Inside readFoo$N'); + readFoo := foo; + END_GET + END_PROPERTY +END_FUNCTION_BLOCK + +FUNCTION main + VAR + instanceA : A; + result : DINT; + END_VAR + + // CHECK: Inside increaseFooBy10 + instanceA.increaseFooBy10; + + // CHECK: Inside increaseFooBy20 + instanceA.increaseFooBy20; + + // CHECK: Inside increaseFooBy30 + // CHECK: Inside increaseFooBy20 + // CHECK: Inside increaseFooBy10 + instanceA.increaseFooBy30; + + // CHECK: Inside readFoo + // CHECK: 60 + printf('%d$N', instanceA.readFoo); +END_FUNCTION \ No newline at end of file diff --git a/tests/lit/single/property/recursion.st b/tests/lit/single/property/recursion.st index deb3ff5786..5d4958c823 100644 --- a/tests/lit/single/property/recursion.st +++ b/tests/lit/single/property/recursion.st @@ -1,5 +1,5 @@ // Ignored for now -// RRRRRRRRRRRRRRRRRRRRRRUN: (%COMPILE %s && %RUN) | %CHECK %s +// NUR: (%COMPILE %s && %RUN) | %CHECK %s FUNCTION_BLOCK A PROPERTY foo : DINT