forked from kellerkindt/asn1rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_integer.rs
62 lines (48 loc) · 1.58 KB
/
basic_integer.rs
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
use asn1rs::prelude::*;
use asn1rs::syn::io::UperWriter as NewUperWriter;
asn_to_rust!(
r"BasicInteger DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
RangedMax ::= Integer (0..MAX)
NotRanged ::= Integer
END"
);
#[test]
fn test_whether_it_compiles_at_all() {}
#[test]
fn test_default_range() {
assert_eq!(RangedMax::value_min(), NotRanged::value_min());
assert_eq!(RangedMax::value_max(), NotRanged::value_max());
let _ = NotRanged(123_u64); // does not compile if the inner type differs
}
#[test]
fn test_readme_sample() {
use asn1rs::syn::numbers::Constraint;
assert_eq!(
___asn1rs_RangedMaxField0Constraint::MIN,
___asn1rs_NotRangedField0Constraint::MIN,
);
assert_eq!(
___asn1rs_RangedMaxField0Constraint::MAX,
___asn1rs_NotRangedField0Constraint::MAX,
);
let value = NotRanged(123_u64); // does not compile if the inner type is not u64
let mut writer = NewUperWriter::default();
writer.write(&value).expect("Failed to serialize");
let mut reader = writer.as_reader();
let value2 = reader.read::<NotRanged>().expect("Failed to deserialize");
assert_eq!(value, value2);
}
#[test]
fn test_uper_small() {
let mut writer = NewUperWriter::default();
writer.write(&RangedMax(123)).unwrap();
assert_eq!(&[0x01, 123_u8], writer.byte_content());
}
#[test]
fn test_uper_big() {
let mut writer = NewUperWriter::default();
writer.write(&RangedMax(66_000)).unwrap();
let bytes = 66_000_u64.to_be_bytes();
assert_eq!(&[0x03, bytes[5], bytes[6], bytes[7]], writer.byte_content());
}