Skip to content

Commit 0ccb4c4

Browse files
authored
row_labels.is_null() actually refers to a method checking for a null pointer (#710)
* `row_labels.is_null()` actually refers to a method checking for a null pointer. * Add a regression test * Implement `is_null` for RObject
1 parent 3dddbb9 commit 0ccb4c4

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

crates/ark/tests/data_explorer.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,12 @@ fn test_row_names_matrix() {
18771877
}),
18781878
format_options: default_format_options(),
18791879
});
1880+
assert_match!(socket_rpc(&socket, DataExplorerBackendRequest::GetState),
1881+
DataExplorerBackendReply::GetStateReply(state) => {
1882+
assert_eq!(state.has_row_labels, true)
1883+
}
1884+
);
1885+
18801886
assert_match!(socket_rpc(&socket, req),
18811887
DataExplorerBackendReply::GetRowLabelsReply(row_labels) => {
18821888
let labels = row_labels.row_labels;
@@ -1885,4 +1891,14 @@ fn test_row_names_matrix() {
18851891
assert_eq!(labels[0][2], "Merc 240D");
18861892
}
18871893
);
1894+
1895+
// Convert mtcars to a matrix
1896+
let socket =
1897+
open_data_explorer_from_expression("matrix(0, ncol =10, nrow = 10)", Some("zero_matrix"))
1898+
.unwrap();
1899+
assert_match!(socket_rpc(&socket, DataExplorerBackendRequest::GetState),
1900+
DataExplorerBackendReply::GetStateReply(state) => {
1901+
assert_eq!(state.has_row_labels, false)
1902+
}
1903+
);
18881904
}

crates/harp/src/object.rs

+16
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ impl RObject {
352352
r_is_object(self.sexp)
353353
}
354354

355+
pub fn is_null(&self) -> bool {
356+
r_is_null(self.sexp)
357+
}
358+
355359
pub fn size(&self) -> harp::Result<usize> {
356360
r_size(self.sexp)
357361
}
@@ -1154,6 +1158,7 @@ mod tests {
11541158
use stdext::assert_match;
11551159

11561160
use super::*;
1161+
use crate::parse_eval_global;
11571162
use crate::r_char;
11581163

11591164
#[test]
@@ -1729,4 +1734,15 @@ mod tests {
17291734
assert_eq!(items_in, items_out);
17301735
})
17311736
}
1737+
1738+
#[test]
1739+
fn test_is_null() {
1740+
crate::r_task(|| {
1741+
let x = parse_eval_global("NULL").unwrap();
1742+
assert!(x.is_null());
1743+
1744+
let x = parse_eval_global("1").unwrap();
1745+
assert!(!x.is_null());
1746+
})
1747+
}
17321748
}

0 commit comments

Comments
 (0)