Skip to content

Commit

Permalink
tests: add simple parsing unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Piturnah committed Sep 1, 2023
1 parent 80d9797 commit dcb171a
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
profile: minimal
components: clippy, rustfmt
override: true
- name: Check
run: cargo check
- name: Test
run: cargo test
- name: Clippy
run: cargo clippy -- -D warnings
- name: Format
Expand Down
83 changes: 80 additions & 3 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ serde_ignored = "0.1.9"
toml = "0.7.6"
vte = "0.11.1"

[dev-dependencies]
test-case = "3.1.0"

# Tokee
# (Gecko gekko) _____________
# __,---'::.- -::_ _ `-----.___ ______
Expand Down
42 changes: 42 additions & 0 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,45 @@ pub fn parse_hunk_new(header: &str) -> Result<&str> {
.with_context(|| format!("tried to parse strange hunk header: {header}"))?;
Ok(old)
}

#[cfg(test)]
mod tests {
use test_case::test_case;

const ISSUE_62: &str = "diff --git a/asteroid-loop/index.html b/asteroid-loop/index.html
index d79df71..e2d1e9f 100644
--- a/asteroid-loop/index.html
+++ b/asteroid-loop/index.html
@@ -14,15 +14,10 @@
var unityInstance = UnityLoader.instantiate(\"unityContainer\", \"Build/thing build.json\", { onProgress: UnityProgress });
</script>
<script src=\"https://code.jquery.com/jquery-1.10.2.js\"></script>
- <script>
- $(function () {
- $(\"#header\").load(\"/assets/header.html\");
- });
- </script>
</head>
<body>
- <div id=\"header\"></div>
+ <#header />
<div class=\"webgl-content\">
<div id=\"unityContainer\" style=\"width: 960px; height: 540px\"></div>
<div class=\"footer\">
@@ -32,4 +27,4 @@
</div>
</body>
-</html>
\\ No newline at end of file
+</html>";

#[test_case(ISSUE_62 ; "issue 62")]
fn parse(diff: &str) {
let parsed = super::parse_diff(diff);
assert!(parsed.is_ok());
let parsed = parsed.unwrap();
assert_eq!(parsed.len(), 1);
}
}

0 comments on commit dcb171a

Please sign in to comment.