es_fluent_cli/commands/
dry_run.rs1use crate::utils::ui;
2
3#[derive(Clone, Debug)]
4pub struct DryRunDiff {
5 before: String,
6 after: String,
7}
8
9impl DryRunDiff {
10 pub fn new(before: String, after: String) -> Self {
11 Self { before, after }
12 }
13
14 pub fn print(&self) {
15 ui::print_diff(&self.before, &self.after);
16 }
17}
18
19#[derive(Clone, Copy, Debug)]
20pub enum DryRunSummary {
21 Format { formatted: usize },
22 Sync { keys: usize, locales: usize },
23}
24
25impl DryRunSummary {
26 pub fn print(self) {
27 match self {
28 DryRunSummary::Format { formatted } => {
29 ui::print_format_dry_run_summary(formatted);
30 },
31 DryRunSummary::Sync { keys, locales } => {
32 ui::print_sync_dry_run_summary(keys, locales);
33 },
34 }
35 }
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 #[test]
43 fn dry_run_diff_new_stores_before_and_after() {
44 let diff = DryRunDiff::new("old".to_string(), "new".to_string());
45 assert_eq!(diff.before, "old");
46 assert_eq!(diff.after, "new");
47 }
48
49 #[test]
50 fn dry_run_diff_print_and_summary_print_do_not_panic() {
51 let diff = DryRunDiff::new("a = 1\n".to_string(), "a = 2\n".to_string());
52 diff.print();
53
54 DryRunSummary::Format { formatted: 3 }.print();
55 DryRunSummary::Sync {
56 keys: 5,
57 locales: 2,
58 }
59 .print();
60 }
61}