Skip to content

Commit

Permalink
more syntax tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino committed Aug 5, 2023
1 parent 428fbe3 commit 283dc7f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
7 changes: 7 additions & 0 deletions proptest-regressions/parser/syntax.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 72dda53aa591d94f5466c82b7f57c179c5b7e39a1fa3d88058bbe1fc5b05a501 # shrinks to x = Quote(No, List(No, [Path(No, ["."], false)]))
38 changes: 30 additions & 8 deletions src/parser/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,11 @@ pub mod tests {
assert!(test(parse_path(), "..", Some(sym_path!([""]))));
assert!(test(parse_path(), "foo", Some(rel_path!(["foo"]))));
assert!(test(parse_path(), "|foo|", Some(rel_path!(["foo"]))));
assert!(test(parse_path(), "|Hi, bye|", Some(rel_path!(["Hi, bye"]))));
assert!(test(
parse_path(),
"|Hi, bye|",
Some(rel_path!(["Hi, bye"]))
));
assert!(test(
parse_path(),
"|foo|.|bar|",
Expand Down Expand Up @@ -427,7 +431,11 @@ pub mod tests {
".foo\\u{00}.bar\\u{00}",
Some(sym_path!(["foo\u{00}", "bar\u{00}"]))
));
assert!(test(parse_path(), ".foo\\.bar", Some(sym_path!(["foo.bar"]))));
assert!(test(
parse_path(),
".foo\\.bar",
Some(sym_path!(["foo.bar"]))
));
assert!(test(parse_path(), "~(asdf )", Some(sym_path!(["asdf"]))));
assert!(test(parse_path(), "~( asdf )", Some(sym_path!(["asdf"]))));
assert!(test(parse_path(), "~( asdf)", Some(sym_path!(["asdf"]))));
Expand Down Expand Up @@ -508,7 +516,10 @@ pub mod tests {
assert!(test(
parse_syntax(),
"(.foo.bar .foo.bar)",
Some(list!([sym_path!(["foo", "bar"]), sym_path!(["foo", "bar"])])),
Some(list!([
sym_path!(["foo", "bar"]),
sym_path!(["foo", "bar"])
])),
));
assert!(test(
parse_syntax(),
Expand All @@ -523,7 +534,10 @@ pub mod tests {
assert!(test(
parse_syntax(),
"(a b . c)",
Some(list!([rel_path!(["a"]), rel_path!(["b"])], rel_path!(["c"]))),
Some(list!(
[rel_path!(["a"]), rel_path!(["b"])],
rel_path!(["c"])
)),
));
assert!(test(
parse_syntax(),
Expand All @@ -536,7 +550,11 @@ pub mod tests {
assert!(test(
parse_syntax(),
"(a b c)",
Some(list!([rel_path!(["a"]), rel_path!(["b"]), rel_path!(["c"])])),
Some(list!([
rel_path!(["a"]),
rel_path!(["b"]),
rel_path!(["c"])
])),
));
assert!(test(
parse_syntax(),
Expand All @@ -547,7 +565,11 @@ pub mod tests {
assert!(test(
parse_syntax(),
"(a. b. c.)",
Some(list!([rel_path!(["a"]), rel_path!(["b"]), rel_path!(["c"])])),
Some(list!([
rel_path!(["a"]),
rel_path!(["b"]),
rel_path!(["c"])
])),
));
assert!(test(
parse_syntax(),
Expand Down Expand Up @@ -750,8 +772,8 @@ pub mod tests {
"{}",
list!(
Scalar,
[Syntax::Quote(Pos::No, Box::new(rel_path!([""])))],
sym_path!(["a"])
[Syntax::Quote(Pos::No, Box::new(sym_path!([""])))],
rel_path!(["a"])
)
)
);
Expand Down
17 changes: 10 additions & 7 deletions src/symbol.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::fmt;

use anyhow::{bail, Result};
use itertools::Itertools;

use crate::parser::LURK_WHITESPACE;
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -281,19 +280,23 @@ impl Symbol {
res.push(c)
}
}
if res.is_empty() {
"||".into()
} else if has_whitespace || Self::start_needs_escaping(&res) {
if has_whitespace || Self::start_needs_escaping(&res) {
format!("|{res}|")
} else {
res
}
}

pub fn format_path(path: &[String]) -> String {
path.iter()
.map(|s| Self::format_path_component(s))
.join(".")
let mut res = String::new();
let mut iter = path.iter().peekable();
while let Some(next) = iter.next() {
res.push_str(&Self::format_path_component(next));
if iter.peek().is_some() || next.is_empty() {
res.push('.');
}
}
res
}

pub fn format(&self) -> String {
Expand Down

0 comments on commit 283dc7f

Please sign in to comment.