summaryrefslogtreecommitdiff
path: root/tests/methods
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2019-11-26 11:06:45 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2019-11-26 13:03:31 +0100
commit34409b10f9ed1dd9cbdc110f8297a8efc34613f3 (patch)
treea30280952c15d41b513daff7145cce1d06612695 /tests/methods
parentaa628acffcb170cfb1634bc65d17b8b04a10446d (diff)
downloadvala-34409b10f9ed1dd9cbdc110f8297a8efc34613f3.tar.gz
codegen: Fix precondition in creation method of structs
Diffstat (limited to 'tests/methods')
-rw-r--r--tests/methods/prepostconditions.vala27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/methods/prepostconditions.vala b/tests/methods/prepostconditions.vala
index d7474df75..d8cd4d3f0 100644
--- a/tests/methods/prepostconditions.vala
+++ b/tests/methods/prepostconditions.vala
@@ -61,6 +61,24 @@ class Foo {
}
}
+struct Bar {
+ public bool ensured;
+ public bool required;
+
+ public Bar () requires (required = true) {
+ }
+
+ public Bar.post () ensures (ensured = true) {
+ }
+
+ public void bar () ensures (ensured = true) {
+ }
+
+ public string foo () ensures (result.length >= 3) {
+ return "foo";
+ }
+}
+
void main () {
var foo = new Foo();
assert(foo.required);
@@ -76,4 +94,13 @@ void main () {
var foo2 = new Foo.post ();
assert (foo2.ensured);
+
+ var bar = new Bar ();
+ assert (bar.required);
+ bar.bar ();
+ assert (bar.ensured);
+ assert (bar.foo () == "foo");
+
+ var bar2 = new Bar.post ();
+ assert (bar2.ensured);
}