Skip to content

Commit 4fe9531

Browse files
committed
WIP 75 - Silence compiler warning, move compat test suite file
Silence compiler warning: macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths rust-lang/rust#52234 By adding this to lib.rs: This is a warning for a future error in the compiler. It does not allow $crate to be used by this macro as_str_slice_test_case! if the macro is used inside the crate, and by other crates. One solution is just to require anyone who uses this macro to import the appropriate symbols, kind of like what you have to do with use `std::fmt::Write as _` before calling write! Also, move the compat test suite file to the top level parser_ng folder instead of being located in the sub-folder "as_str_slice_core". And rename "core.rs" to "as_str_slice_core.rs" since "core" is used else where in the code base to refer to the top-level "core" module.
1 parent 55d5d9e commit 4fe9531

File tree

18 files changed

+170
-151
lines changed

18 files changed

+170
-151
lines changed

todo.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,15 @@
245245
- [x] update `md_parser_syn_hi_impl.rs` to use this. provide a new `bool` flag that allows the new
246246
`_ng` parser active instead of the old one (keep them all in the code for now). there is 1
247247
function that is shared between the two, so move that to `_ng` for smart code block tests.
248-
- [ ] add a new test case in `parse_heading_ng()` test cases, and use the markdown constant from the
248+
- [x] add a new test case in `parse_heading_ng()` test cases, and use the markdown constant from the
249249
demo examples for the editor, which currently shows up in 2 places (consolidate them into
250250
one):
251251
- `get_real_world_content()` in
252252
`tui/src/tui/md_parser_ng/as_str_slice/compatibility_test_suite.rs`
253253
- `get_default_content()` in `tui/examples/tui_apps/ex_editor/state.rs`
254-
- [ ] make quality and compatibility improvments to `md_parse_ng` now that it is attached to the
255-
test examples. there is an extra new line at the bottom of the editor for some reason that
256-
does not show up with the legacy parser.
254+
- [x] make quality and compatibility improvments to `md_parse_ng` now that it is attached to the
255+
test examples. verify that extra line at the bottom of editor example shows up both for legacy
256+
and NG parser
257257
- [ ] use `cargo bench` in `compatibility_test_suite.rs` to compare the relative performance of both
258258
legacy and NG parsers
259259
- [ ] would it be possible to cache the AST returned by `parse_markdown_ng()`? is this a tree

tui/src/core/common/ring_buffer_heap.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
*/
1717

1818
//! A fixed-size ring buffer implementation using heap allocation. For stack allocated
19-
//! version, take a look at [super::RingBufferStack].
19+
//! version, take a look at [`super::RingBufferStack`].
2020
2121
use std::fmt::Debug;
2222

2323
use super::RingBuffer;
2424
use crate::{len, Index, Length};
2525

