mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-22 04:37:46 +00:00
Fix EXL writing test by preserving the order
This commit is contained in:
parent
cece5936e8
commit
56a738fde7
1 changed files with 11 additions and 7 deletions
18
src/exl.rs
18
src/exl.rs
|
@ -12,7 +12,7 @@ pub struct EXL {
|
||||||
pub version: i32,
|
pub version: i32,
|
||||||
|
|
||||||
/// The entries of the list.
|
/// The entries of the list.
|
||||||
pub entries: HashMap<String, i32>,
|
pub entries: Vec<(String, i32)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EXL {
|
impl EXL {
|
||||||
|
@ -20,7 +20,7 @@ impl EXL {
|
||||||
pub fn from_existing(buffer: &MemoryBuffer) -> Option<EXL> {
|
pub fn from_existing(buffer: &MemoryBuffer) -> Option<EXL> {
|
||||||
let mut exl = Self {
|
let mut exl = Self {
|
||||||
version: 0,
|
version: 0,
|
||||||
entries: HashMap::new(),
|
entries: Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let cursor = Cursor::new(buffer);
|
let cursor = Cursor::new(buffer);
|
||||||
|
@ -37,7 +37,7 @@ impl EXL {
|
||||||
if name == "EXLT" {
|
if name == "EXLT" {
|
||||||
exl.version = parsed_value;
|
exl.version = parsed_value;
|
||||||
} else {
|
} else {
|
||||||
exl.entries.insert(name.parse().unwrap(), parsed_value);
|
exl.entries.push((name.parse().unwrap(), parsed_value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,10 +51,10 @@ impl EXL {
|
||||||
let cursor = Cursor::new(&mut buffer);
|
let cursor = Cursor::new(&mut buffer);
|
||||||
let mut writer = BufWriter::new(cursor);
|
let mut writer = BufWriter::new(cursor);
|
||||||
|
|
||||||
writer.write(format!("EXLT,{}", self.version).as_ref());
|
writer.write_all(format!("EXLT,{}", self.version).as_ref()).ok()?;
|
||||||
|
|
||||||
for entry in &self.entries {
|
for (key, value) in &self.entries {
|
||||||
writer.write(format!("\n{},{}", entry.0, entry.1).as_ref());
|
writer.write_all(format!("\n{key},{value}").as_ref()).ok()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ impl EXL {
|
||||||
/// exl.contains("Foo");
|
/// exl.contains("Foo");
|
||||||
/// ```
|
/// ```
|
||||||
pub fn contains(&self, key: &str) -> bool {
|
pub fn contains(&self, key: &str) -> bool {
|
||||||
self.entries.contains_key(key)
|
self.entries.iter().any(|t| t.0 == key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +123,10 @@ mod tests {
|
||||||
|
|
||||||
let exl = read(d).unwrap();
|
let exl = read(d).unwrap();
|
||||||
|
|
||||||
|
let mut out = std::io::stdout();
|
||||||
|
out.write_all(&existing_exl.write_to_buffer().unwrap());
|
||||||
|
out.flush();
|
||||||
|
|
||||||
assert_eq!(existing_exl.write_to_buffer().unwrap(), exl);
|
assert_eq!(existing_exl.write_to_buffer().unwrap(), exl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue