Make the UTF-8 statement more explicit and explicitly test for it

This commit is contained in:
est31 2021-08-03 03:33:05 +02:00
parent 5d7b6595ce
commit 7d20789c02
3 changed files with 17 additions and 9 deletions

View File

@ -432,8 +432,8 @@ pub struct LineColumn {
/// The 1-indexed line in the source file on which the span starts or ends (inclusive).
#[unstable(feature = "proc_macro_span", issue = "54725")]
pub line: usize,
/// The 1-indexed column (in UTF-8 characters) in the source file on which
/// the span starts or ends (inclusive).
/// The 1-indexed column (number of bytes in UTF-8 encoding) in the source
/// file on which the span starts or ends (inclusive).
#[unstable(feature = "proc_macro_span", issue = "54725")]
pub column: usize,
}

View File

@ -9,8 +9,16 @@ assert_span_pos::assert_span_pos!(5, 35);
// Test tab indentation
assert_span_pos::assert_span_pos!(10, 36);
// Two tests to ensure the promise of the docs that the column is the number
// of UTF-8 bytes instead of some other number like number of code points.
// Test that multi byte UTF-8 characters indeed count as multiple bytes
/*🌈*/assert_span_pos::assert_span_pos!(16, 40);
// Test with a complete grapheme cluster
/*🏳️‍🌈*/assert_span_pos::assert_span_pos!(18, 43);
// Test that the macro actually emits an error on a mismatch:
assert_span_pos::assert_span_pos!(0, 35); //~ ERROR line/column mismatch: (0, 35) != (13, 35)
assert_span_pos::assert_span_pos!(14, 0); //~ ERROR line/column mismatch: (14, 0) != (14, 35)
assert_span_pos::assert_span_pos!(0, 35); //~ ERROR line/column mismatch: (0, 35) != (21, 35)
assert_span_pos::assert_span_pos!(22, 0); //~ ERROR line/column mismatch: (22, 0) != (22, 35)
fn main() {}

View File

@ -1,13 +1,13 @@
error: line/column mismatch: (0, 35) != (13, 35)
--> $DIR/span-absolute-posititions.rs:13:35
error: line/column mismatch: (0, 35) != (21, 35)
--> $DIR/span-absolute-posititions.rs:21:35
|
LL | assert_span_pos::assert_span_pos!(0, 35);
| ^
error: line/column mismatch: (14, 0) != (14, 35)
--> $DIR/span-absolute-posititions.rs:14:35
error: line/column mismatch: (22, 0) != (22, 35)
--> $DIR/span-absolute-posititions.rs:22:35
|
LL | assert_span_pos::assert_span_pos!(14, 0);
LL | assert_span_pos::assert_span_pos!(22, 0);
| ^^
error: aborting due to 2 previous errors