[vala/wip/issue/327: 20/27] Added with statement declaration tests



commit 3fa2526ae774c04eb8e30ad7d48122f252315cba
Author: Nick Schrader <nick schrader mailbox org>
Date:   Sun Apr 5 20:32:34 2020 -0300

    Added with statement declaration tests

 tests/Makefile.am                               |  8 +++-
 tests/objects/with-nested.vala                  | 64 ++-----------------------
 tests/parser/with-invalid-declaration.test      |  5 ++
 tests/parser/with-invalid-expression.test       |  5 ++
 tests/semantic/with-declaration-cast-type.vala  |  7 +++
 tests/semantic/with-declaration-wrong-type.test |  9 ++++
 tests/semantic/with-declaration.vala            | 35 ++++++++++++++
 tests/semantic/with-no-declaration.test         |  7 +++
 tests/semantic/with-no-such-with-member.test    |  9 ----
 tests/semantic/with-outside-declaration.test    | 13 +++++
 10 files changed, 93 insertions(+), 69 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 75276e894..709a4f14d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -731,6 +731,8 @@ TESTS = \
        parser/using-invalid-namespace.test \
        parser/with-embedded.vala \
        parser/with-empty.vala \
+       parser/with-invalid-declaration.test \
+       parser/with-invalid-expression.test \
        parser/with-no-block.test \
        parser/with-no-expression.test \
        parser/yield-method.test \
@@ -930,6 +932,9 @@ TESTS = \
        semantic/with-buildin.vala \
        semantic/with-class.test \
        semantic/with-compact.vala \
+       semantic/with-declaration-cast-type.vala \
+       semantic/with-declaration-wrong-type.test \
+       semantic/with-declaration.vala \
        semantic/with-dereferenced-pointer.vala \
        semantic/with-enum.test \
        semantic/with-enum-member.vala \
@@ -937,10 +942,11 @@ TESTS = \
        semantic/with-error-member.test \
        semantic/with-pointer.test \
        semantic/with-namespace.test \
+       semantic/with-no-declaration.test \
        semantic/with-no-such-member.test \
-       semantic/with-no-such-with-member.test \
        semantic/with-null.vala \
        semantic/with-string.vala \
+       semantic/with-outside-declaration.test \
        semantic/with-value.vala \
        semantic/yield-call-requires-async-context.test \
        semantic/yield-call-requires-async-method.test \
