Add the derive proc macro
This commit is contained in:
31
simconnect-sdk-derive/tests/01-parse.rs
Normal file
31
simconnect-sdk-derive/tests/01-parse.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
#![allow(unused_variables, dead_code)]
|
||||
|
||||
use simconnect_sdk_derive::SimConnectObject;
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second")]
|
||||
struct GpsData1 {
|
||||
#[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
|
||||
pub lat: f64,
|
||||
#[simconnect(name = "PLANE LONGITUDE", unit = "degrees")]
|
||||
pub lon: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", condition = "none")]
|
||||
struct GpsData2 {
|
||||
#[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
|
||||
pub lat: f64,
|
||||
#[simconnect(name = "PLANE LONGITUDE", unit = "degrees")]
|
||||
pub lon: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "visual-frame", condition = "changed")]
|
||||
struct GpsData3 {
|
||||
#[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
|
||||
pub lat: f64,
|
||||
#[simconnect(name = "PLANE LONGITUDE", unit = "degrees")]
|
||||
pub lon: f64,
|
||||
}
|
||||
|
||||
fn main() {}
|
39
simconnect-sdk-derive/tests/02-struct-attr-errors.rs
Normal file
39
simconnect-sdk-derive/tests/02-struct-attr-errors.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
#![allow(unused_variables, dead_code)]
|
||||
use simconnect_sdk_derive::SimConnectObject;
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "visual-frame", condition = "changed")]
|
||||
struct GpsData1(f64);
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
struct GpsData2 {}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect]
|
||||
struct GpsData3 {}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect()]
|
||||
struct GpsData4 {}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", period = "second")]
|
||||
struct GpsData5 {}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(condition = "none", condition = "none")]
|
||||
struct GpsData6 {}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", condition = "none", test = "test")]
|
||||
struct GpsData7 {}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(periodX = "second", condition = "none")]
|
||||
struct GpsData8 {}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", conditionX = "none")]
|
||||
struct GpsData9 {}
|
||||
|
||||
fn main() {}
|
54
simconnect-sdk-derive/tests/02-struct-attr-errors.stderr
Normal file
54
simconnect-sdk-derive/tests/02-struct-attr-errors.stderr
Normal file
@@ -0,0 +1,54 @@
|
||||
error: Unsupported field type. Only named fields are supported.
|
||||
--> tests/02-struct-attr-errors.rs:5:1
|
||||
|
|
||||
5 | / #[simconnect(period = "visual-frame", condition = "changed")]
|
||||
6 | | struct GpsData1(f64);
|
||||
| |_____________________^
|
||||
|
||||
error: expected attribute `#[simconnect(period = "...", condition = "...")]`
|
||||
--> tests/02-struct-attr-errors.rs:9:1
|
||||
|
|
||||
9 | struct GpsData2 {}
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(period = "...", condition = "...")]`
|
||||
--> tests/02-struct-attr-errors.rs:12:3
|
||||
|
|
||||
12 | #[simconnect]
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(period = "...", condition = "...")]`
|
||||
--> tests/02-struct-attr-errors.rs:16:3
|
||||
|
|
||||
16 | #[simconnect()]
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(period = "...", condition = "...")]`
|
||||
--> tests/02-struct-attr-errors.rs:20:3
|
||||
|
|
||||
20 | #[simconnect(period = "second", period = "second")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(period = "...", condition = "...")]`
|
||||
--> tests/02-struct-attr-errors.rs:24:3
|
||||
|
|
||||
24 | #[simconnect(condition = "none", condition = "none")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(period = "...", condition = "...")]`
|
||||
--> tests/02-struct-attr-errors.rs:28:3
|
||||
|
|
||||
28 | #[simconnect(period = "second", condition = "none", test = "test")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(period = "...", condition = "...")]`
|
||||
--> tests/02-struct-attr-errors.rs:32:3
|
||||
|
|
||||
32 | #[simconnect(periodX = "second", condition = "none")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(period = "...", condition = "...")]`
|
||||
--> tests/02-struct-attr-errors.rs:36:3
|
||||
|
|
||||
36 | #[simconnect(period = "second", conditionX = "none")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
73
simconnect-sdk-derive/tests/03-field-attr-errors.rs
Normal file
73
simconnect-sdk-derive/tests/03-field-attr-errors.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
#![allow(unused_variables, dead_code)]
|
||||
use simconnect_sdk_derive::SimConnectObject;
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", condition = "none")]
|
||||
struct GpsData1 {
|
||||
pub lat: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", condition = "none")]
|
||||
struct GpsData2 {
|
||||
#[simconnect]
|
||||
pub lat: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", condition = "none")]
|
||||
struct GpsData3 {
|
||||
#[simconnect()]
|
||||
pub lat: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", condition = "none")]
|
||||
struct GpsData4 {
|
||||
#[simconnect(name = "PLANE LATITUDE")]
|
||||
pub lat: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", condition = "none")]
|
||||
struct GpsData5 {
|
||||
#[simconnect(unit = "degrees")]
|
||||
pub lat: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", condition = "none")]
|
||||
struct GpsData6 {
|
||||
#[simconnect(name = "PLANE LATITUDE", name = "PLANE LATITUDE")]
|
||||
pub lat: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", condition = "none")]
|
||||
struct GpsData7 {
|
||||
#[simconnect(unit = "degrees", unit = "degrees")]
|
||||
pub lat: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", condition = "none")]
|
||||
struct GpsData8 {
|
||||
#[simconnect(name = "PLANE LATITUDE", unit = "degrees", unit = "degrees")]
|
||||
pub lat: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", condition = "none")]
|
||||
struct GpsData9 {
|
||||
#[simconnect(nameX = "PLANE LATITUDE", unit = "degrees")]
|
||||
pub lat: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", condition = "none")]
|
||||
struct GpsData10 {
|
||||
#[simconnect(name = "PLANE LATITUDE", unitX = "degrees")]
|
||||
pub lat: f64,
|
||||
}
|
||||
|
||||
fn main() {}
|
59
simconnect-sdk-derive/tests/03-field-attr-errors.stderr
Normal file
59
simconnect-sdk-derive/tests/03-field-attr-errors.stderr
Normal file
@@ -0,0 +1,59 @@
|
||||
error: expected attribute `#[simconnect(name = "...", unit = "...")]`
|
||||
--> tests/03-field-attr-errors.rs:7:5
|
||||
|
|
||||
7 | pub lat: f64,
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(name = "...", unit = "...")]`
|
||||
--> tests/03-field-attr-errors.rs:13:7
|
||||
|
|
||||
13 | #[simconnect]
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(name = "...", unit = "...")]`
|
||||
--> tests/03-field-attr-errors.rs:20:7
|
||||
|
|
||||
20 | #[simconnect()]
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(name = "...", unit = "...")]`
|
||||
--> tests/03-field-attr-errors.rs:27:7
|
||||
|
|
||||
27 | #[simconnect(name = "PLANE LATITUDE")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(name = "...", unit = "...")]`
|
||||
--> tests/03-field-attr-errors.rs:34:7
|
||||
|
|
||||
34 | #[simconnect(unit = "degrees")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(name = "...", unit = "...")]`
|
||||
--> tests/03-field-attr-errors.rs:41:7
|
||||
|
|
||||
41 | #[simconnect(name = "PLANE LATITUDE", name = "PLANE LATITUDE")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(name = "...", unit = "...")]`
|
||||
--> tests/03-field-attr-errors.rs:48:7
|
||||
|
|
||||
48 | #[simconnect(unit = "degrees", unit = "degrees")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(name = "...", unit = "...")]`
|
||||
--> tests/03-field-attr-errors.rs:55:7
|
||||
|
|
||||
55 | #[simconnect(name = "PLANE LATITUDE", unit = "degrees", unit = "degrees")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(name = "...", unit = "...")]`
|
||||
--> tests/03-field-attr-errors.rs:62:7
|
||||
|
|
||||
62 | #[simconnect(nameX = "PLANE LATITUDE", unit = "degrees")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: expected attribute `#[simconnect(name = "...", unit = "...")]`
|
||||
--> tests/03-field-attr-errors.rs:69:7
|
||||
|
|
||||
69 | #[simconnect(name = "PLANE LATITUDE", unitX = "degrees")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
27
simconnect-sdk-derive/tests/04-invalid-values.rs
Normal file
27
simconnect-sdk-derive/tests/04-invalid-values.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
#![allow(unused_variables, dead_code)]
|
||||
use simconnect_sdk_derive::SimConnectObject;
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = 123, condition = "none")]
|
||||
struct GpsData1 {}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", condition = 123)]
|
||||
struct GpsData2 {}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "X")]
|
||||
struct GpsData3 {}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", condition = "X")]
|
||||
struct GpsData4 {}
|
||||
|
||||
#[derive(Debug, Clone, SimConnectObject)]
|
||||
#[simconnect(period = "second", condition = "none")]
|
||||
struct GpsData5 {
|
||||
#[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
|
||||
pub lat: String,
|
||||
}
|
||||
|
||||
fn main() {}
|
30
simconnect-sdk-derive/tests/04-invalid-values.stderr
Normal file
30
simconnect-sdk-derive/tests/04-invalid-values.stderr
Normal file
@@ -0,0 +1,30 @@
|
||||
error: expected string, found Int(LitInt { token: 123 })
|
||||
--> tests/04-invalid-values.rs:5:14
|
||||
|
|
||||
5 | #[simconnect(period = 123, condition = "none")]
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: expected string, found Int(LitInt { token: 123 })
|
||||
--> tests/04-invalid-values.rs:9:33
|
||||
|
|
||||
9 | #[simconnect(period = "second", condition = 123)]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: `period` must be one of ['once', 'visual-frame', 'sim-frame', 'second']
|
||||
--> tests/04-invalid-values.rs:13:14
|
||||
|
|
||||
13 | #[simconnect(period = "X")]
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: `condition` must be one of ['none', 'changed']
|
||||
--> tests/04-invalid-values.rs:17:33
|
||||
|
|
||||
17 | #[simconnect(period = "second", condition = "X")]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: Field type must be one of ['f64', 'bool']
|
||||
--> tests/04-invalid-values.rs:23:5
|
||||
|
|
||||
23 | / #[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
|
||||
24 | | pub lat: String,
|
||||
| |___________________^
|
8
simconnect-sdk-derive/tests/run.rs
Normal file
8
simconnect-sdk-derive/tests/run.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
#[test]
|
||||
fn tests() {
|
||||
let t = trybuild::TestCases::new();
|
||||
t.pass("tests/01-parse.rs");
|
||||
t.compile_fail("tests/02-struct-attr-errors.rs");
|
||||
t.compile_fail("tests/03-field-attr-errors.rs");
|
||||
t.compile_fail("tests/04-invalid-values.rs");
|
||||
}
|
Reference in New Issue
Block a user