diff options
Diffstat (limited to 'tests')
31 files changed, 436 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 78c939a2f..7ff4ff350 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -504,6 +504,9 @@ TESTS = \ objects/bug795225-3.test \ objects/bug795225-4.test \ objects/bug795521.vala \ + objects/with-expression.vala \ + objects/with-instance.vala \ + objects/with-nested.vala \ errors/catch-error-code.vala \ errors/catch-in-finally.vala \ errors/default-gtype.vala \ @@ -733,6 +736,12 @@ TESTS = \ parser/using-ambiguous-reference.test \ parser/using-directive.vala \ 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 \ parser/yield-return.test \ parser/yield-return.vala \ @@ -927,6 +936,26 @@ TESTS = \ semantic/unary-unsupported-increment.test \ semantic/unary-unsupported-minus.test \ semantic/unary-unsupported-negation.test \ + semantic/with-array.test \ + 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 \ + semantic/with-error.test \ + 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-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 \ semantic/yield-creation-requires-async-context.test \ @@ -940,6 +969,7 @@ NON_NULL_TESTS = \ nullability/member-access-nullable-instance.test \ nullability/method-parameter-invalid-convert.test \ nullability/method-return-invalid-convert.test \ + nullability/with-non-null.test \ $(NULL) LINUX_TESTS = \ diff --git a/tests/nullability/with-non-null.test b/tests/nullability/with-non-null.test new file mode 100644 index 000000000..ed8fb40df --- /dev/null +++ b/tests/nullability/with-non-null.test @@ -0,0 +1,12 @@ +Invalid Code + +class Foo { + public int i; +} + +void main () { + Foo? f = new Foo (); + with (f) { + i = 7; + } +} diff --git a/tests/objects/with-expression.vala b/tests/objects/with-expression.vala new file mode 100644 index 000000000..8e2821ded --- /dev/null +++ b/tests/objects/with-expression.vala @@ -0,0 +1,38 @@ +class Foo { + public static int factory_called = 0; + public static Foo factory () { + factory_called++; + return new Foo (); + } + + public static int method_called = 0; + public void method () { + method_called++; + } +} + +void test () { + var foo = new Foo (); + with (foo) + method (); + + with (new Foo ()) + method (); + + with (Foo.factory ()) { + method (); + method (); + } + + Foo[] arr = {foo, foo}; + with (arr[0]) { + method (); + } + + assert (Foo.method_called == 5); + assert (Foo.factory_called == 1); +} + +void main () { + test (); +} diff --git a/tests/objects/with-instance.vala b/tests/objects/with-instance.vala new file mode 100644 index 000000000..715833ef8 --- /dev/null +++ b/tests/objects/with-instance.vala @@ -0,0 +1,73 @@ +class Foo { + public int field; + public string prop { get; set; } + + public bool method_called = false; + public void method () { + method_called = true; + } +} + +class Bar : Foo { } + +class TestFoo { + public static int class_field; + public int instance_field; + + public void test () { + var foo = new Foo (); + var local_field = 0; + + with (foo) { + field = 10; + prop = "prop"; + method (); + + local_field = 20; + class_field = 30; + instance_field = 40; + } + + assert (foo.field == 10); + assert (foo.prop == "prop"); + assert (foo.method_called); + + assert (local_field == 20); + assert (class_field == 30); + assert (instance_field == 40); + } +} + +// Copy and paste TestFoo, change Foo to Bar +class TestBar { + public static int class_field; + public int instance_field; + + public void test () { + var foo = new Bar (); + var local_field = 0; + + with (foo) { + field = 10; + prop = "prop"; + method (); + + local_field = 20; + class_field = 30; + instance_field = 40; + } + + assert (foo.field == 10); + assert (foo.prop == "prop"); + assert (foo.method_called); + + assert (local_field == 20); + assert (class_field == 30); + assert (instance_field == 40); + } +} + +void main () { + new TestFoo ().test (); + new TestBar ().test (); +} diff --git a/tests/objects/with-nested.vala b/tests/objects/with-nested.vala new file mode 100644 index 000000000..ac356654e --- /dev/null +++ b/tests/objects/with-nested.vala @@ -0,0 +1,34 @@ +class Foo { + public int field; +} + +class Bar { + public int field; +} + +class Test { + public int field; + + void nested () { + var foo = new Foo (); + var bar = new Bar (); + + with (var f = foo) { + field = 100; + with (bar) { + field = 200; + f.field = 300; + this.field = 400; + } + } + + assert (foo.field == 300); + assert (bar.field == 200); + assert (this.field == 400); + } + + static int main () { + new Test ().nested (); + return 0; + } +} diff --git a/tests/parser/with-embedded.vala b/tests/parser/with-embedded.vala new file mode 100644 index 000000000..c668e5afc --- /dev/null +++ b/tests/parser/with-embedded.vala @@ -0,0 +1,4 @@ +void main () { + with (10) + assert (to_string () == "10"); +} diff --git a/tests/parser/with-empty.vala b/tests/parser/with-empty.vala new file mode 100644 index 000000000..1a870b61f --- /dev/null +++ b/tests/parser/with-empty.vala @@ -0,0 +1,3 @@ +void main () { + with (10); +} diff --git a/tests/parser/with-invalid-declaration.test b/tests/parser/with-invalid-declaration.test new file mode 100644 index 000000000..ae1e775b2 --- /dev/null +++ b/tests/parser/with-invalid-declaration.test @@ -0,0 +1,6 @@ +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..50fbe77e3 --- /dev/null +++ b/tests/parser/with-invalid-expression.test @@ -0,0 +1,6 @@ +Invalid Code + +void main () { + with (f foo) { + } +} diff --git a/tests/parser/with-no-block.test b/tests/parser/with-no-block.test new file mode 100644 index 000000000..237bd89d8 --- /dev/null +++ b/tests/parser/with-no-block.test @@ -0,0 +1,5 @@ +Invalid Code + +void main () { + with (10) +}
\ No newline at end of file diff --git a/tests/parser/with-no-expression.test b/tests/parser/with-no-expression.test new file mode 100644 index 000000000..0e01d28ab --- /dev/null +++ b/tests/parser/with-no-expression.test @@ -0,0 +1,6 @@ +Invalid Code + +void main () { + with () { + } +} diff --git a/tests/semantic/with-array.test b/tests/semantic/with-array.test new file mode 100644 index 000000000..bf0b4d18d --- /dev/null +++ b/tests/semantic/with-array.test @@ -0,0 +1,7 @@ +Invalid Code + +void main () { + int[] arr = { 1, 2, 3 }; + with (arr) { + } +} diff --git a/tests/semantic/with-buildin.vala b/tests/semantic/with-buildin.vala new file mode 100644 index 000000000..999554adf --- /dev/null +++ b/tests/semantic/with-buildin.vala @@ -0,0 +1,5 @@ +void main () { + with (stdout) { + assert (!eof ()); + } +} diff --git a/tests/semantic/with-class.test b/tests/semantic/with-class.test new file mode 100644 index 000000000..2bea6e52c --- /dev/null +++ b/tests/semantic/with-class.test @@ -0,0 +1,9 @@ +Invalid Code + +class Foo { +} + +void main () { + with (Foo) { + } +} diff --git a/tests/semantic/with-compact.vala b/tests/semantic/with-compact.vala new file mode 100644 index 000000000..b2530c91f --- /dev/null +++ b/tests/semantic/with-compact.vala @@ -0,0 +1,13 @@ +[Compact] +class Foo { + public int i; +} + +void main () { + var foo = new Foo (); + with (foo) { + i = 13; + } + + assert (foo.i == 13); +} diff --git a/tests/semantic/with-declaration-cast-type.vala b/tests/semantic/with-declaration-cast-type.vala new file mode 100644 index 000000000..c855d1c0b --- /dev/null +++ b/tests/semantic/with-declaration-cast-type.vala @@ -0,0 +1,10 @@ +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..79ae8f8fb --- /dev/null +++ b/tests/semantic/with-declaration-wrong-type.test @@ -0,0 +1,12 @@ +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-dereferenced-pointer.vala b/tests/semantic/with-dereferenced-pointer.vala new file mode 100644 index 000000000..42fc20fd8 --- /dev/null +++ b/tests/semantic/with-dereferenced-pointer.vala @@ -0,0 +1,14 @@ +class Foo { + public int i; +} + +void main () { + var f = new Foo (); + var p = &f; + + with (*p) { + i = 13; + } + + assert (f.i == 13); +} diff --git a/tests/semantic/with-enum-member.vala b/tests/semantic/with-enum-member.vala new file mode 100644 index 000000000..3b5517db0 --- /dev/null +++ b/tests/semantic/with-enum-member.vala @@ -0,0 +1,8 @@ +enum FooEnum { + FIRST +} + +void main () { + with (FooEnum.FIRST) { + } +} diff --git a/tests/semantic/with-enum.test b/tests/semantic/with-enum.test new file mode 100644 index 000000000..3a473a2f1 --- /dev/null +++ b/tests/semantic/with-enum.test @@ -0,0 +1,10 @@ +Invalid Code + +enum FooEnum { + FIRST +} + +void main () { + with (FooEnum) { + } +} diff --git a/tests/semantic/with-error-member.test b/tests/semantic/with-error-member.test new file mode 100644 index 000000000..6d883b6e5 --- /dev/null +++ b/tests/semantic/with-error-member.test @@ -0,0 +1,11 @@ +Invalid Code + +errordomain FooError { + FAIL +} + +void main () { + var e = new FooError.FAIL ("foo"); + with (e) { + } +} diff --git a/tests/semantic/with-error.test b/tests/semantic/with-error.test new file mode 100644 index 000000000..61cc28efa --- /dev/null +++ b/tests/semantic/with-error.test @@ -0,0 +1,10 @@ +Invalid Code + +errordomain FooError { + FAIL +} + +void main () { + with (FooError) { + } +} diff --git a/tests/semantic/with-namespace.test b/tests/semantic/with-namespace.test new file mode 100644 index 000000000..e328fe205 --- /dev/null +++ b/tests/semantic/with-namespace.test @@ -0,0 +1,9 @@ +Invalid Code + +namespace Foo { +} + +void main () { + with (Foo) { + } +} diff --git a/tests/semantic/with-no-declaration.test b/tests/semantic/with-no-declaration.test new file mode 100644 index 000000000..3b033a8e3 --- /dev/null +++ b/tests/semantic/with-no-declaration.test @@ -0,0 +1,9 @@ +Invalid Code + +class Foo { +} + +void main () { + with (f = new Foo ()) { + } +} diff --git a/tests/semantic/with-no-such-member.test b/tests/semantic/with-no-such-member.test new file mode 100644 index 000000000..5f20d21c8 --- /dev/null +++ b/tests/semantic/with-no-such-member.test @@ -0,0 +1,10 @@ +Invalid Code + +class Foo { +} + +void main () { + with (new Foo ()) { + field = 100; + } +} diff --git a/tests/semantic/with-null.vala b/tests/semantic/with-null.vala new file mode 100644 index 000000000..dd108b256 --- /dev/null +++ b/tests/semantic/with-null.vala @@ -0,0 +1,12 @@ +class Foo { + public int i; +} + +void main () { + Foo? f = null; + Process.exit (0); + + with (f) { + i = 7; + } +} 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; +} diff --git a/tests/semantic/with-pointer.test b/tests/semantic/with-pointer.test new file mode 100644 index 000000000..d268b1cd2 --- /dev/null +++ b/tests/semantic/with-pointer.test @@ -0,0 +1,7 @@ +Invalid Code + +void main () { + int i = 0; + with (&i) { + } +} diff --git a/tests/semantic/with-string.vala b/tests/semantic/with-string.vala new file mode 100644 index 000000000..133be17b6 --- /dev/null +++ b/tests/semantic/with-string.vala @@ -0,0 +1,5 @@ +void main () { + with ("string ") { + assert (chomp () == "string"); + } +} diff --git a/tests/semantic/with-value.vala b/tests/semantic/with-value.vala new file mode 100644 index 000000000..a0f111ad8 --- /dev/null +++ b/tests/semantic/with-value.vala @@ -0,0 +1,10 @@ +void main () { + int i = 0; + string s; + + with (i) { + s = i.to_string (); + } + + assert (s == "0"); +} |