formatter: in tests, use IndexMap to preserve definition order of colors

This commit is contained in:
Yuya Nishihara 2024-12-01 23:50:01 +09:00
parent 1d58bdc8eb
commit 1c7634fcf0
3 changed files with 21 additions and 21 deletions

1
Cargo.lock generated
View file

@ -1849,6 +1849,7 @@ checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f"
dependencies = [
"equivalent",
"hashbrown 0.15.2",
"serde",
]
[[package]]

View file

@ -67,7 +67,7 @@ glob = "0.3.1"
hashbrown = { version = "0.15.2", default-features = false, features = ["inline-more"] }
hex = "0.4.3"
ignore = "0.4.23"
indexmap = "2.7.0"
indexmap = { version = "2.7.0", features = ["serde"] }
indoc = "2.0.4"
insta = { version = "1.41.1", features = ["filters"] }
itertools = "0.13.0"

View file

@ -709,6 +709,7 @@ mod tests {
use std::error::Error as _;
use std::str;
use indexmap::IndexMap;
use indoc::indoc;
use jj_lib::config::ConfigLayer;
use jj_lib::config::ConfigSource;
@ -774,11 +775,10 @@ mod tests {
bright-cyan = 'bright cyan'
bright-white = 'bright white'
"});
// TODO: migrate off config::Config and switch to IndexMap
let colors: HashMap<String, String> = config.get("colors").unwrap();
let colors: IndexMap<String, String> = config.get("colors").unwrap();
let mut output: Vec<u8> = vec![];
let mut formatter = ColorFormatter::for_config(&mut output, &config, false).unwrap();
for (label, color) in colors.iter().sorted() {
for (label, color) in &colors {
formatter.push_label(label).unwrap();
write!(formatter, " {color} ").unwrap();
formatter.pop_label().unwrap();
@ -787,21 +787,21 @@ mod tests {
drop(formatter);
insta::assert_snapshot!(String::from_utf8(output).unwrap(), @r"
 black 
 blue 
 bright black 
 bright blue 
 bright cyan 
 bright green 
 bright magenta 
 bright red 
 bright white 
 bright yellow 
 cyan 
 green 
 magenta 
 red 
 white 
 green 
 yellow 
 blue 
 magenta 
 cyan 
 white 
 bright black 
 bright red 
 bright green 
 bright yellow 
 bright blue 
 bright magenta 
 bright cyan 
 bright white 
");
}
@ -814,11 +814,10 @@ mod tests {
white = '#ffffff'
pastel-blue = '#AFE0D9'
"});
// TODO: migrate off config::Config and switch to IndexMap
let colors: HashMap<String, String> = config.get("colors").unwrap();
let colors: IndexMap<String, String> = config.get("colors").unwrap();
let mut output: Vec<u8> = vec![];
let mut formatter = ColorFormatter::for_config(&mut output, &config, false).unwrap();
for label in colors.keys().sorted() {
for label in colors.keys() {
formatter.push_label(&label.replace(' ', "-")).unwrap();
write!(formatter, " {label} ").unwrap();
formatter.pop_label().unwrap();
@ -827,8 +826,8 @@ mod tests {
drop(formatter);
insta::assert_snapshot!(String::from_utf8(output).unwrap(), @r"
 black 
 pastel-blue 
 white 
 pastel-blue 
");
}