mirror of
				https://github.com/slint-ui/slint.git
				synced 2025-10-31 20:08:35 +00:00 
			
		
		
		
	 12393e21bd
			
		
	
	
		12393e21bd
		
			
		
	
	
	
	
		
			
			* 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
		
	
			
		
			
				
	
	
		
			67 lines
		
	
	
	
		
			3.4 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			67 lines
		
	
	
	
		
			3.4 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
 | |
| 
 | |
| global Glob := {
 | |
| //          ^warning{':=' to declare a global is deprecated. Remove the ':='}
 | |
|     property <physical_length> len: 45px * 5;
 | |
| //                                  ^error{Cannot convert between logical and physical length in a global component, because the scale factor is not known}
 | |
|     property <length> logic_len: 45phx * 5;
 | |
| //                               ^error{Cannot convert between logical and physical length in a global component, because the scale factor is not known}
 | |
|     property <float> ratio: allowed / 1phx;
 | |
| //                          ^error{Cannot convert between logical and physical length in a global component, because the scale factor is not known}
 | |
|     property <length> converted_rem: 2rem;
 | |
| //                                   ^error{Cannot convert between rem and logical length in a global component, because the default font size is not known}
 | |
|     property <float> should_work: 45px / 8px + (4rem / 2rem);
 | |
|     property <length> allowed: 45px * 5;
 | |
|     property <relative-font-size> rem_allowed: 42rem;
 | |
| }
 | |
| 
 | |
| export X := Rectangle {
 | |
| //       ^warning{':=' to declare a component is deprecated. The new syntax declare components with 'component MyComponent {'. Read the documentation for more info}
 | |
| 
 | |
|     t := Text {
 | |
|         x: "hello";
 | |
| //         ^error{Cannot convert string to length}
 | |
|         text: 45;
 | |
|     }
 | |
| 
 | |
|     Text {
 | |
|         x: t.text;
 | |
| //         ^error{Cannot convert string to length}
 | |
|         y: 42;
 | |
| //         ^error{Cannot convert float to length. Use an unit, or multiply by 1px to convert explicitly}
 | |
|         text: x;
 | |
| //            ^error{Cannot convert length to string. Divide by 1px to convert to a plain number}
 | |
|         property<int> foo: y;
 | |
| //                         ^error{Cannot convert length to int. Divide by 1px to convert to a plain number}
 | |
|         property<duration> bar: foo;
 | |
| //                              ^error{Cannot convert int to duration. Use an unit, or multiply by 1ms to convert explicitly}
 | |
|     }
 | |
| 
 | |
|     Rectangle {
 | |
|         background: "blue";
 | |
| //                  ^error{Cannot convert string to brush}
 | |
|         property<length> no_matching_parent: 50%;
 | |
| //                                           ^error{Automatic conversion from percentage to length is only possible for the following properties: width, height, preferred-width, preferred-height}
 | |
|     }
 | |
| 
 | |
|     property <{a: string, b: int}> object1: { a: "123", typo: 42};
 | |
| //                                          ^error{Cannot convert { a: string,typo: float,} to { a: string,b: int,}}
 | |
| 
 | |
|     property <[{a: [int]}]> ccc: [{a: []}, {}, {a: ["123"]}, {a: [123]}]; //  (FIXME: error location)  (FIXME: duplicated)
 | |
| //                               ^error{Cannot convert string to int}
 | |
| //                               ^^error{Cannot convert string to int}
 | |
| 
 | |
|     property <int> arr1: [];
 | |
| //                       ^error{Cannot convert [void] to int}
 | |
| 
 | |
|     property <{a: int}> arr2: {a: []};
 | |
| //                            ^error{Cannot convert [void] to int}
 | |
| 
 | |
|     property <int> arr3: false ? [] : 45;  //(FIXME: error not ideal)
 | |
| //                       ^error{Cannot convert void to int}
 | |
| //                                    ^^error{Cannot convert float to [void]}
 | |
| 
 | |
|     property <int> to-float: "foobar".to-float;
 | |
| //                                    ^error{Member function must be called. Did you forgot the '()'?}
 | |
| }
 |