formatter: support formatting bindings, for example in a let (#2883)

This commit is contained in:
Tyler Wilding
2023-08-05 13:23:09 -06:00
committed by GitHub
parent bb8b39a5e8
commit a7cf66fda6
17 changed files with 427 additions and 134 deletions
@@ -6,12 +6,10 @@ Basic Nested Form
---
(println
"hello"
(println
"world"
"world2"
"very-long-formvery-long-formvery-long-formvery-long-formvery-long-formvery-long-formvery-long-form"))
(println "hello"
(println "world"
"world2"
"very-long-formvery-long-formvery-long-formvery-long-formvery-long-formvery-long-formvery-long-form"))
===
Multiple Top Level Forms
@@ -58,3 +56,14 @@ Single Item Form
(println)
===
defun - No Docstring
===
(defun test-function ((arg0 string))
(println arg0))
---
(defun test-function ((arg0 string))
(println arg0))
+24
View File
@@ -0,0 +1,24 @@
===
Single Binding - Inlinable
===
(let ((a 1))
(+ a b))
---
(let ((a 1)) (+ a b))
===
Multiple Bindings
===
(let ((a 1)
(b 2))
(+ a b))
---
(let ((a 1)
(b 2))
(+ a b))
@@ -0,0 +1,24 @@
===
Constant List
===
(1 2 3 4)
---
(1 2 3 4)
===
Constant List - Too Long to Inline
===
(1111111111111 2222222222222222 3333333333333333333333333 444444444444444444444444444 555555555555555555555555555555555 666666666666666666666666666666666666666)
---
(1111111111111
2222222222222222
3333333333333333333333333
444444444444444444444444444
555555555555555555555555555555555
666666666666666666666666666666666666666)
+22 -18
View File
@@ -122,27 +122,31 @@ bool run_tests(const fs::path& file_path, const bool only_important_tests) {
}
bool find_and_run_tests() {
// Enumerate test files
const auto test_files = file_util::find_files_recursively(
file_util::get_file_path({"test/common/formatter/corpus"}), std::regex("^.*\.test.gc$"));
bool failed = false;
// First do a pass to see if any tests are meant to be prioritized for debugging
bool only_important_tests = false;
for (const auto& file : test_files) {
only_important_tests = has_important_tests(file);
if (only_important_tests) {
break;
try {
// Enumerate test files
const auto test_files = file_util::find_files_recursively(
file_util::get_file_path({"test/common/formatter/corpus"}), std::regex("^.*\.test.gc$"));
bool failed = false;
// First do a pass to see if any tests are meant to be prioritized for debugging
bool only_important_tests = false;
for (const auto& file : test_files) {
only_important_tests = has_important_tests(file);
if (only_important_tests) {
break;
}
}
}
for (const auto& file : test_files) {
// don't fail fast, but any failure means we return false
if (failed) {
run_tests(file, only_important_tests);
} else {
failed = run_tests(file, only_important_tests);
for (const auto& file : test_files) {
// don't fail fast, but any failure means we return false
if (failed) {
run_tests(file, only_important_tests);
} else {
failed = run_tests(file, only_important_tests);
}
}
return !failed;
} catch (std::exception& e) {
return false;
}
return !failed;
}
TEST(Formatter, FormatterTests) {