]>
git.proxmox.com Git - rustc.git/blob - src/libsyntax/tokenstream/tests.rs
4 use crate::with_default_globals
;
5 use crate::tests
::string_to_stream
;
6 use syntax_pos
::{Span, BytePos}
;
8 fn string_to_ts(string
: &str) -> TokenStream
{
9 string_to_stream(string
.to_owned())
12 fn sp(a
: u32, b
: u32) -> Span
{
13 Span
::with_root_ctxt(BytePos(a
), BytePos(b
))
18 with_default_globals(|| {
19 let test_res
= string_to_ts("foo::bar::baz");
20 let test_fst
= string_to_ts("foo::bar");
21 let test_snd
= string_to_ts("::baz");
22 let eq_res
= TokenStream
::from_streams(smallvec
![test_fst
, test_snd
]);
23 assert_eq
!(test_res
.trees().count(), 5);
24 assert_eq
!(eq_res
.trees().count(), 5);
25 assert_eq
!(test_res
.eq_unspanned(&eq_res
), true);
30 fn test_to_from_bijection() {
31 with_default_globals(|| {
32 let test_start
= string_to_ts("foo::bar(baz)");
33 let test_end
= test_start
.trees().collect();
34 assert_eq
!(test_start
, test_end
)
40 with_default_globals(|| {
41 let test_res
= string_to_ts("foo");
42 let test_eqs
= string_to_ts("foo");
43 assert_eq
!(test_res
, test_eqs
)
49 with_default_globals(|| {
50 let test_res
= string_to_ts("::bar::baz");
51 let test_eqs
= string_to_ts("::bar::baz");
52 assert_eq
!(test_res
, test_eqs
)
58 with_default_globals(|| {
59 let test_res
= string_to_ts("");
60 let test_eqs
= string_to_ts("");
61 assert_eq
!(test_res
, test_eqs
)
67 with_default_globals(|| {
68 let test_res
= string_to_ts("::bar::baz");
69 let test_eqs
= string_to_ts("bar::baz");
70 assert_eq
!(test_res
== test_eqs
, false)
76 with_default_globals(|| {
77 let test_res
= string_to_ts("(bar,baz)");
78 let test_eqs
= string_to_ts("bar,baz");
79 assert_eq
!(test_res
== test_eqs
, false)
85 with_default_globals(|| {
86 let test0
: TokenStream
= Vec
::<TokenTree
>::new().into_iter().collect();
87 let test1
: TokenStream
=
88 TokenTree
::token(token
::Ident(Name
::intern("a"), false), sp(0, 1)).into();
89 let test2
= string_to_ts("foo(bar::baz)");
91 assert_eq
!(test0
.is_empty(), true);
92 assert_eq
!(test1
.is_empty(), false);
93 assert_eq
!(test2
.is_empty(), false);
99 with_default_globals(|| {
100 let mut builder
= TokenStreamBuilder
::new();
101 builder
.push(TokenTree
::token(token
::Dot
, sp(0, 1)).joint());
102 builder
.push(TokenTree
::token(token
::Dot
, sp(1, 2)).joint());
103 builder
.push(TokenTree
::token(token
::Dot
, sp(2, 3)));
104 let stream
= builder
.build();
105 assert
!(stream
.eq_unspanned(&string_to_ts("...")));
106 assert_eq
!(stream
.trees().count(), 1);