test(config-render): cover the edges mutation testing found untested

The moved rules kept these changes undetected: a string provider DNS field being ignored or an empty one counted, a wider or empty gap after short-id disturbing the quoting, an unchanged scalar beside a numeric short-id rejecting the quoted result, and quoting leaking outside the fake-ip-filter block or at a deeper indentation. Each new test fails under its mutant and passes against the unchanged code.
This commit is contained in:
Tunglies
2026-12-06 16:03:27 +08:00
parent 91e091daec
commit 80aad98358
2 changed files with 50 additions and 0 deletions
@@ -120,4 +120,13 @@ mod tests {
"tun: {enable: true}\ndns: {enable: false, enhanced-mode: fake-ip}"
)));
}
#[test]
fn override_source_accepts_a_string_field_only_when_it_has_content() -> Result<(), serde_json::Error> {
let config = mapping("dns: {proxy-server-nameserver: ' 1.1.1.1 '}");
assert!(override_source("profile", &config)?.is_some());
let config = mapping("dns: {nameserver-policy: ' '}");
assert!(override_source("profile", &config)?.is_none());
Ok(())
}
}
@@ -218,4 +218,45 @@ note: |
assert_eq!(roundtrip(&out), roundtrip(yaml));
assert!(out.contains("'+.market.xiaomi.com'"));
}
#[test]
fn unchanged_scalars_beside_a_numeric_short_id_keep_the_quoted_result() {
let value = parse_short_id_safe(
"proxies:\n - name: a\n reality-opts:\n short-id: 1234e123\n",
Path::new("profile.yaml"),
)
.expect("profile should parse");
let proxy = &value["proxies"].as_sequence().expect("sequence")[0];
assert_eq!(proxy["name"], Value::String("a".into()));
assert_eq!(proxy["reality-opts"]["short-id"], Value::String("1234e123".into()));
}
#[test]
fn wider_whitespace_and_empty_short_ids_do_not_disturb_the_quoting() {
let value = parse_short_id_safe(
"tunnels:\n - short-id: 1234e123\n - short-id:\t\n - short-id: 0e5\n",
Path::new("p.yaml"),
)
.expect("yaml");
let tunnels = value["tunnels"].as_sequence().expect("sequence");
assert_eq!(tunnels[0]["short-id"], Value::String("1234e123".into()));
assert_eq!(tunnels[1]["short-id"], Value::Null);
assert_eq!(tunnels[2]["short-id"], Value::String("0e5".into()));
}
#[test]
fn wildcards_outside_fake_ip_filter_are_left_alone() {
let yaml = "\ndns:\n fake-ip-filter:\n - .example.com\n fake-ip-filter-mode: blacklist\nsniffer:\n skip-domain:\n - +.push.apple.com\n";
let out = serialize_for_export(&serde_yaml_ng::from_str::<Value>(yaml).expect("yaml")).expect("yaml");
assert_eq!(roundtrip(&out), roundtrip(yaml));
assert!(out.contains(" - '.example.com'\n"), "{out}");
assert!(out.contains(" - +.push.apple.com\n"), "{out}");
}
#[test]
fn quoting_follows_the_block_indentation() {
let yaml = "\nwrap:\n dns:\n fake-ip-filter:\n - +.market.xiaomi.com\n";
let out = serialize_for_export(&serde_yaml_ng::from_str::<Value>(yaml).expect("yaml")).expect("yaml");
assert!(out.contains(" - '+.market.xiaomi.com'\n"), "{out}");
}
}