Skip to content

Commit

Permalink
formatter: in tests, use IndexMap to preserve definition order of colors
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Dec 9, 2024
1 parent 8080981 commit 061adac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
33 changes: 16 additions & 17 deletions cli/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -787,21 +787,21 @@ mod tests {
drop(formatter);
insta::assert_snapshot!(String::from_utf8(output).unwrap(), @r"
 black 
 red 
 green 
 yellow 
 blue 
 magenta 
 cyan 
 white 
 bright black 
 bright blue 
 bright cyan 
 bright red 
 bright green 
 bright yellow 
 bright blue 
 bright magenta 
[38;5;9m bright red [39m
[38;5;14m bright cyan [39m
 bright white 
 bright yellow 
 cyan 
 green 
 magenta 
 red 
 white 
 yellow 
");
}

Expand All @@ -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();
Expand All @@ -827,8 +826,8 @@ mod tests {
drop(formatter);
insta::assert_snapshot!(String::from_utf8(output).unwrap(), @r"
 black 
 pastel-blue 
 white 
 pastel-blue 
");
}

Expand Down

0 comments on commit 061adac

Please sign in to comment.