Skip to content

Commit e37ba70

Browse files
committed
cargo format
1 parent 94796e6 commit e37ba70

File tree

2 files changed

+39
-30
lines changed

2 files changed

+39
-30
lines changed

crates/ra_syntax/src/validation.rs

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ fn validate_char(node: ast::Char, errors: &mut Vec<SyntaxError>) {
4949
if text.len() < 4 {
5050
errors.push(SyntaxError::new(TooShortAsciiCodeEscape, range));
5151
} else {
52-
assert!(text.chars().count() == 4, "AsciiCodeEscape cannot be longer than 4 chars");
52+
assert!(
53+
text.chars().count() == 4,
54+
"AsciiCodeEscape cannot be longer than 4 chars"
55+
);
5356

5457
match u8::from_str_radix(&text[2..], 16) {
55-
Ok(code) if code < 128 => { /* Escape code is valid */ },
58+
Ok(code) if code < 128 => { /* Escape code is valid */ }
5659
Ok(_) => errors.push(SyntaxError::new(AsciiCodeEscapeOutOfRange, range)),
5760
Err(_) => errors.push(SyntaxError::new(MalformedAsciiCodeEscape, range)),
5861
}
59-
6062
}
6163
}
6264
UnicodeEscape => {
@@ -127,7 +129,7 @@ fn validate_char(node: ast::Char, errors: &mut Vec<SyntaxError>) {
127129
if text == "\t" || text == "\r" {
128130
errors.push(SyntaxError::new(UnescapedCodepoint, range));
129131
}
130-
},
132+
}
131133
}
132134
}
133135

@@ -162,13 +164,17 @@ mod test {
162164

163165
fn assert_valid_char(literal: &str) {
164166
let file = build_file(literal);
165-
assert!(file.errors().len() == 0, "Errors for literal '{}': {:?}", literal, file.errors());
167+
assert!(
168+
file.errors().len() == 0,
169+
"Errors for literal '{}': {:?}",
170+
literal,
171+
file.errors()
172+
);
166173
}
167174

168-
fn assert_invalid_char(literal: &str) { //, expected_errors: HashSet<SyntaxErrorKind>) {
175+
fn assert_invalid_char(literal: &str) {
169176
let file = build_file(literal);
170177
assert!(file.errors().len() > 0);
171-
//let found_errors = file.errors().iter().map(|e| e.kind()).collect();
172178
}
173179

174180
#[test]
@@ -184,68 +190,60 @@ mod test {
184190

185191
#[test]
186192
fn test_unicode_codepoints() {
187-
let valid = [
188-
"Ƒ", "バ", "メ", "﷽"
189-
];
193+
let valid = ["Ƒ", "バ", "メ", "﷽"];
190194
for c in &valid {
191195
assert_valid_char(c);
192196
}
193197
}
194198

195199
#[test]
196200
fn test_unicode_multiple_codepoints() {
197-
let invalid = [
198-
"नी", "👨‍👨‍"
199-
];
201+
let invalid = ["नी", "👨‍👨‍"];
200202
for c in &invalid {
201203
assert_invalid_char(c);
202204
}
203205
}
204206

205207
#[test]
206208
fn test_valid_ascii_escape() {
207-
let valid = [
208-
r"\'", "\"", "\\\"", r"\n", r"\r", r"\t", r"\0", "a", "b"
209-
];
209+
let valid = [r"\'", "\"", "\\\"", r"\n", r"\r", r"\t", r"\0", "a", "b"];
210210
for c in &valid {
211211
assert_valid_char(c);
212212
}
213213
}
214214

215215
#[test]
216216
fn test_invalid_ascii_escape() {
217-
let invalid = [
218-
r"\a", r"\?", r"\"
219-
];
217+
let invalid = [r"\a", r"\?", r"\"];
220218
for c in &invalid {
221219
assert_invalid_char(c);
222220
}
223221
}
224222

225223
#[test]
226224
fn test_valid_ascii_code_escape() {
227-
let valid = [
228-
r"\x00", r"\x7F", r"\x55"
229-
];
225+
let valid = [r"\x00", r"\x7F", r"\x55"];
230226
for c in &valid {
231227
assert_valid_char(c);
232228
}
233229
}
234230

235231
#[test]
236232
fn test_invalid_ascii_code_escape() {
237-
let invalid = [
238-
r"\x", r"\x7", r"\xF0"
239-
];
233+
let invalid = [r"\x", r"\x7", r"\xF0"];
240234
for c in &invalid {
241235
assert_invalid_char(c);
242236
}
243237
}
244238

245-
#[test]
239+
#[test]
246240
fn test_valid_unicode_escape() {
247241
let valid = [
248-
r"\u{FF}", r"\u{0}", r"\u{F}", r"\u{10FFFF}", r"\u{1_0__FF___FF_____}"
242+
r"\u{FF}",
243+
r"\u{0}",
244+
r"\u{F}",
245+
r"\u{10FFFF}",
246+
r"\u{1_0__FF___FF_____}",
249247
];
250248
for c in &valid {
251249
assert_valid_char(c);
@@ -255,7 +253,14 @@ mod test {
255253
#[test]
256254
fn test_invalid_unicode_escape() {
257255
let invalid = [
258-
r"\u", r"\u{}", r"\u{", r"\u{FF", r"\u{FFFFFF}", r"\u{_F}", r"\u{00FFFFF}", r"\u{110000}"
256+
r"\u",
257+
r"\u{}",
258+
r"\u{",
259+
r"\u{FF",
260+
r"\u{FFFFFF}",
261+
r"\u{_F}",
262+
r"\u{00FFFFF}",
263+
r"\u{110000}",
259264
];
260265
for c in &invalid {
261266
assert_invalid_char(c);

crates/ra_syntax/src/yellow/syntax_error.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,16 @@ impl fmt::Display for SyntaxErrorKind {
9898
UnclosedChar => write!(f, "Unclosed char literal"),
9999
LongChar => write!(f, "Char literal should be one character long"),
100100
TooShortAsciiCodeEscape => write!(f, "Escape sequence should have two digits"),
101-
AsciiCodeEscapeOutOfRange => write!(f, "Escape sequence should be between \\x00 and \\x7F"),
101+
AsciiCodeEscapeOutOfRange => {
102+
write!(f, "Escape sequence should be between \\x00 and \\x7F")
103+
}
102104
MalformedAsciiCodeEscape => write!(f, "Escape sequence should be a hexadecimal number"),
103105
UnclosedUnicodeEscape => write!(f, "Missing `}}`"),
104106
MalformedUnicodeEscape => write!(f, "Malformed unicode escape sequence"),
105107
EmptyUnicodeEcape => write!(f, "Empty unicode escape sequence"),
106-
OverlongUnicodeEscape => write!(f, "Unicode escape sequence should have at most 6 digits"),
108+
OverlongUnicodeEscape => {
109+
write!(f, "Unicode escape sequence should have at most 6 digits")
110+
}
107111
UnicodeEscapeOutOfRange => write!(f, "Unicode escape code should be at most 0x10FFFF"),
108112
ParseError(msg) => write!(f, "{}", msg.0),
109113
}

0 commit comments

Comments
 (0)