26-
#[derive(Clone, Debug, PartialEq)]
26+
#[derive(Clone, Debug, PartialEq, Eq)]
2727
pub struct RingBufferHeap<T, const N: usize> {
2828
internal_storage: Vec<Option<T>>,
2929
head: usize,
@@ -37,7 +37,7 @@ impl<T, const N: usize> Default for RingBufferHeap<T, N> {
3737

3838
impl<T, const N: usize> RingBufferHeap<T, N> {
3939
pub fn new() -> Self {
40-
RingBufferHeap {
40+
Self {
4141
internal_storage: Vec::with_capacity(N),
4242
head: 0,
4343
tail: 0,

tui/src/core/stack_alloc_types/sizes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ impl AsRef<str> for InlineStringCow<'_> {
6666
impl Display for InlineStringCow<'_> {
6767
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6868
match self {
69-
Self::Borrowed(as_ref_str) => write!(f, "{}", as_ref_str),
70-
Self::Owned(as_ref_str) => write!(f, "{}", as_ref_str),
69+
Self::Borrowed(as_ref_str) => write!(f, "{as_ref_str}"),
70+
Self::Owned(as_ref_str) => write!(f, "{as_ref_str}"),
7171
}
7272
}
7373
}
@@ -82,7 +82,7 @@ pub const DEFAULT_CHAR_STORAGE_SIZE: usize = 4;
8282
/// [DEFAULT_DOCUMENT_SIZE], it will be [smallvec::SmallVec::spilled] on the heap.
8383
pub type DocumentStorage = SmallString<[u8; DEFAULT_DOCUMENT_SIZE]>;
8484
/// 128KB, or approximately 2200 lines of Markdown text (assuming 60 chars per line).
85-
pub const DEFAULT_DOCUMENT_SIZE: usize = 131072;
85+
pub const DEFAULT_DOCUMENT_SIZE: usize = 131_072;
8686

8787
// 16KB buffer for reasonable performance on Linux, which typically has a 4KB page size. A
8888
// page is a fixed sized block of memory, and memory is managed in terms of pages. It is

tui/src/core/tui_core/color_wheel/color_wheel_impl.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ impl ColorWheel {
191191
self.gradient_length_kind = GradientLengthKind::Lolcat(builder.seed);
192192
}
193193

194-
ColorWheelConfig::Rgb(stops, _, _) => {
194+
ColorWheelConfig::Rgb(color_stops, _, _) => {
195195
// Generate new gradient.
196-
let new_gradient = generate_truecolor_gradient(stops, steps);
196+
let new_gradient = generate_truecolor_gradient(color_stops, steps);
197197
self.gradient_length_kind =
198198
GradientLengthKind::ColorWheel(new_gradient.len());
199199
self.gradient_kind = GradientKind::ColorWheel(new_gradient);
@@ -454,11 +454,11 @@ impl ColorWheel {
454454
pub fn gen_style_fg_bg_color_for(
455455
maybe_style: Option<TuiStyle>,
456456
next_fg_color: Option<TuiColor>,
457-
next_bg_color: Option<TuiColor>,
457+
next_background_color: Option<TuiColor>,
458458
) -> TuiStyle {
459459
let mut it = TuiStyle {
460460
color_fg: next_fg_color,
461-
color_bg: next_bg_color,
461+
color_bg: next_background_color,
462462
..Default::default()
463463
};
464464
it += &maybe_style;

tui/src/core/tui_core/color_wheel/lolcat_impl.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ impl Default for Lolcat {
4040

4141
impl Debug for Lolcat {
4242
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
43-
return write! { f,
44-
"lolcat: [{}, {}, {}, {}]",
45-
pretty_print_f64(*self.color_wheel_control.seed),
46-
pretty_print_f64(*self.color_wheel_control.spread),
47-
pretty_print_f64(*self.color_wheel_control.frequency),
48-
self.color_wheel_control.color_change_speed
49-
};
43+
return write!(
44+
f,
45+
"lolcat: [{}, {}, {}, {}]",
46+
pretty_print_f64(*self.color_wheel_control.seed),
47+
pretty_print_f64(*self.color_wheel_control.spread),
48+
pretty_print_f64(*self.color_wheel_control.frequency),
49+
self.color_wheel_control.color_change_speed
50+
);
5051

5152
/// More info: <https://stackoverflow.com/questions/63214346/how-to-truncate-f64-to-2-decimal-places>
5253
fn pretty_print_f64(before: f64) -> f64 { f64::trunc(before * 100.0) / 100.0 }

tui/src/tui/md_parser_ng/as_str_slice/core.rs renamed to tui/src/tui/md_parser_ng/as_str_slice/as_str_slice_core.rs

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -298,84 +298,6 @@ where
298298
pub current_taken: CharacterLength,
299299
}
300300

301-
/// Macro for quickly creating an [`AsStrSlice`] test instance from one or more string
302-
/// literals.
303-
///
304-
/// This macro is intended for use in tests and examples, allowing you to easily construct
305-
/// an [`AsStrSlice`] from a list of string slices. It automatically wraps each string in
306-
/// a [`GCString`] and creates an array, which is then passed to [`AsStrSlice::from()`].
307-
///
308-
/// You can also specify an optional character length limit using the `limit:` syntax,
309-
/// which will call [`AsStrSlice::with_limit()`] instead.
310-
///
311-
/// # Examples
312-
///
313-
/// Basic usage with multiple lines:
314-
/// ```
315-
/// use r3bl_tui::{as_str_slice_test_case, AsStrSlice};
316-
/// as_str_slice_test_case!(slice, "hello", "world");
317-
/// assert_eq!(slice.to_inline_string(), "hello\nworld\n");
318-
/// ```
319-
///
320-
/// Single line:
321-
/// ```
322-
/// use r3bl_tui::{as_str_slice_test_case, AsStrSlice};
323-
/// as_str_slice_test_case!(slice, "single line");
324-
/// assert_eq!(slice.to_inline_string(), "single line");
325-
/// ```
326-
///
327-
/// With a character length limit:
328-
/// ```
329-
/// use r3bl_tui::{as_str_slice_test_case, AsStrSlice};
330-
/// as_str_slice_test_case!(slice, limit: 5, "abcdef", "ghijk");
331-
/// assert_eq!(slice.to_inline_string(), "abcde");
332-
/// ```
333-
///
334-
/// Empty lines are preserved:
335-
/// ```
336-
/// use r3bl_tui::{as_str_slice_test_case, AsStrSlice};
337-
/// as_str_slice_test_case!(slice, "", "foo", "");
338-
/// assert_eq!(slice.to_inline_string(), "\nfoo\n\n");
339-
/// ```
340-
#[macro_export]
341-
macro_rules! as_str_slice_test_case {
342-
($var_name:ident, $($string_expr:expr),+ $(,)?) => {
343-
#[allow(unused_variables)]
344-
let _input_array = [$($crate::GCString::new($string_expr)),+];
345-
let $var_name = $crate::AsStrSlice::from(&_input_array);
346-
};
347-
($var_name:ident, limit: $max_len:expr, $($string_expr:expr),+ $(,)?) => {
348-
#[allow(unused_variables)]
349-
let _input_array = [$($crate::GCString::new($string_expr)),+];
350-
let $var_name = $crate::AsStrSlice::with_limit(&_input_array, $crate::idx(0), $crate::idx(0), Some($crate::len($max_len)));
351-
};
352-
}
353-
354-
#[cfg(test)]
355-
mod tests_as_str_slice_test_case {
356-
use crate::{as_str_slice_test_case, assert_eq2};
357-
358-
#[test]
359-
fn test_as_str_slice_creation() {
360-
// Single string.
361-
as_str_slice_test_case!(input, "@title: Something");
362-
assert_eq2!(input.lines.len(), 1);
363-
assert_eq2!(input.lines[0].as_ref(), "@title: Something");
364-
365-
// Multiple strings.
366-
as_str_slice_test_case!(input, "@title: Something", "more content", "even more");
367-
assert_eq2!(input.lines.len(), 3);
368-
assert_eq2!(input.lines[0].as_ref(), "@title: Something");
369-
assert_eq2!(input.lines[1].as_ref(), "more content");
370-
assert_eq2!(input.lines[2].as_ref(), "even more");
371-
372-
// With trailing comma (optional).
373-
as_str_slice_test_case!(input, "@title: Something",);
374-
assert_eq2!(input.lines.len(), 1);
375-
assert_eq2!(input.lines[0].as_ref(), "@title: Something");
376-
}
377-
}
378-
379301
/// Extension trait for getting the character length of string-like types.
380302
///
381303
/// This trait provides a unified interface for obtaining the character count

tui/src/tui/md_parser_ng/as_str_slice/compatibility.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ pub fn convert_into_code_block_lines<'input>(
121121
/// lines.
122122
#[cfg(test)]
123123
mod tests_write_to_byte_cache_compat_behavior {
124-
use super::*;
125-
use crate::{as_str_slice_test_case, GCString, ParserByteCache};
124+
use crate::{as_str_slice_test_case, AsStrSlice, GCString, ParserByteCache};
126125

127126
#[test]
128127
fn test_empty_string() {

tui/src/tui/md_parser_ng/as_str_slice/mod.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,29 @@
8989
//! documentation on the [`AsStrSlice`] struct.**
9090
9191
// Attach.
92+
#[rustfmt::skip]
9293
pub mod compatibility;
93-
#[cfg(test)]
94-
pub mod compatibility_test_suite;
95-
pub mod core;
94+
#[rustfmt::skip]
95+
pub mod as_str_slice_core;
96+
#[rustfmt::skip]
9697
pub mod iterators;
98+
#[rustfmt::skip]
9799
pub mod operations;
100+
#[rustfmt::skip]
98101
pub mod position;
102+
#[rustfmt::skip]
99103
pub mod traits;
100104

101105
// Re-export.
102-
pub use core::*;
103-
106+
#[rustfmt::skip]
107+
pub use as_str_slice_core::*;
108+
#[rustfmt::skip]
104109
pub use compatibility::*;
110+
#[rustfmt::skip]
105111
pub use iterators::*;
112+
#[rustfmt::skip]
106113
pub use operations::*;
114+
#[rustfmt::skip]
107115
pub use position::*;
116+
#[rustfmt::skip]
108117
pub use traits::*;

tui/src/tui/md_parser_ng/as_str_slice/operations/search_and_split.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'a> AsStrSlice<'a> {
117117
/// ## Examples
118118
///
119119
/// ```rust
120-
/// # use r3bl_tui::{as_str_slice_test_case, len};
120+
/// # use r3bl_tui::{GCString, AsStrSlice, as_str_slice_test_case, len};
121121
/// // ✅ Good: Single-line processing
122122
/// as_str_slice_test_case!(input, "Hello, World!");
123123
/// let result = input.skip_take_in_current_line(7, 5); // Skip "Hello, ", take "World"
@@ -192,8 +192,7 @@ impl<'a> AsStrSlice<'a> {
192192
mod tests_is_empty {
193193
use nom::Input as _;
194194

195-
use super::*;
196-
use crate::{as_str_slice_test_case, assert_eq2, idx, len, GCString};
195+
use crate::{as_str_slice_test_case, assert_eq2, idx, len, AsStrSlice, GCString};
197196

198197
#[test]
199198
fn test_is_empty_with_max_len_zero() {

tui/src/tui/md_parser_ng/as_str_slice/operations/trim_whitespace.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ impl<'a> AsStrSlice<'a> {
116116
mod tests_trim_whitespace_chars_start_current_line {
117117
use nom::Input as _;
118118

119-
use super::*;
120-
use crate::{as_str_slice_test_case, assert_eq2, idx, len, GCString};
119+
use crate::{as_str_slice_test_case, assert_eq2, idx, len, AsStrSlice, GCString};
121120

122121
#[test]
123122
fn test_no_whitespace_to_trim() {

0 commit comments

Comments
 (0)