diff --git a/tests/objects/with-nested.vala b/tests/objects/with-nested.vala
index 387110868..ac356654e 100644
--- a/tests/objects/with-nested.vala
+++ b/tests/objects/with-nested.vala
@@ -9,80 +9,26 @@ class Bar {
 class Test {
     public int field;
 
-    void method_local () {
-        var field = 0;
-        var foo = new Foo ();
-
-        with (foo) {
-            field = 10;
-            //with.field = 20;
-            this.field = 30;
-        }
-
-        assert (foo.field == 10);
-        //assert (field == 20);
-        assert (this.field == 30);
-    }
-
     void nested () {
-        var field = 0;
         var foo = new Foo ();
         var bar = new Bar ();
 
-        with (foo) {
+        with (var f = foo) {
             field = 100;
             with (bar) {
                 field = 200;
-                //with.with.field = 300;
+                f.field = 300;
+                this.field = 400;
             }
         }
 
-        assert (foo.field == 100);
+        assert (foo.field == 300);
         assert (bar.field == 200);
-        //assert (field == 300);
-
-        /*with (foo) {
-            field = 1000;
-            with (bar) {
-                field = with.field;
-                this.field = 2000;
-            }
-        }
-
-        assert (bar.field == 1000);
-        assert (this.field == 2000);*/
-    }
-
-    void nested_useless () {
-        var field = 0;
-        var foo = new Foo ();
-        var bar = new Bar ();
-
-        /*with (foo) {
-            with.this.field = 10000;
-            with.foo.field = 20000;
-        }
-
-        assert (this.field == 10000);
-        assert (foo.field == 20000);
-
-        with (foo) {
-            with (bar) {
-                field = 30000;
-                with.field = 40000;
-                with.with.field = 50000;
-            }
-        }
-
-        assert (bar.field == 30000)
-        assert (foo.field == 40000);
-        assert (field == 50000);*/
+        assert (this.field == 400);
     }
 
     static int main () {
-        new Test ().method_local ();
         new Test ().nested ();
-        new Test ().nested_useless ();
         return 0;
     }
 }
diff --git a/tests/parser/with-invalid-declaration.test b/tests/parser/with-invalid-declaration.test
new file mode 100644
index 000000000..ad9b8cfcc
--- /dev/null
+++ b/tests/parser/with-invalid-declaration.test
@@ -0,0 +1,5 @@
+Invalid Code
+
+void main () {
+    with (var f foo) { }
+}
diff --git a/tests/parser/with-invalid-expression.test b/tests/parser/with-invalid-expression.test
new file mode 100644
index 000000000..67bbcc60f
--- /dev/null
+++ b/tests/parser/with-invalid-expression.test
@@ -0,0 +1,5 @@
+Invalid Code
+
+void main () {
+    with (f foo) { }
+}
diff --git a/tests/semantic/with-declaration-cast-type.vala b/tests/semantic/with-declaration-cast-type.vala
new file mode 100644
index 000000000..df5b583c1
--- /dev/null
+++ b/tests/semantic/with-declaration-cast-type.vala
@@ -0,0 +1,7 @@
+class Foo { }
+
+class Bar : Foo { }
+
+void main () {
+    with (Foo f = new Bar ()) { }
+}
diff --git a/tests/semantic/with-declaration-wrong-type.test b/tests/semantic/with-declaration-wrong-type.test
new file mode 100644
index 000000000..1926cf56f
--- /dev/null
+++ b/tests/semantic/with-declaration-wrong-type.test
@@ -0,0 +1,9 @@
+Invalid Code
+
+class Foo { }
+
+class Bar { }
+
+void main () {
+    with (Bar f = new Foo ()) { }
+}
diff --git a/tests/semantic/with-declaration.vala b/tests/semantic/with-declaration.vala
new file mode 100644
index 000000000..78763c333
--- /dev/null
+++ b/tests/semantic/with-declaration.vala
@@ -0,0 +1,35 @@
+class Foo {
+    public int i;
+    public int j;
+}
+
+void main () {
+    var foo = new Foo ();
+    with (foo) {
+        i = 10;
+    }
+
+    assert (foo.i == 10);
+    with (var f = foo) {
+        i = 100;
+        f.j = 200;
+    }
+
+    assert (foo.i == 100);
+    assert (foo.j == 200);
+    with (Foo f = foo) {
+        i = 1000;
+        f.j = 2000;
+    }
+
+    assert (foo.i == 1000);
+    assert (foo.j == 2000);
+    Foo f;
+    with (f = foo) {
+        i = 10000;
+        f.j = 20000;
+    }
+
+    assert (f.i == 10000);
+    assert (foo.j == 20000);
+}
diff --git a/tests/semantic/with-no-declaration.test b/tests/semantic/with-no-declaration.test
new file mode 100644
index 000000000..a1a3721a3
--- /dev/null
+++ b/tests/semantic/with-no-declaration.test
@@ -0,0 +1,7 @@
+Invalid Code
+
+class Foo { }
+
+void main () {
+    with (f = new Foo ()) { }
+}
diff --git a/tests/semantic/with-outside-declaration.test b/tests/semantic/with-outside-declaration.test
new file mode 100644
index 000000000..86af413e7
--- /dev/null
+++ b/tests/semantic/with-outside-declaration.test
@@ -0,0 +1,13 @@
+Invalid Code
+
+class Foo {
+    public int i;
+}
+
+void main () {
+    with (var f = new Foo ()) {
+        i = 10;
+    }
+
+    f.i = 100;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]