mirror of
https://github.com/YaLTeR/niri.git
synced 2025-10-06 00:23:14 +02:00
config: Add a diff empty to default test
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -2415,6 +2415,7 @@ version = "25.8.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.9.3",
|
"bitflags 2.9.3",
|
||||||
"csscolorparser",
|
"csscolorparser",
|
||||||
|
"diff",
|
||||||
"insta",
|
"insta",
|
||||||
"knuffel",
|
"knuffel",
|
||||||
"miette",
|
"miette",
|
||||||
|
@@ -21,3 +21,4 @@ tracy-client.workspace = true
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
insta.workspace = true
|
insta.workspace = true
|
||||||
pretty_assertions = "1.4.1"
|
pretty_assertions = "1.4.1"
|
||||||
|
diff = "0.1.13"
|
||||||
|
@@ -234,7 +234,7 @@ impl ConfigPath {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use insta::assert_debug_snapshot;
|
use insta::{assert_debug_snapshot, assert_snapshot};
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -1773,4 +1773,103 @@ mod tests {
|
|||||||
}
|
}
|
||||||
"#);
|
"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn diff_lines(expected: &str, actual: &str) -> String {
|
||||||
|
let mut output = String::new();
|
||||||
|
let mut in_change = false;
|
||||||
|
|
||||||
|
for change in diff::lines(expected, actual) {
|
||||||
|
match change {
|
||||||
|
diff::Result::Both(_, _) => {
|
||||||
|
in_change = false;
|
||||||
|
}
|
||||||
|
diff::Result::Left(line) => {
|
||||||
|
if !output.is_empty() && !in_change {
|
||||||
|
output.push('\n');
|
||||||
|
}
|
||||||
|
output.push('-');
|
||||||
|
output.push_str(line);
|
||||||
|
output.push('\n');
|
||||||
|
in_change = true;
|
||||||
|
}
|
||||||
|
diff::Result::Right(line) => {
|
||||||
|
if !output.is_empty() && !in_change {
|
||||||
|
output.push('\n');
|
||||||
|
}
|
||||||
|
output.push('+');
|
||||||
|
output.push_str(line);
|
||||||
|
output.push('\n');
|
||||||
|
in_change = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn diff_empty_to_default() {
|
||||||
|
// We try to write the config defaults in such a way that empty sections (and an empty
|
||||||
|
// config) give the same outcome as the default config bundled with niri. This test
|
||||||
|
// verifies the actual differences between the two.
|
||||||
|
let mut default_config = Config::default();
|
||||||
|
let empty_config = Config::parse("empty.kdl", "").unwrap();
|
||||||
|
|
||||||
|
// Some notable omissions: the default config has some window rules, and an empty config
|
||||||
|
// will not have any binds. Clear them out so they don't spam the diff.
|
||||||
|
default_config.window_rules.clear();
|
||||||
|
default_config.binds.0.clear();
|
||||||
|
|
||||||
|
assert_snapshot!(
|
||||||
|
diff_lines(
|
||||||
|
&format!("{empty_config:#?}"),
|
||||||
|
&format!("{default_config:#?}")
|
||||||
|
),
|
||||||
|
@r#"
|
||||||
|
- numlock: false,
|
||||||
|
+ numlock: true,
|
||||||
|
|
||||||
|
- tap: false,
|
||||||
|
+ tap: true,
|
||||||
|
|
||||||
|
- natural_scroll: false,
|
||||||
|
+ natural_scroll: true,
|
||||||
|
|
||||||
|
- spawn_at_startup: [],
|
||||||
|
+ spawn_at_startup: [
|
||||||
|
+ SpawnAtStartup {
|
||||||
|
+ command: [
|
||||||
|
+ "waybar",
|
||||||
|
+ ],
|
||||||
|
+ },
|
||||||
|
+ ],
|
||||||
|
|
||||||
|
- a: 0.4392157,
|
||||||
|
+ a: 0.46666667,
|
||||||
|
|
||||||
|
- preset_column_widths: [],
|
||||||
|
- default_column_width: None,
|
||||||
|
+ preset_column_widths: [
|
||||||
|
+ Proportion(
|
||||||
|
+ 0.33333,
|
||||||
|
+ ),
|
||||||
|
+ Proportion(
|
||||||
|
+ 0.5,
|
||||||
|
+ ),
|
||||||
|
+ Proportion(
|
||||||
|
+ 0.66667,
|
||||||
|
+ ),
|
||||||
|
+ ],
|
||||||
|
+ default_column_width: Some(
|
||||||
|
+ DefaultPresetSize(
|
||||||
|
+ Some(
|
||||||
|
+ Proportion(
|
||||||
|
+ 0.5,
|
||||||
|
+ ),
|
||||||
|
+ ),
|
||||||
|
+ ),
|
||||||
|
+ ),
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user