mirror of
https://gitee.com/openharmony/third_party_rust_proc-macro2
synced 2024-11-23 15:29:39 +00:00
Add some tests for the join method
This commit is contained in:
parent
f8d5f2171a
commit
ddea156a89
@ -127,3 +127,27 @@ fn default_span() {
|
||||
assert!(!source_file.is_real());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn span_join() {
|
||||
let source1 =
|
||||
"aaa\nbbb".parse::<TokenStream>().unwrap().into_iter().collect::<Vec<_>>();
|
||||
let source2 =
|
||||
"ccc\nddd".parse::<TokenStream>().unwrap().into_iter().collect::<Vec<_>>();
|
||||
|
||||
assert!(source1[0].span.source_file() != source2[0].span.source_file());
|
||||
assert_eq!(source1[0].span.source_file(), source1[1].span.source_file());
|
||||
|
||||
let joined1 = source1[0].span.join(source1[1].span);
|
||||
let joined2 = source1[0].span.join(source2[0].span);
|
||||
assert!(joined1.is_some());
|
||||
assert!(joined2.is_none());
|
||||
|
||||
let start = joined1.unwrap().start();
|
||||
let end = joined1.unwrap().end();
|
||||
assert_eq!(start.line, 1);
|
||||
assert_eq!(start.column, 0);
|
||||
assert_eq!(end.line, 2);
|
||||
assert_eq!(end.column, 3);
|
||||
|
||||
assert_eq!(joined1.unwrap().source_file(), source1[0].span.source_file());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user