summaryrefslogtreecommitdiff
path: root/tests/arrays
diff options
context:
space:
mode:
authorUlrich Küttler <kuettler@gmail.com>2020-12-22 08:59:16 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2020-12-22 10:53:10 +0100
commit462fdc23f804fe7c5d355c3c593ace7303eb15a4 (patch)
tree57dda019a1512789b572cf0441349c9adf79d2ce /tests/arrays
parentdf7a984607f55338ff2dde6f2fd324dc363a46b4 (diff)
downloadvala-462fdc23f804fe7c5d355c3c593ace7303eb15a4.tar.gz
vala: SliceExpression need to return heap-allocated or unowned references
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1120
Diffstat (limited to 'tests/arrays')
-rw-r--r--tests/arrays/slice-fixed-length.vala75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/arrays/slice-fixed-length.vala b/tests/arrays/slice-fixed-length.vala
new file mode 100644
index 000000000..7b81f615a
--- /dev/null
+++ b/tests/arrays/slice-fixed-length.vala
@@ -0,0 +1,75 @@
+void manam (string[] foo) {
+ assert (foo.length == 2);
+ assert (foo[0] == "bar");
+ assert (foo[1] == "baz");
+}
+
+void minim (owned string[] foo) {
+ assert (foo.length == 2);
+ assert (foo[0] == "bar");
+ assert (foo[1] == "baz");
+}
+
+void main () {
+ string bar[4] = { "foo", "bar", "baz", "buzz" };
+ {
+ var foo = bar[1:3];
+ assert (foo.length == 2);
+ assert (foo[0] == "bar");
+ assert (foo[1] == "baz");
+ }
+ {
+ unowned var foo = bar[1:3];
+ assert (foo.length == 2);
+ assert (foo[0] == "bar");
+ assert (foo[1] == "baz");
+ }
+ {
+ int begin = 1;
+ var foo = bar[begin:3];
+ assert (foo.length == 2);
+ assert (foo[0] == "bar");
+ assert (foo[1] == "baz");
+ }
+ {
+ string[] foo = bar[1:3];
+ assert (foo.length == 2);
+ assert (foo[0] == "bar");
+ assert (foo[1] == "baz");
+ }
+ {
+ unowned string[] foo = bar[1:3];
+ assert (foo.length == 2);
+ assert (foo[0] == "bar");
+ assert (foo[1] == "baz");
+ }
+ {
+ int end = 3;
+ string[] foo = bar[1:end];
+ assert (foo.length == 2);
+ assert (foo[0] == "bar");
+ assert (foo[1] == "baz");
+ }
+ {
+ manam (bar[1:3]);
+ }
+ {
+ int begin = 1;
+ manam (bar[begin:3]);
+ }
+ {
+ int end = 3;
+ manam (bar[1:end]);
+ }
+ {
+ minim (bar[1:3]);
+ }
+ {
+ int begin = 1;
+ minim (bar[begin:3]);
+ }
+ {
+ int end = 3;
+ minim (bar[1:end]);
+ }
+}