File: pi.rs

package info (click to toggle)
rust-xmlparser 0.13.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 252 kB
  • sloc: makefile: 4
file content (135 lines) | stat: -rw-r--r-- 4,530 bytes parent folder | download | duplicates (2)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
use crate::token::*;

test!(pi_01, "<?xslt ma?>",
    Token::PI("xslt", Some("ma"), 0..11)
);

test!(pi_02, "<?xslt \t\n m?>",
    Token::PI("xslt", Some("m"), 0..13)
);

test!(pi_03, "<?xslt?>",
    Token::PI("xslt", None, 0..8)
);

test!(pi_04, "<?xslt ?>",
    Token::PI("xslt", None, 0..9)
);

test!(pi_05, "<?xml-stylesheet?>",
    Token::PI("xml-stylesheet", None, 0..18)
);

test!(pi_err_01, "<??xml \t\n m?>",
    Token::Error("invalid processing instruction at 1:1 cause invalid name token".to_string())
);

test!(declaration_01, "<?xml version=\"1.0\"?>",
    Token::Declaration("1.0", None, None, 0..21)
);

test!(declaration_02, "<?xml version='1.0'?>",
    Token::Declaration("1.0", None, None, 0..21)
);

test!(declaration_03, "<?xml version='1.0' encoding=\"UTF-8\"?>",
    Token::Declaration("1.0", Some("UTF-8"), None, 0..38)
);

test!(declaration_04, "<?xml version='1.0' encoding='UTF-8'?>",
    Token::Declaration("1.0", Some("UTF-8"), None, 0..38)
);

test!(declaration_05, "<?xml version='1.0' encoding='utf-8'?>",
    Token::Declaration("1.0", Some("utf-8"), None, 0..38)
);

test!(declaration_06, "<?xml version='1.0' encoding='EUC-JP'?>",
    Token::Declaration("1.0", Some("EUC-JP"), None, 0..39)
);

test!(declaration_07, "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>",
    Token::Declaration("1.0", Some("UTF-8"), Some(true), 0..55)
);

test!(declaration_08, "<?xml version='1.0' encoding='UTF-8' standalone='no'?>",
    Token::Declaration("1.0", Some("UTF-8"), Some(false), 0..54)
);

test!(declaration_09, "<?xml version='1.0' standalone='no'?>",
    Token::Declaration("1.0", None, Some(false), 0..37)
);

test!(declaration_10, "<?xml version='1.0' standalone='no' ?>",
    Token::Declaration("1.0", None, Some(false), 0..38)
);

// Declaration with an invalid order
test!(declaration_err_01, "<?xml encoding='UTF-8' version='1.0'?>",
    Token::Error("invalid XML declaration at 1:1 cause expected 'version' at 1:7".to_string())
);

test!(declaration_err_02, "<?xml version='1.0' encoding='*invalid*'?>",
    Token::Error("invalid XML declaration at 1:1 cause expected '\'' not '*' at 1:31".to_string())
);

test!(declaration_err_03, "<?xml version='2.0'?>",
    Token::Error("invalid XML declaration at 1:1 cause expected '1.' at 1:16".to_string())
);

test!(declaration_err_04, "<?xml version='1.0' standalone='true'?>",
    Token::Error("invalid XML declaration at 1:1 cause expected 'yes', 'no' at 1:33".to_string())
);

test!(declaration_err_05, "<?xml version='1.0' yes='true'?>",
    Token::Error("invalid XML declaration at 1:1 cause expected '?>' at 1:21".to_string())
);

test!(declaration_err_06, "<?xml version='1.0' encoding='UTF-8' standalone='yes' yes='true'?>",
    Token::Error("invalid XML declaration at 1:1 cause expected '?>' at 1:55".to_string())
);

test!(declaration_err_07, "\u{000a}<?xml\u{000a}&jg'];",
    Token::Error("invalid processing instruction at 2:1 cause expected '?>' at 3:7".to_string())
);

test!(declaration_err_08, "<?xml \t\n ?m?>",
    Token::Error("invalid XML declaration at 1:1 cause expected 'version' at 2:2".to_string())
);

test!(declaration_err_09, "<?xml \t\n m?>",
    Token::Error("invalid XML declaration at 1:1 cause expected 'version' at 2:2".to_string())
);

// XML declaration allowed only at the start of the document.
test!(declaration_err_10, " <?xml version='1.0'?>",
    Token::Error("unknown token at 1:2".to_string())
);

// XML declaration allowed only at the start of the document.
test!(declaration_err_11, "<!-- comment --><?xml version='1.0'?>",
    Token::Comment(" comment ", 0..16),
    Token::Error("unknown token at 1:17".to_string())
);

// Duplicate.
test!(declaration_err_12, "<?xml version='1.0'?><?xml version='1.0'?>",
    Token::Declaration("1.0", None, None, 0..21),
    Token::Error("unknown token at 1:22".to_string())
);

test!(declaration_err_13, "<?target \u{1}content>",
    Token::Error("invalid processing instruction at 1:1 cause a non-XML character '\\u{1}' found at 1:10".to_string())
);

test!(declaration_err_14, "<?xml version='1.0'encoding='UTF-8'?>",
    Token::Error("invalid XML declaration at 1:1 cause expected space not 'e' at 1:20".to_string())
);

test!(declaration_err_15, "<?xml version='1.0' encoding='UTF-8'standalone='yes'?>",
    Token::Error("invalid XML declaration at 1:1 cause expected space not 's' at 1:37".to_string())
);

test!(declaration_err_16, "<?xml version='1.0'",
    Token::Error("invalid XML declaration at 1:1 cause expected '?>' at 1:20".to_string())
);