refactor of testing code
This commit is contained in:
parent
2995f6e48b
commit
ffa987e00a
119
src/lib.rs
119
src/lib.rs
@ -108,15 +108,15 @@ impl Sway {
|
||||
let n = self.stream.read(&mut buffer)?;
|
||||
|
||||
match serde_json::from_slice::<T>(&buffer[14..n]) {
|
||||
Ok(result) => return Ok(result),
|
||||
Err(e) => return Err(e.into()),
|
||||
Ok(result) => Ok(result),
|
||||
Err(e) => Err(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_events(&mut self, events: Vec<&str>) -> Result<String> {
|
||||
match serde_json::to_string(&events) {
|
||||
Ok(json) => Ok(json),
|
||||
Err(e) => return Err(e.into()),
|
||||
Err(e) => Err(e.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -136,50 +136,31 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn run_command() {
|
||||
match sway_ipc().run_command("reload") {
|
||||
Ok(response) => assert_eq!(response.into_iter().nth(0).unwrap().success, true),
|
||||
Err(e) => panic!("{}", e.to_string()),
|
||||
}
|
||||
assert_eq!(sway_ipc().run_command("reload").unwrap()[0].success, true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_workspaces() {
|
||||
match sway_ipc().get_workspaces() {
|
||||
Ok(response) => {
|
||||
for workspace in response {
|
||||
assert_eq!(workspace._type, "workspace");
|
||||
}
|
||||
},
|
||||
Err(e) => panic!("{}", e.to_string()),
|
||||
for workspace in sway_ipc().get_workspaces().unwrap() {
|
||||
assert_eq!(workspace._type, "workspace");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subscribe() {
|
||||
match sway_ipc().subscribe(vec!(EVENT_WORKSPACE, EVENT_MODE)) {
|
||||
Ok(response) => assert_eq!(response.success, true),
|
||||
Err(e) => panic!("{}", e.to_string()),
|
||||
}
|
||||
assert_eq!(sway_ipc().subscribe(vec!(EVENT_WORKSPACE, EVENT_MODE)).unwrap().success, true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_outputs() {
|
||||
match sway_ipc().get_outputs() {
|
||||
Ok(response) => {
|
||||
for output in response {
|
||||
assert_eq!(output._type, "output");
|
||||
}
|
||||
},
|
||||
Err(e) => panic!("{}", e.to_string()),
|
||||
for output in sway_ipc().get_outputs().unwrap() {
|
||||
assert_eq!(output._type, "output");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_tree() {
|
||||
match sway_ipc().get_tree() {
|
||||
Ok(response) => assert_eq!(response.id, 1),
|
||||
Err(e) => panic!("{}", e.to_string()),
|
||||
}
|
||||
assert_eq!(sway_ipc().get_tree().unwrap().id, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -187,106 +168,68 @@ mod tests {
|
||||
let mut sway = sway_ipc();
|
||||
sway.run_command("unmark").unwrap();
|
||||
sway.run_command("mark test").unwrap();
|
||||
match sway.get_marks() {
|
||||
Ok(response) => assert_eq!(response.into_iter().nth(0).unwrap(), "test"),
|
||||
Err(e) => panic!("{}", e.to_string()),
|
||||
}
|
||||
assert_eq!(sway.get_marks().unwrap()[0], "test");
|
||||
sway.run_command("unmark").unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_bar_config() {
|
||||
match sway_ipc().get_bar_config("bar-0") {
|
||||
Ok(response) => assert_eq!(response.id, "bar-0"),
|
||||
Err(e) => panic!("{}", e.to_string())
|
||||
}
|
||||
assert_eq!(sway_ipc().get_bar_config("bar-0").unwrap().id, "bar-0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_version() {
|
||||
match sway_ipc().get_version() {
|
||||
Ok(response) => assert_eq!(response.major, 1),
|
||||
Err(e) => panic!("{}", e.to_string()),
|
||||
}
|
||||
assert_eq!(sway_ipc().get_version().unwrap().major, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_binding_modes() {
|
||||
match sway_ipc().get_binding_modes() {
|
||||
Ok(response) => {
|
||||
assert_eq!(response.into_iter().nth(0).unwrap(), "default")
|
||||
},
|
||||
Err(e) => panic!("{}", e.to_string()),
|
||||
}
|
||||
assert_eq!(sway_ipc().get_binding_modes().unwrap()[0], "default");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_config() {
|
||||
match sway_ipc().get_config() {
|
||||
Ok(_) => {},
|
||||
Err(e) => panic!("{}", e.to_string())
|
||||
}
|
||||
sway_ipc().get_config().unwrap().config;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_tick() {
|
||||
match sway_ipc().send_tick("") {
|
||||
Ok(response) => assert_eq!(response.success, true),
|
||||
Err(e) => panic!("{}", e.to_string()),
|
||||
}
|
||||
assert_eq!(sway_ipc().send_tick("").unwrap().success, true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sync() {
|
||||
match sway_ipc().sync() {
|
||||
Ok(response) => assert_eq!(response.success, false),
|
||||
Err(e) => panic!("{}", e.to_string()),
|
||||
}
|
||||
assert_eq!(sway_ipc().sync().unwrap().success, false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_binding_state() {
|
||||
match sway_ipc().get_binding_state() {
|
||||
Ok(response) => assert_eq!(response.name, "default"),
|
||||
Err(e) => panic!("{}", e.to_string()),
|
||||
}
|
||||
assert_eq!(sway_ipc().get_binding_state().unwrap().name, "default");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_inputs() {
|
||||
match sway_ipc().get_inputs() {
|
||||
Ok(response) => {
|
||||
for input in response {
|
||||
if !(input._type.eq("keyboard") | input._type.eq("pointer")) {
|
||||
panic!("invalid input: {}", input._type);
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => panic!("{}", e.to_string()),
|
||||
for input in sway_ipc().get_inputs().unwrap() {
|
||||
if !(input._type.eq("keyboard") | input._type.eq("pointer")) {
|
||||
panic!("invalid input: {}", input._type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_seats() {
|
||||
match sway_ipc().get_seats() {
|
||||
Ok(response) => assert_eq!(response.into_iter().nth(0).unwrap().name, "seat0"),
|
||||
Err(e) => panic!("{}", e.to_string())
|
||||
}
|
||||
assert_eq!(sway_ipc().get_seats().unwrap()[0].name, "seat0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn construct_packet() {
|
||||
match I3msg::new("reload", IPC_RUN_COMMAND).construct_packet() {
|
||||
Ok(buffer) => {
|
||||
assert_eq!(buffer, vec![
|
||||
0x69, 0x33, 0x2D, 0x69,
|
||||
0x70, 0x63, 0x06, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x72, 0x65,
|
||||
0x6C, 0x6F, 0x61, 0x64,
|
||||
]);
|
||||
},
|
||||
Err(e) => panic!("{}", e.to_string()),
|
||||
}
|
||||
let packet = I3msg::new("reload", IPC_RUN_COMMAND).construct_packet().unwrap();
|
||||
assert_eq!(packet, vec![
|
||||
0x69, 0x33, 0x2D, 0x69,
|
||||
0x70, 0x63, 0x06, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x72, 0x65,
|
||||
0x6C, 0x6F, 0x61, 0x64,
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user