diff options
author | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
commit | 12e3b4c70b5ef23b2fdfc197296d483680e125f9 (patch) | |
tree | 71baa0e0a62f9f6b61450501c5f821f67badf9e4 /crates/ra_syntax/src/validation/byte.rs | |
parent | 5cb1d41a30d25cbe136402644bf5434dd667f1e5 (diff) |
reformat the world
Diffstat (limited to 'crates/ra_syntax/src/validation/byte.rs')
-rw-r--r-- | crates/ra_syntax/src/validation/byte.rs | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/crates/ra_syntax/src/validation/byte.rs b/crates/ra_syntax/src/validation/byte.rs index 9bddabc80..d51fabcf9 100644 --- a/crates/ra_syntax/src/validation/byte.rs +++ b/crates/ra_syntax/src/validation/byte.rs | |||
@@ -28,10 +28,7 @@ pub(super) fn validate_byte_node(node: &ast::Byte, errors: &mut Vec<SyntaxError> | |||
28 | } | 28 | } |
29 | 29 | ||
30 | if let Some(range) = components.suffix { | 30 | if let Some(range) = components.suffix { |
31 | errors.push(SyntaxError::new( | 31 | errors.push(SyntaxError::new(InvalidSuffix, range + literal_range.start())); |
32 | InvalidSuffix, | ||
33 | range + literal_range.start(), | ||
34 | )); | ||
35 | } | 32 | } |
36 | 33 | ||
37 | if len == 0 { | 34 | if len == 0 { |
@@ -55,10 +52,7 @@ pub(super) fn validate_byte_component( | |||
55 | AsciiCodeEscape => validate_byte_code_escape(text, range, errors), | 52 | AsciiCodeEscape => validate_byte_code_escape(text, range, errors), |
56 | UnicodeEscape => errors.push(SyntaxError::new(UnicodeEscapeForbidden, range)), | 53 | UnicodeEscape => errors.push(SyntaxError::new(UnicodeEscapeForbidden, range)), |
57 | CodePoint => { | 54 | CodePoint => { |
58 | let c = text | 55 | let c = text.chars().next().expect("Code points should be one character long"); |
59 | .chars() | ||
60 | .next() | ||
61 | .expect("Code points should be one character long"); | ||
62 | 56 | ||
63 | // These bytes must always be escaped | 57 | // These bytes must always be escaped |
64 | if c == '\t' || c == '\r' || c == '\n' { | 58 | if c == '\t' || c == '\r' || c == '\n' { |
@@ -93,10 +87,7 @@ fn validate_byte_code_escape(text: &str, range: TextRange, errors: &mut Vec<Synt | |||
93 | } else if text.chars().count() < 4 { | 87 | } else if text.chars().count() < 4 { |
94 | errors.push(SyntaxError::new(TooShortByteCodeEscape, range)); | 88 | errors.push(SyntaxError::new(TooShortByteCodeEscape, range)); |
95 | } else { | 89 | } else { |
96 | assert!( | 90 | assert!(text.chars().count() == 4, "ByteCodeEscape cannot be longer than 4 chars"); |
97 | text.chars().count() == 4, | ||
98 | "ByteCodeEscape cannot be longer than 4 chars" | ||
99 | ); | ||
100 | 91 | ||
101 | if u8::from_str_radix(&text[2..], 16).is_err() { | 92 | if u8::from_str_radix(&text[2..], 16).is_err() { |
102 | errors.push(SyntaxError::new(MalformedByteCodeEscape, range)); | 93 | errors.push(SyntaxError::new(MalformedByteCodeEscape, range)); |
@@ -115,12 +106,7 @@ mod test { | |||
115 | 106 | ||
116 | fn assert_valid_byte(literal: &str) { | 107 | fn assert_valid_byte(literal: &str) { |
117 | let file = build_file(literal); | 108 | let file = build_file(literal); |
118 | assert!( | 109 | assert!(file.errors().len() == 0, "Errors for literal '{}': {:?}", literal, file.errors()); |
119 | file.errors().len() == 0, | ||
120 | "Errors for literal '{}': {:?}", | ||
121 | literal, | ||
122 | file.errors() | ||
123 | ); | ||
124 | } | 110 | } |
125 | 111 | ||
126 | fn assert_invalid_byte(literal: &str) { | 112 | fn assert_invalid_byte(literal: &str) { |
@@ -193,13 +179,7 @@ mod test { | |||
193 | 179 | ||
194 | #[test] | 180 | #[test] |
195 | fn test_invalid_unicode_escape() { | 181 | fn test_invalid_unicode_escape() { |
196 | let well_formed = [ | 182 | let well_formed = [r"\u{FF}", r"\u{0}", r"\u{F}", r"\u{10FFFF}", r"\u{1_0__FF___FF_____}"]; |
197 | r"\u{FF}", | ||
198 | r"\u{0}", | ||
199 | r"\u{F}", | ||
200 | r"\u{10FFFF}", | ||
201 | r"\u{1_0__FF___FF_____}", | ||
202 | ]; | ||
203 | for c in &well_formed { | 183 | for c in &well_formed { |
204 | assert_invalid_byte(c); | 184 | assert_invalid_byte(c); |
205 | } | 185 | } |