-
Notifications
You must be signed in to change notification settings - Fork 7
/
parse_test.rs
105 lines (93 loc) · 3.07 KB
/
parse_test.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
extern crate webidl;
extern crate zip;
use std::fs;
use std::io::Read;
use webidl::*;
#[test]
fn parse_servo_webidls() {
let parser = Parser::new();
let file = fs::File::open("tests/mozilla_webidls.zip").unwrap();
let mut archive = zip::ZipArchive::new(file).unwrap();
for i in 0..archive.len() {
let mut file = archive.by_index(i).unwrap();
let mut webidl = String::new();
file.read_to_string(&mut webidl).unwrap();
// With the new update to the specification, the "implements" definition has been replaced
// with "includes", but the Mozilla WebIDLs have not been updated.
if let Err(err) = parser.parse_string(&*webidl) {
match err {
ParseError::UnrecognizedToken {
token: Some((_, ref token, _)),
..
} if *token == Token::Identifier("implements".to_string()) =>
{
break
}
_ => panic!("parse error: {:?}", err),
}
}
}
}
// A test case using the "includes" definition does not appear in the Mozilla WebIDLs, so it needs
// to be tested separately.
#[test]
fn parse_includes() {
use ast::*;
let parser = Parser::new();
let ast = parser.parse_string("[test] A includes B;").unwrap();
assert_eq!(
ast,
vec![
Definition::Includes(Includes {
extended_attributes: vec![
Box::new(ExtendedAttribute::NoArguments(Other::Identifier(
"test".to_string(),
))),
],
includee: "B".to_string(),
includer: "A".to_string(),
}),
]
);
}
// A test case using the "mixin" definition does not appear in the Mozilla WebIDLs, so it needs to
// be tested separately.
#[test]
fn parse_mixin() {
use ast::*;
let parser = Parser::new();
let ast = parser
.parse_string(
"[test]
partial interface mixin Name {
readonly attribute unsigned short entry;
};",
)
.unwrap();
assert_eq!(
ast,
vec![
Definition::Mixin(Mixin::Partial(PartialMixin {
extended_attributes: vec![
Box::new(ExtendedAttribute::NoArguments(Other::Identifier(
"test".to_string(),
))),
],
members: vec![
MixinMember::Attribute(Attribute::Regular(RegularAttribute {
extended_attributes: vec![],
inherits: false,
name: "entry".to_string(),
read_only: true,
type_: Box::new(Type {
extended_attributes: vec![],
kind: TypeKind::UnsignedShort,
nullable: false,
}),
})),
],
name: "Name".to_string(),
})),
]
);
}