mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Fix formatting of YAML merge key error messages
This commit is contained in:
@@ -347,12 +347,13 @@ impl std::fmt::Display for YamlMergeKeyError {
|
||||
let yaml = to_yaml(&self.value);
|
||||
|
||||
if saphyr::YamlEmitter::new(&mut output).dump(&yaml).is_ok() {
|
||||
// The emitter starts the dumped YAML with ---\n, so strip that.
|
||||
write!(
|
||||
f,
|
||||
"invalid YAML merge key value at line {} column {}: {}",
|
||||
self.value.span.start.line(),
|
||||
self.value.span.start.col(),
|
||||
output
|
||||
output.get(4..).unwrap_or_default()
|
||||
)
|
||||
} else {
|
||||
write!(
|
||||
|
||||
@@ -72,3 +72,49 @@ fn merge_hashes(
|
||||
}
|
||||
hash1
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
mod process_merge_keys {
|
||||
use crate::metadata::parse;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn should_error_if_merge_key_value_has_a_single_value_that_is_not_a_hash() {
|
||||
let yaml = parse(
|
||||
"
|
||||
- &anchor1 test
|
||||
- <<: *anchor1
|
||||
value: test-value-2",
|
||||
);
|
||||
|
||||
let error_message = process_merge_keys(yaml).unwrap_err().to_string();
|
||||
|
||||
assert_eq!(
|
||||
"invalid YAML merge key value at line 3 column 6: test",
|
||||
error_message
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_error_if_merge_key_value_is_an_array_of_non_hash_values() {
|
||||
let yaml = parse(
|
||||
"
|
||||
- &anchor1 {key: test-key}
|
||||
- &anchor2 test
|
||||
- <<: [*anchor1, *anchor2]
|
||||
value: test-value-2",
|
||||
);
|
||||
|
||||
let error_message = process_merge_keys(yaml).unwrap_err().to_string();
|
||||
|
||||
assert_eq!(
|
||||
"invalid YAML merge key value at line 4 column 17: test",
|
||||
error_message
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user