forked from 1b-agent/opencadstudio-upstream
style: apply cargo fmt across workspace
This commit is contained in:
1 parent
85710e5454
commit
9cf9ff2c5c
531 files changed
+57740
-33906
No files matched your search
@@ -53,7 +53,10 @@ pub enum PluginToHostV4 {
|
||||
tab_id: Option<u64>,
|
||||
payload: PluginRequest,
|
||||
},
|
||||
Response { id: u64, payload: HostResponse },
|
||||
Response {
|
||||
id: u64,
|
||||
payload: HostResponse,
|
||||
},
|
||||
Notification(NotificationEnvelope<PluginNotification>),
|
||||
}
|
||||
|
||||
@@ -95,11 +98,17 @@ mod tests {
|
||||
let bytes = bincode::serialize(¬ification).unwrap();
|
||||
let decoded: HostNotification = bincode::deserialize(&bytes).unwrap();
|
||||
assert_eq!(decoded, notification);
|
||||
let stopped = HostNotification::CommandStateChanged { tab_id: 42, command: None };
|
||||
let stopped = HostNotification::CommandStateChanged {
|
||||
tab_id: 42,
|
||||
command: None,
|
||||
};
|
||||
let bytes = bincode::serialize(&stopped).unwrap();
|
||||
let decoded: HostNotification = bincode::deserialize(&bytes).unwrap();
|
||||
assert_eq!(decoded, stopped);
|
||||
let changed = HostNotification::DrawingChanged { tab_id: 42, epoch: 7 };
|
||||
let changed = HostNotification::DrawingChanged {
|
||||
tab_id: 42,
|
||||
epoch: 7,
|
||||
};
|
||||
let bytes = bincode::serialize(&changed).unwrap();
|
||||
let decoded: HostNotification = bincode::deserialize(&bytes).unwrap();
|
||||
assert_eq!(decoded, changed);
|
||||
@@ -109,19 +118,33 @@ mod tests {
|
||||
fn command_request_and_outcome_roundtrip() {
|
||||
use crate::host::{CommandOutcome, CommandRequest};
|
||||
for request in [
|
||||
CommandRequest::Run { line: "LINE 0,0 1,1".into() },
|
||||
CommandRequest::Start { name: "OFFSET".into() },
|
||||
CommandRequest::Point { point: [1.0, 2.0, 3.0] },
|
||||
CommandRequest::Run {
|
||||
line: "LINE 0,0 1,1".into(),
|
||||
},
|
||||
CommandRequest::Start {
|
||||
name: "OFFSET".into(),
|
||||
},
|
||||
CommandRequest::Point {
|
||||
point: [1.0, 2.0, 3.0],
|
||||
},
|
||||
CommandRequest::Text { text: "2".into() },
|
||||
CommandRequest::Token { text: "R".into() },
|
||||
CommandRequest::Entity { handle: codec::Handle::new(9), point: [0.0; 3] },
|
||||
CommandRequest::Entity {
|
||||
handle: codec::Handle::new(9),
|
||||
point: [0.0; 3],
|
||||
},
|
||||
CommandRequest::Selection,
|
||||
CommandRequest::Enter,
|
||||
CommandRequest::Cancel,
|
||||
] {
|
||||
let bytes = bincode::serialize(&PluginRequest::RunCommand { request: request.clone() }).unwrap();
|
||||
assert!(matches!(bincode::deserialize::<PluginRequest>(&bytes).unwrap(),
|
||||
PluginRequest::RunCommand { request: decoded } if decoded == request));
|
||||
let bytes = bincode::serialize(&PluginRequest::RunCommand {
|
||||
request: request.clone(),
|
||||
})
|
||||
.unwrap();
|
||||
assert!(
|
||||
matches!(bincode::deserialize::<PluginRequest>(&bytes).unwrap(),
|
||||
PluginRequest::RunCommand { request: decoded } if decoded == request)
|
||||
);
|
||||
}
|
||||
let outcome = CommandOutcome {
|
||||
status: "waiting_input".into(),
|
||||
@@ -137,8 +160,10 @@ mod tests {
|
||||
};
|
||||
for result in [Ok(outcome), Err("refused".to_owned())] {
|
||||
let bytes = bincode::serialize(&PluginResponse::CommandResult(result.clone())).unwrap();
|
||||
assert!(matches!(bincode::deserialize::<PluginResponse>(&bytes).unwrap(),
|
||||
PluginResponse::CommandResult(decoded) if decoded == result));
|
||||
assert!(
|
||||
matches!(bincode::deserialize::<PluginResponse>(&bytes).unwrap(),
|
||||
PluginResponse::CommandResult(decoded) if decoded == result)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,19 +180,60 @@ mod tests {
|
||||
..Default::default()
|
||||
},
|
||||
},
|
||||
TableOperation::LayerModify { config: LayerConfig { name: "Walls".into(), off: Some(true), ..Default::default() } },
|
||||
TableOperation::LayerRename { from: "A".into(), to: "B".into() },
|
||||
TableOperation::LayerDelete { name: "A".into(), erase_objects: true },
|
||||
TableOperation::LayerModify {
|
||||
config: LayerConfig {
|
||||
name: "Walls".into(),
|
||||
off: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
},
|
||||
TableOperation::LayerRename {
|
||||
from: "A".into(),
|
||||
to: "B".into(),
|
||||
},
|
||||
TableOperation::LayerDelete {
|
||||
name: "A".into(),
|
||||
erase_objects: true,
|
||||
},
|
||||
TableOperation::LayerSetCurrent { name: "A".into() },
|
||||
TableOperation::TextStyleCreate {
|
||||
config: crate::host::TextStyleConfig { name: "T".into(), height: Some(2.5), oblique_angle: Some(0.2), backward: Some(true), ..Default::default() },
|
||||
config: crate::host::TextStyleConfig {
|
||||
name: "T".into(),
|
||||
height: Some(2.5),
|
||||
oblique_angle: Some(0.2),
|
||||
backward: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
},
|
||||
TableOperation::TextStyleModify {
|
||||
config: crate::host::TextStyleConfig {
|
||||
name: "T".into(),
|
||||
font_file: Some("romans".into()),
|
||||
..Default::default()
|
||||
},
|
||||
},
|
||||
TableOperation::DimStyleCreate {
|
||||
name: "D".into(),
|
||||
copy_from: Some("Standard".into()),
|
||||
properties: "{\"dimscale\":2}".into(),
|
||||
},
|
||||
TableOperation::DimStyleModify {
|
||||
name: "D".into(),
|
||||
properties: "{}".into(),
|
||||
},
|
||||
TableOperation::StyleRename {
|
||||
kind: crate::host::TableStyleKind::Text,
|
||||
from: "A".into(),
|
||||
to: "B".into(),
|
||||
},
|
||||
TableOperation::StyleDelete {
|
||||
kind: crate::host::TableStyleKind::Dim,
|
||||
name: "A".into(),
|
||||
},
|
||||
TableOperation::StyleSetCurrent {
|
||||
kind: crate::host::TableStyleKind::Dim,
|
||||
name: "A".into(),
|
||||
},
|
||||
TableOperation::TextStyleModify { config: crate::host::TextStyleConfig { name: "T".into(), font_file: Some("romans".into()), ..Default::default() } },
|
||||
TableOperation::DimStyleCreate { name: "D".into(), copy_from: Some("Standard".into()), properties: "{\"dimscale\":2}".into() },
|
||||
TableOperation::DimStyleModify { name: "D".into(), properties: "{}".into() },
|
||||
TableOperation::StyleRename { kind: crate::host::TableStyleKind::Text, from: "A".into(), to: "B".into() },
|
||||
TableOperation::StyleDelete { kind: crate::host::TableStyleKind::Dim, name: "A".into() },
|
||||
TableOperation::StyleSetCurrent { kind: crate::host::TableStyleKind::Dim, name: "A".into() },
|
||||
TableOperation::BlockCreate {
|
||||
name: "B".into(),
|
||||
entities: vec![codec::Handle::new(4), codec::Handle::new(5)],
|
||||
@@ -175,31 +241,67 @@ mod tests {
|
||||
erase_originals: true,
|
||||
description: Some("d".into()),
|
||||
},
|
||||
TableOperation::BlockModify { name: "B".into(), description: None, explodable: Some(false), scale_uniformly: Some(true) },
|
||||
TableOperation::BlockRename { from: "B".into(), to: "C".into() },
|
||||
TableOperation::BlockModify {
|
||||
name: "B".into(),
|
||||
description: None,
|
||||
explodable: Some(false),
|
||||
scale_uniformly: Some(true),
|
||||
},
|
||||
TableOperation::BlockRename {
|
||||
from: "B".into(),
|
||||
to: "C".into(),
|
||||
},
|
||||
TableOperation::BlockDelete { name: "C".into() },
|
||||
TableOperation::BlockEntityAdd {
|
||||
block: "C".into(),
|
||||
entity: codec::EntityType::Line(codec::entities::Line::new()),
|
||||
},
|
||||
TableOperation::LinetypeCreate { name: "L".into(), description: "d".into(), pattern: vec![1.0, -1.0] },
|
||||
TableOperation::LinetypeModify { name: "L".into(), description: None, pattern: Some(vec![2.0, -2.0]) },
|
||||
TableOperation::LinetypeRename { from: "L".into(), to: "M".into() },
|
||||
TableOperation::LinetypeCreate {
|
||||
name: "L".into(),
|
||||
description: "d".into(),
|
||||
pattern: vec![1.0, -1.0],
|
||||
},
|
||||
TableOperation::LinetypeModify {
|
||||
name: "L".into(),
|
||||
description: None,
|
||||
pattern: Some(vec![2.0, -2.0]),
|
||||
},
|
||||
TableOperation::LinetypeRename {
|
||||
from: "L".into(),
|
||||
to: "M".into(),
|
||||
},
|
||||
TableOperation::LinetypeDelete { name: "M".into() },
|
||||
TableOperation::LayoutCreate { name: "S".into() },
|
||||
TableOperation::LayoutRename { from: "S".into(), to: "T".into() },
|
||||
TableOperation::LayoutRename {
|
||||
from: "S".into(),
|
||||
to: "T".into(),
|
||||
},
|
||||
TableOperation::LayoutDelete { name: "T".into() },
|
||||
TableOperation::LayoutSetCurrent { name: "Model".into() },
|
||||
TableOperation::LayoutSetPage { name: "S".into(), paper_size: Some([420.0, 297.0]), rotation: Some(90), scale: Some([1.0, 50.0]) },
|
||||
TableOperation::LayoutSetCurrent {
|
||||
name: "Model".into(),
|
||||
},
|
||||
TableOperation::LayoutSetPage {
|
||||
name: "S".into(),
|
||||
paper_size: Some([420.0, 297.0]),
|
||||
rotation: Some(90),
|
||||
scale: Some([1.0, 50.0]),
|
||||
},
|
||||
] {
|
||||
let bytes = bincode::serialize(&PluginRequest::TableOperation { operation: operation.clone() }).unwrap();
|
||||
assert!(matches!(bincode::deserialize::<PluginRequest>(&bytes).unwrap(),
|
||||
PluginRequest::TableOperation { operation: decoded } if decoded == operation));
|
||||
let bytes = bincode::serialize(&PluginRequest::TableOperation {
|
||||
operation: operation.clone(),
|
||||
})
|
||||
.unwrap();
|
||||
assert!(
|
||||
matches!(bincode::deserialize::<PluginRequest>(&bytes).unwrap(),
|
||||
PluginRequest::TableOperation { operation: decoded } if decoded == operation)
|
||||
);
|
||||
}
|
||||
for result in [Ok(codec::Handle::new(9)), Err("refused".to_owned())] {
|
||||
let bytes = bincode::serialize(&PluginResponse::TableResult(result.clone())).unwrap();
|
||||
assert!(matches!(bincode::deserialize::<PluginResponse>(&bytes).unwrap(),
|
||||
PluginResponse::TableResult(decoded) if decoded == result));
|
||||
assert!(
|
||||
matches!(bincode::deserialize::<PluginResponse>(&bytes).unwrap(),
|
||||
PluginResponse::TableResult(decoded) if decoded == result)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,12 +310,29 @@ mod tests {
|
||||
use crate::host::{SolidOperation, SolidPrimitive};
|
||||
for operation in [
|
||||
SolidOperation::Create {
|
||||
primitive: SolidPrimitive::Pyramid { center: [1.0, 2.0, 3.0], radius: 4.0, height: 5.0, sides: 6 },
|
||||
primitive: SolidPrimitive::Pyramid {
|
||||
center: [1.0, 2.0, 3.0],
|
||||
radius: 4.0,
|
||||
height: 5.0,
|
||||
sides: 6,
|
||||
},
|
||||
layer: Some("SOLIDS".into()),
|
||||
},
|
||||
SolidOperation::Transform { handle: codec::Handle::new(7), matrix: [1.0; 16] },
|
||||
SolidOperation::RegionFromProfile { source: codec::Handle::new(3), layer: None, delete_source: true },
|
||||
SolidOperation::EmbedPicture { path: "p.png".into(), origin: [0.0; 3], width: 5.0, layer: None },
|
||||
SolidOperation::Transform {
|
||||
handle: codec::Handle::new(7),
|
||||
matrix: [1.0; 16],
|
||||
},
|
||||
SolidOperation::RegionFromProfile {
|
||||
source: codec::Handle::new(3),
|
||||
layer: None,
|
||||
delete_source: true,
|
||||
},
|
||||
SolidOperation::EmbedPicture {
|
||||
path: "p.png".into(),
|
||||
origin: [0.0; 3],
|
||||
width: 5.0,
|
||||
layer: None,
|
||||
},
|
||||
SolidOperation::Boolean {
|
||||
first: codec::Handle::new(1),
|
||||
second: codec::Handle::new(2),
|
||||
@@ -221,30 +340,52 @@ mod tests {
|
||||
layer: None,
|
||||
keep_operands: false,
|
||||
},
|
||||
SolidOperation::SurfaceFromProfile { source: codec::Handle::new(4), layer: Some("S".into()), delete_source: false },
|
||||
SolidOperation::Extrude { source: codec::Handle::new(5), direction: [0.0, 0.0, 2.0], layer: None, delete_source: true },
|
||||
SolidOperation::SurfaceFromProfile {
|
||||
source: codec::Handle::new(4),
|
||||
layer: Some("S".into()),
|
||||
delete_source: false,
|
||||
},
|
||||
SolidOperation::Extrude {
|
||||
source: codec::Handle::new(5),
|
||||
direction: [0.0, 0.0, 2.0],
|
||||
layer: None,
|
||||
delete_source: true,
|
||||
},
|
||||
] {
|
||||
let bytes = bincode::serialize(&PluginRequest::SolidOperation { operation: operation.clone() }).unwrap();
|
||||
assert!(matches!(bincode::deserialize::<PluginRequest>(&bytes).unwrap(),
|
||||
PluginRequest::SolidOperation { operation: decoded } if decoded == operation));
|
||||
let bytes = bincode::serialize(&PluginRequest::SolidOperation {
|
||||
operation: operation.clone(),
|
||||
})
|
||||
.unwrap();
|
||||
assert!(
|
||||
matches!(bincode::deserialize::<PluginRequest>(&bytes).unwrap(),
|
||||
PluginRequest::SolidOperation { operation: decoded } if decoded == operation)
|
||||
);
|
||||
}
|
||||
for result in [Ok(codec::Handle::new(9)), Err("refused".to_owned())] {
|
||||
let bytes = bincode::serialize(&PluginResponse::SolidResult(result.clone())).unwrap();
|
||||
assert!(matches!(bincode::deserialize::<PluginResponse>(&bytes).unwrap(),
|
||||
PluginResponse::SolidResult(decoded) if decoded == result));
|
||||
assert!(
|
||||
matches!(bincode::deserialize::<PluginResponse>(&bytes).unwrap(),
|
||||
PluginResponse::SolidResult(decoded) if decoded == result)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selection_request_and_response_roundtrip() {
|
||||
let request = PluginRequest::SetSelection { handles: vec![codec::Handle::new(9)] };
|
||||
let request = PluginRequest::SetSelection {
|
||||
handles: vec![codec::Handle::new(9)],
|
||||
};
|
||||
let bytes = bincode::serialize(&request).unwrap();
|
||||
assert!(matches!(bincode::deserialize::<PluginRequest>(&bytes).unwrap(),
|
||||
PluginRequest::SetSelection { handles } if handles == vec![codec::Handle::new(9)]));
|
||||
assert!(
|
||||
matches!(bincode::deserialize::<PluginRequest>(&bytes).unwrap(),
|
||||
PluginRequest::SetSelection { handles } if handles == vec![codec::Handle::new(9)])
|
||||
);
|
||||
let response = PluginResponse::Selection(vec![codec::Handle::new(9)]);
|
||||
let bytes = bincode::serialize(&response).unwrap();
|
||||
assert!(matches!(bincode::deserialize::<PluginResponse>(&bytes).unwrap(),
|
||||
PluginResponse::Selection(handles) if handles == vec![codec::Handle::new(9)]));
|
||||
assert!(
|
||||
matches!(bincode::deserialize::<PluginResponse>(&bytes).unwrap(),
|
||||
PluginResponse::Selection(handles) if handles == vec![codec::Handle::new(9)])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user