Skip to content

Commit 2e6d0ac

Browse files
committed
test: Newline count and width
1 parent 5b0e69e commit 2e6d0ac

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed

src/renderer/mod.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3021,7 +3021,7 @@ fn newline_count(body: &str) -> usize {
30213021

30223022
#[cfg(test)]
30233023
mod test {
3024-
use super::OUTPUT_REPLACEMENTS;
3024+
use super::{newline_count, OUTPUT_REPLACEMENTS};
30253025
use snapbox::IntoData;
30263026

30273027
fn format_replacements(replacements: Vec<(char, &str)>) -> String {
@@ -3043,4 +3043,26 @@ mod test {
30433043
let actual = format_replacements(OUTPUT_REPLACEMENTS.to_owned());
30443044
snapbox::assert_data_eq!(actual, expected.into_data().raw());
30453045
}
3046+
3047+
#[test]
3048+
fn ensure_newline_count_correct() {
3049+
let source = r#"
3050+
cargo-features = ["path-bases"]
3051+
3052+
[package]
3053+
name = "foo"
3054+
version = "0.5.0"
3055+
authors = ["[email protected]"]
3056+
3057+
[dependencies]
3058+
bar = { base = '^^not-valid^^', path = 'bar' }
3059+
"#;
3060+
let actual_count = newline_count(source);
3061+
#[cfg(feature = "simd")]
3062+
let expected_count = 9;
3063+
#[cfg(not(feature = "simd"))]
3064+
let expected_count = 10;
3065+
3066+
assert_eq!(expected_count, actual_count);
3067+
}
30463068
}

tests/formatter.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,3 +3227,79 @@ LL │ t.field;
32273227
let renderer = renderer.decor_style(DecorStyle::Unicode);
32283228
assert_data_eq!(renderer.render(input), expected_unicode);
32293229
}
3230+
3231+
#[test]
3232+
fn multiple_line_num_widths() {
3233+
let source = r#"
3234+
cargo-features = ["path-bases"]
3235+
3236+
[package]
3237+
name = "foo"
3238+
version = "0.5.0"
3239+
authors = ["[email protected]"]
3240+
3241+
[dependencies]
3242+
bar = { base = '^^not-valid^^', path = 'bar' }
3243+
"#;
3244+
3245+
let title = "invalid character `^` in path base name: `^^not-valid^^`, the first character must be a Unicode XID start character (most letters or `_`)";
3246+
3247+
let input = &[
3248+
Group::with_title(Level::ERROR.primary_title(title)).element(
3249+
Snippet::source(source)
3250+
.path("Cargo.toml")
3251+
.annotation(AnnotationKind::Primary.span(243..282))
3252+
.annotation(AnnotationKind::Visible.span(206..219)),
3253+
),
3254+
];
3255+
3256+
#[cfg(feature = "simd")]
3257+
{
3258+
let expected_ascii = str![[r#"
3259+
error: invalid character `^` in path base name: `^^not-valid^^`, the first character must be a Unicode XID start character (most letters or `_`)
3260+
--> Cargo.toml:10:24
3261+
|
3262+
9 | [dependencies]
3263+
10| bar = { base = '^^not-valid^^', path = 'bar' }
3264+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3265+
"#]];
3266+
let renderer = Renderer::plain();
3267+
assert_data_eq!(renderer.render(input), expected_ascii);
3268+
3269+
let expected_unicode = str![[r#"
3270+
error: invalid character `^` in path base name: `^^not-valid^^`, the first character must be a Unicode XID start character (most letters or `_`)
3271+
╭▸ Cargo.toml:10:24
3272+
3273+
9 │ [dependencies]
3274+
10│ bar = { base = '^^not-valid^^', path = 'bar' }
3275+
╰╴ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
3276+
"#]];
3277+
let renderer = renderer.decor_style(DecorStyle::Unicode);
3278+
assert_data_eq!(renderer.render(input), expected_unicode);
3279+
}
3280+
3281+
#[cfg(not(feature = "simd"))]
3282+
{
3283+
let expected_ascii = str![[r#"
3284+
error: invalid character `^` in path base name: `^^not-valid^^`, the first character must be a Unicode XID start character (most letters or `_`)
3285+
--> Cargo.toml:10:24
3286+
|
3287+
9 | [dependencies]
3288+
10 | bar = { base = '^^not-valid^^', path = 'bar' }
3289+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3290+
"#]];
3291+
let renderer = Renderer::plain();
3292+
assert_data_eq!(renderer.render(input), expected_ascii);
3293+
3294+
let expected_unicode = str![[r#"
3295+
error: invalid character `^` in path base name: `^^not-valid^^`, the first character must be a Unicode XID start character (most letters or `_`)
3296+
╭▸ Cargo.toml:10:24
3297+
3298+
9 │ [dependencies]
3299+
10 │ bar = { base = '^^not-valid^^', path = 'bar' }
3300+
╰╴ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
3301+
"#]];
3302+
let renderer = renderer.decor_style(DecorStyle::Unicode);
3303+
assert_data_eq!(renderer.render(input), expected_unicode);
3304+
}
3305+
}

0 commit comments

Comments
 (0)