Skip to content

Commit c213563

Browse files
committed
test: add failing test for problem
1 parent 8aad9e0 commit c213563

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

Cargo.lock

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ opt-level = 2
4848

4949
[dev-dependencies]
5050
insta = { version = "1.34.0", features = ["ron", "glob", "yaml"] }
51+
pretty_assertions = "1.4.0"
52+
ron = "0.8.1"
5153
rstest = "0.18.2"
5254

5355
# If you want to use the bleeding edge version of egui and eframe:

src/app.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const SPACE_BETWEEN_TABLES: f32 = 10.;
1414
#[serde(default)] // if we add new fields, give them default values when deserializing old state
1515
pub struct LogViewerApp {
1616
#[serde(skip)]
17-
// TODO 1 Fix issue where if data is included in the save load fails? (Need to check if it is failing and check if we can do a round trip on deserialize then serialize then deserialize)
17+
// TODO 1 Fix issue where if data is included in the load fails
1818
// TODO 2 after fixing issue with serializing and deserializing then change to only a map so access pattern can be consistent
1919
data: Option<Data>,
2020
details_size: f32,

src/app/data.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ use std::collections::BTreeMap;
22

33
use anyhow::Context;
44

5-
#[derive(serde::Deserialize, serde::Serialize, Default, Debug)]
5+
#[derive(serde::Deserialize, serde::Serialize, Default, Debug, PartialEq, Eq)]
66
pub struct Data {
77
pub selected_row: Option<usize>,
88
rows: Vec<LogRow>,
99
}
1010

11-
#[derive(serde::Deserialize, serde::Serialize, Default, Debug)]
11+
#[derive(serde::Deserialize, serde::Serialize, Default, Debug, PartialEq, Eq)]
1212
pub struct LogRow {
1313
time: Option<String>,
1414
request_id: Option<String>,
@@ -80,6 +80,7 @@ impl TryFrom<&str> for Data {
8080
#[cfg(test)]
8181
mod tests {
8282
use insta::glob;
83+
use pretty_assertions::assert_eq;
8384
use rstest::{fixture, rstest};
8485

8586
use super::*;
@@ -104,4 +105,24 @@ mod tests {
104105
insta_settings.bind(|| insta::assert_ron_snapshot!(data));
105106
});
106107
}
108+
109+
#[rstest]
110+
fn round_trip() {
111+
glob!(PATH_PROJECT_ROOT, PATH_TEST_SAMPLES, |path| {
112+
let input = std::fs::read_to_string(path).unwrap();
113+
let rows_before = Data::try_from(&input[..]).unwrap();
114+
115+
// Test single row
116+
for row_before in rows_before.rows() {
117+
let as_ron = ron::to_string(&row_before).unwrap();
118+
let row_after: LogRow = ron::from_str(&dbg!(as_ron)).unwrap();
119+
assert_eq!(&row_after, row_before);
120+
}
121+
122+
// Test all rows
123+
let as_ron = ron::to_string(&rows_before).unwrap();
124+
let rows_after: Data = ron::from_str(&dbg!(as_ron)).unwrap();
125+
assert_eq!(rows_after, rows_before);
126+
});
127+
}
107128
}

0 commit comments

Comments
 (0)