Skip to content

Commit

Permalink
cargo: fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
santhosh-tekuri committed Sep 12, 2023
1 parent b02723b commit 9c71a06
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
24 changes: 12 additions & 12 deletions src/ecma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ fn fix_error(e: &Error) -> Option<String> {
let (start, end) = (e.span().start.offset, e.span().end.offset);
let s = &e.pattern()[start..end];
match s {
r#"\/"# => {
r"\/" => {
// handle escaping '/'
return Some(format!("{}/{}", &e.pattern()[..start], &e.pattern()[end..],));
}
r#"\c"# => {
r"\c" => {
// handle \c{control_letter}
if let Some(control_letter) = e.pattern()[end..].chars().next() {
if control_letter.is_ascii_alphabetic() {
Expand All @@ -70,7 +70,7 @@ fn fix_error(e: &Error) -> Option<String> {
}
}
}
r#"\D"# => {
r"\D" => {
// handle \c{control_letter}
if let Some(control_letter) = e.pattern()[end..].chars().next() {
if control_letter.is_ascii_alphabetic() {
Expand Down Expand Up @@ -174,13 +174,13 @@ mod tests {
fn test_ecma_compat_valid() {
// println!("{:#?}", Parser::new().parse(r#"a\a"#));
let tests = [
(r#"ab\/cde\/fg"#, r#"ab/cde/fg"#), // '/' can be escaped
(r#"ab\cAcde\cBfg"#, "ab\u{1}cde\u{2}fg"), // \c{control_letter}
(r#"\\comment"#, r#"\\comment"#), // there is no \c
(r#"ab\def"#, r#"ab[0-9]ef"#), // \d
(r#"ab[a-z\d]ef"#, r#"ab[a-z[0-9]]ef"#), // \d inside classSet
(r#"ab\Def"#, r#"ab[^0-9]ef"#), // \d
(r#"ab[a-z\D]ef"#, r#"ab[a-z[^0-9]]ef"#), // \D inside classSet
(r"ab\/cde\/fg", r"ab/cde/fg"), // '/' can be escaped
(r"ab\cAcde\cBfg", "ab\u{1}cde\u{2}fg"), // \c{control_letter}
(r"\\comment", r"\\comment"), // there is no \c
(r"ab\def", r#"ab[0-9]ef"#), // \d
(r"ab[a-z\d]ef", r#"ab[a-z[0-9]]ef"#), // \d inside classSet
(r"ab\Def", r#"ab[^0-9]ef"#), // \d
(r"ab[a-z\D]ef", r#"ab[a-z[^0-9]]ef"#), // \D inside classSet
];
for (input, want) in tests {
match convert(input) {
Expand All @@ -200,8 +200,8 @@ mod tests {
fn test_ecma_compat_invalid() {
// println!("{:#?}", Parser::new().parse(r#"a\a"#));
let tests = [
r#"\c\n"#, // \c{invalid_char}
r#"abc\adef"#, // \a is not valid
r"\c\n", // \c{invalid_char}
r"abc\adef", // \a is not valid
];
for input in tests {
if convert(input).is_ok() {
Expand Down
2 changes: 1 addition & 1 deletion src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl<'a, 's, 'v> Display for SchemaLocation<'a, 's, 'v> {
};

let Some(prev) = iter.next_back() else {
return write!(f, "{cur}")
return write!(f, "{cur}");
};

let p = match &prev.kind {
Expand Down
4 changes: 1 addition & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ pub(crate) fn quote<T>(s: &T) -> String
where
T: AsRef<str> + std::fmt::Debug + ?Sized,
{
let s = format!("{s:?}")
.replace(r#"\""#, "\"")
.replace('\'', r#"\'"#);
let s = format!("{s:?}").replace(r#"\""#, "\"").replace('\'', r"\'");
format!("'{}'", &s[1..s.len() - 1])
}

Expand Down

0 comments on commit 9c71a06

Please sign in to comment.