mirror of
https://github.com/slint-ui/slint.git
synced 2025-07-16 01:25:27 +00:00

* syntax_tests: allow to "bless" tests, and don't use a regexp
A regexp was used at the beginning because I thought we would want to
allow error to contains things that were not predictable or that would
often change. But this is not the case¹. It is better to actually test
for the full error message
¹ well actually it was the case for path, but there is another substitution to
`📂` for the manifest directory
* syntax_tests: Bless the tests
* syntax_tests: Manual adjust after bless
Because there used to be comments on the same line of the message which
bless don't support
* Fix error message with path on windows
- The debug implementation of path make double slash, that's not what
we want to show the user
- normalize paths to use `/` so the test passes
164 lines
3.6 KiB
Text
164 lines
3.6 KiB
Text
|
|
|
|
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
|
|
|
export component Foo {
|
|
property <int> prop;
|
|
callback c1;
|
|
pure callback c2;
|
|
|
|
function f1() {
|
|
prop = 1;
|
|
}
|
|
function f2() -> int { 42 }
|
|
|
|
pure function f3() {
|
|
f2();
|
|
f1();
|
|
// ^error{Call of impure function 'f1'}
|
|
|
|
prop /= 5;
|
|
// ^error{Assignment in a pure context}
|
|
}
|
|
public function f4() {}
|
|
|
|
|
|
pure function f5() {
|
|
f1();
|
|
// ^error{Call of impure function 'f1'}
|
|
f2(); // ok, private function auto-detected as pure
|
|
f3();
|
|
f4();
|
|
// ^error{Call of impure function 'f4'}
|
|
c1();
|
|
// ^error{Call of impure callback 'c1'}
|
|
c2();
|
|
}
|
|
|
|
protected function f6() {}
|
|
|
|
c1 => { f2() }
|
|
c2 => {
|
|
c1();
|
|
// ^error{Call of impure callback 'c1'}
|
|
}
|
|
|
|
|
|
property <int> p1: f2();
|
|
property <int> p2: {
|
|
p1 = 42;
|
|
// ^error{Assignment in a pure context}
|
|
42
|
|
};
|
|
property <int> p3: {
|
|
pw.show();
|
|
// ^error{Call of impure function}
|
|
fs.focus();
|
|
// ^error{Call of impure function}
|
|
f6();
|
|
// ^error{Call of impure function 'f6'}
|
|
42
|
|
};
|
|
|
|
pw := PopupWindow {}
|
|
fs := FocusScope {}
|
|
|
|
callback model() -> [int];
|
|
for xx in model() : Rectangle {
|
|
// ^error{Call of impure callback 'model'}
|
|
property <int> abc: xx;
|
|
}
|
|
}
|
|
|
|
|
|
export component Bar {
|
|
pure callback xc1 <=> f.c1;
|
|
// ^error{Purity of callbacks 'xc1' and 'f.c1' doesn't match}
|
|
callback xc2 <=> f.c2;
|
|
// ^error{Purity of callbacks 'xc2' and 'f.c2' doesn't match}
|
|
f := Foo {
|
|
c2 => {
|
|
self.c1();
|
|
// ^error{Call of impure callback 'c1'}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export Foo_Legacy := Rectangle {
|
|
// ^warning{':=' to declare a component is deprecated. The new syntax declare components with 'component MyComponent {'. Read the documentation for more info}
|
|
property <int> prop;
|
|
callback c1;
|
|
pure callback c2;
|
|
|
|
function f1() {
|
|
prop = 1;
|
|
}
|
|
function f2() -> int { 42 }
|
|
|
|
pure function f3() {
|
|
f2();
|
|
f1();
|
|
// ^warning{Call of impure function 'f1'}
|
|
|
|
prop /= 5;
|
|
// ^warning{Assignment in a pure context}
|
|
}
|
|
public function f4() {}
|
|
|
|
|
|
pure function f5() {
|
|
f1();
|
|
// ^warning{Call of impure function 'f1'}
|
|
f2(); // ok, private function auto-detected as pure
|
|
f3();
|
|
f4();
|
|
// ^warning{Call of impure function 'f4'}
|
|
c1();
|
|
// ^warning{Call of impure callback 'c1'}
|
|
c2();
|
|
}
|
|
|
|
c1 => { f2() }
|
|
c2 => {
|
|
c1();
|
|
// ^warning{Call of impure callback 'c1'}
|
|
}
|
|
|
|
|
|
property <int> p1: f2();
|
|
property <int> p2: {
|
|
p1 = 42;
|
|
// ^warning{Assignment in a pure context}
|
|
42
|
|
};
|
|
property <int> p3: {
|
|
pw.show();
|
|
// ^warning{Call of impure function}
|
|
fs.focus();
|
|
// ^warning{Call of impure function}
|
|
42
|
|
};
|
|
|
|
pw := PopupWindow {}
|
|
fs := FocusScope {}
|
|
}
|
|
|
|
|
|
export Bar_Legacy := Rectangle {
|
|
// ^warning{':=' to declare a component is deprecated. The new syntax declare components with 'component MyComponent {'. Read the documentation for more info}
|
|
pure callback xc1 <=> f.c1;
|
|
// ^error{Purity of callbacks 'xc1' and 'f.c1' doesn't match}
|
|
callback xc2 <=> f.c2;
|
|
// ^error{Purity of callbacks 'xc2' and 'f.c2' doesn't match}
|
|
f := Foo {
|
|
c2 => {
|
|
self.c1();
|
|
// ^warning{Call of impure callback 'c1'}
|
|
}
|
|
}
|
|
}
|