Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: zprint #364

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/formatters/zprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,47 @@ pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfEr

execute_command(cmd, file_path)
}

#[cfg(test)]
mod test_zprint {
use crate::{formatters::setup_snippet, generated::language_to_ext};

#[test_with::executable(zprint)]
fn it_should_format_clojure() {
let input = "(defn change-start-column [new-start-column style-vec [inline-comment-index
start-column spaces-before :as comment-vec]] (if (zero? inline-comment-index)
style-vec (let [delta-spaces (- new-start-column start-column) new-spaces
(+ spaces-before delta-spaces) previous-element-index (dec
inline-comment-index) [s c e :as previous-element] (nth style-vec
previous-element-index) new-previous-element (cond (= e :indent) [(str \"\n\"
(blanks new-spaces)) c e] (= e :whitespace) [(str (blanks new-spaces))
c e 26] :else nil)] (assoc style-vec previous-element-index
new-previous-element))))";

let expected_output = "(defn change-start-column
[new-start-column style-vec
[inline-comment-index start-column spaces-before :as comment-vec]]
(if (zero? inline-comment-index)
style-vec
(let [delta-spaces (- new-start-column start-column)
new-spaces (+ spaces-before delta-spaces)
previous-element-index (dec inline-comment-index)
[s c e :as previous-element] (nth style-vec previous-element-index)
new-previous-element
(cond (= e :indent) [(str \"\n\" (blanks new-spaces)) c e]
(= e :whitespace) [(str (blanks new-spaces)) c e 26]
:else nil)]
(assoc style-vec previous-element-index new-previous-element))))";

let snippet =
setup_snippet(input, language_to_ext("clojure")).expect("it to create a snippet file");

let output = super::run(snippet.path())
.expect("it to be successful")
.1
.expect("it to be some");

// NOTE: we are trimming since I do not remember if the output ends with a blank line
assert_eq!(expected_output, output.trim());
}
}
Loading