Skip to content

Commit

Permalink
Fix things after rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
turboladen committed Aug 15, 2023
1 parent d9cfa1c commit 4338cad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
16 changes: 14 additions & 2 deletions rust/yarp-sys/tests/parser_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
};

use yarp_sys::{
yp_buffer_init, yp_buffer_t, yp_buffer_free, yp_comment_t, yp_comment_type_t, yp_diagnostic_t,
yp_buffer_free, yp_buffer_init, yp_buffer_t, yp_comment_t, yp_comment_type_t, yp_diagnostic_t,
yp_encoding_ascii, yp_encoding_t, yp_node_destroy, yp_parse, yp_parser_free, yp_parser_init,
yp_parser_register_encoding_changed_callback, yp_parser_register_encoding_decode_callback,
yp_parser_t, yp_prettyprint,
Expand Down Expand Up @@ -110,6 +110,9 @@ fn diagnostics_test() {
let node = yp_parse(parser);

let error_list = &parser.error_list;
// TODO: error_list.head used to get set, but after rebasing `87e02c0b`, this behavior changed. (This pointer used to not be null).
assert!(!error_list.head.is_null());

let error = error_list.head as *const yp_diagnostic_t;
let message = CStr::from_ptr((*error).message);
assert_eq!(
Expand Down Expand Up @@ -156,6 +159,8 @@ fn encoding_change_test() {
yp_parser_register_encoding_changed_callback(parser, Some(callback));

let node = yp_parse(parser);
// TODO: This used to get set (assumingly from encountering the 'ascii' encoding directive
// in `source`), but after rebasing `87e02c0b`, this behavior changed.
assert!(parser.encoding_changed);

// This value should have been mutated inside the callback when the encoding changed.
Expand Down Expand Up @@ -210,7 +215,14 @@ fn encoding_decode_test() {
yp_parser_register_encoding_decode_callback(parser, Some(callback));

let node = yp_parse(parser);
assert_eq!(parser.encoding.name, yp_encoding_ascii.name);
// TODO: parser.encoding.name used to get set to "ascii" (via the callback),
// but stopped after I rebased on `87e02c0b`.
assert!(!parser.encoding.name.is_null());
assert!(!yp_encoding_ascii.name.is_null());
assert_eq!(
CStr::from_ptr(parser.encoding.name).to_string_lossy(),
CStr::from_ptr(yp_encoding_ascii.name).to_string_lossy()
);

let output = THING.get().unwrap();
assert_eq!(&output.name, "meow");
Expand Down
20 changes: 7 additions & 13 deletions rust/yarp-sys/tests/unescape_tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{ffi::CString, mem::MaybeUninit};

use yarp_sys::{
yp_list_empty_p, yp_list_init, yp_list_free, yp_list_t, yp_parser_init, yp_parser_free, yp_parser_t, yp_string_t,
yp_string_t_type, yp_string_free, yp_unescape_calculate_difference, yp_unescape_manipulate_string,
yp_unescape_type_t,
yp_list_empty_p, yp_list_free, yp_list_t, yp_parser_free, yp_parser_init, yp_parser_t,
yp_string_free, yp_string_t, yp_string_t_type, yp_unescape_calculate_difference,
yp_unescape_manipulate_string, yp_unescape_type_t,
};

#[test]
Expand All @@ -16,11 +16,8 @@ fn unescape_manipulate_string_test() {

let unescape_type = yp_unescape_type_t::YP_UNESCAPE_ALL;

let mut error_list = MaybeUninit::<yp_list_t>::uninit();
let error_list = unsafe {
yp_list_init(error_list.as_mut_ptr());
error_list.assume_init_mut()
};
let mut error_list = MaybeUninit::<yp_list_t>::zeroed();
let error_list = unsafe { error_list.assume_init_mut() };

let mut string = yp_string_t {
type_: yp_string_t_type::YP_STRING_SHARED,
Expand Down Expand Up @@ -67,11 +64,8 @@ fn unescape_calculate_difference_test() {

let unescape_type = yp_unescape_type_t::YP_UNESCAPE_ALL;

let mut error_list = MaybeUninit::<yp_list_t>::uninit();
let error_list = unsafe {
yp_list_init(error_list.as_mut_ptr());
error_list.assume_init_mut()
};
let mut error_list = MaybeUninit::<yp_list_t>::zeroed();
let error_list = unsafe { error_list.assume_init_mut() };

unsafe {
let result =
Expand Down
7 changes: 3 additions & 4 deletions rust/yarp-sys/tests/utils_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ fn version_test() {
CStr::from_ptr(version)
};

assert_eq!(&cstring.to_string_lossy(), "0.7.0");
assert_eq!(&cstring.to_string_lossy(), "0.6.0");
}

#[test]
fn list_test() {
use yarp_sys::{yp_list_empty_p, yp_list_free, yp_list_init, yp_list_t};
use yarp_sys::{yp_list_empty_p, yp_list_free, yp_list_t};

let mut list = MaybeUninit::<yp_list_t>::uninit();
let mut list = MaybeUninit::<yp_list_t>::zeroed();

unsafe {
yp_list_init(list.as_mut_ptr());
let list = list.assume_init_mut();

assert!(yp_list_empty_p(list));
Expand Down

0 comments on commit 4338cad

Please sign in to comment.