1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
use {serde_test::*, std::ops, text_size::*};
fn size(x: u32) -> TextSize {
TextSize::from(x)
}
fn range(x: ops::Range<u32>) -> TextRange {
TextRange::new(x.start.into(), x.end.into())
}
#[test]
fn size_serialization() {
assert_tokens(&size(00), &[Token::U32(00)]);
assert_tokens(&size(10), &[Token::U32(10)]);
assert_tokens(&size(20), &[Token::U32(20)]);
assert_tokens(&size(30), &[Token::U32(30)]);
}
#[test]
fn range_serialization() {
assert_tokens(
&range(00..10),
&[
Token::Tuple { len: 2 },
Token::U32(00),
Token::U32(10),
Token::TupleEnd,
],
);
assert_tokens(
&range(10..20),
&[
Token::Tuple { len: 2 },
Token::U32(10),
Token::U32(20),
Token::TupleEnd,
],
);
assert_tokens(
&range(20..30),
&[
Token::Tuple { len: 2 },
Token::U32(20),
Token::U32(30),
Token::TupleEnd,
],
);
assert_tokens(
&range(30..40),
&[
Token::Tuple { len: 2 },
Token::U32(30),
Token::U32(40),
Token::TupleEnd,
],
);
}
#[test]
fn invalid_range_deserialization() {
assert_tokens::<TextRange>(
&range(62..92),
&[
Token::Tuple { len: 2 },
Token::U32(62),
Token::U32(92),
Token::TupleEnd,
],
);
assert_de_tokens_error::<TextRange>(
&[
Token::Tuple { len: 2 },
Token::U32(92),
Token::U32(62),
Token::TupleEnd,
],
"invalid range: 92..62",
);
}
|