slint/internal/compiler/tests/syntax/expressions/math-macro.slint
Olivier Goffart 12393e21bd
syntax_tests: allow to update tests, and don't use a regexp (#8589)
* 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
2025-06-02 16:47:33 +02:00

61 lines
No EOL
2.5 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 <float> m1: mod(4);
// ^error{Needs 2 arguments}
property <float> m2: mod(4, 5, 5);
// ^error{Needs 2 arguments}
property <float> m3: mod("455", "465");
// ^error{Cannot convert string to float}
// ^^error{Cannot convert string to float}
property <float> m4: mod(455, "465");
// ^error{Cannot convert string to float}
property <length> m5: mod(45px, 4);
// ^error{Cannot convert float to length. Use an unit, or multiply by 1px to convert explicitly}
property <length> m6: mod(45px, 4ms);
// ^error{Cannot convert duration to length}
property <duration> m7: mod(5, 4ms);
// ^error{Cannot convert float to duration. Use an unit, or multiply by 1ms to convert explicitly}
property <duration> m8: (5).mod(4ms);
// ^error{Cannot convert float to duration. Use an unit, or multiply by 1ms to convert explicitly}
property <duration> m9: 5ms.mod(4);
// ^error{Cannot convert float to duration. Use an unit, or multiply by 1ms to convert explicitly}
property <float> a1: abs();
// ^error{Needs 1 argument}
property <float> a2: abs(4, 5, 5);
// ^error{Needs 1 argument}
property <float> a3: abs(1, 2);
// ^error{Needs 1 argument}
property <float> a4: abs("465");
// ^error{Cannot convert string to float}
property <string> a5: abs(45px);
// ^error{Cannot convert length to string. Divide by 1px to convert to a plain number}
property <string> a6: abs;
// ^error{Builtin function must be called. Did you forgot the '()'?}
property <string> a7: (-21).abs;
// ^error{Member function must be called. Did you forgot the '()'?}
property <float> sq1: 1.0.sqrt(1);
// ^error{The callback or function expects 0 arguments, but 1 are provided}
property <float> sq2: 1.0.sqrt;
// ^error{Member function must be called. Did you forgot the '()'?}
}