FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

ci: increase test coverage by JheisonMB · Pull Request #17 · UniverLab/gitkit · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .lock  (1) .rs  (10) .toml  (1) dotfile  (1) All 4 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
28 changes: 28 additions & 0 deletions .gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,31 @@ skills-lock.json
#/target
*.mp4
.mimocode/

# AI coding agents
.cursor/
.windsurf/
.claude/
.continue/
.copilot/
.kilocode/
.zencoder/
.qwen/

# AI coding agents

# AI coding agents

# AI coding agents

# AI coding agents

# AI coding agents

# AI coding agents

# AI coding agents

# AI coding agents

# AI coding agents
73 changes: 73 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ toml = "0.8"
ureq = "2"

[dev-dependencies]
serial_test = "3.5.0"
tempfile = "3"

[dependencies.inquire]
Expand Down
95 changes: 92 additions & 3 deletions src/attributes/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ pub fn run(cmd: AttributesCommand) -> Result<()> {
Ok(())
}

/// Apply one or more attribute presets by label. Used by the interactive wizard.
pub(crate) fn apply_presets(labels: &[&str]) -> Result<()> {
let root = find_repo_root()?;
/// Apply one or more attribute presets by label at a given root. Used by the interactive wizard.
pub(crate) fn apply_presets_at(labels: &[&str], root: &std::path::Path) -> Result<()> {
let path = root.join(".gitattributes");
let existing = if path.exists() {
fs::read_to_string(&path).unwrap_or_default()
Expand All @@ -91,6 +90,12 @@ pub(crate) fn apply_presets(labels: &[&str]) -> Result<()> {
Ok(())
}

/// Apply presets using CWD to find repo root.
pub(crate) fn apply_presets(labels: &[&str]) -> Result<()> {
let root = find_repo_root()?;
apply_presets_at(labels, &root)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -123,4 +128,88 @@ mod tests {
fn attributes_binary_preset_marks_png() {
assert!(PRESET_BINARY.contains("*.png binary"));
}

#[test]
fn apply_presets_line_endings_writes_content() {
let dir = make_git_repo();
let path = dir.path().join(".gitattributes");
fs::write(&path, "").unwrap();
let result = apply_presets_at(&["line-endings"], dir.path());
assert!(result.is_ok());
let content = fs::read_to_string(&path).unwrap();
assert!(content.contains("eol=lf"));
}

#[test]
fn apply_presets_binary_files_writes_content() {
let dir = make_git_repo();
let path = dir.path().join(".gitattributes");
fs::write(&path, "").unwrap();
let result = apply_presets_at(&["binary-files"], dir.path());
assert!(result.is_ok());
let content = fs::read_to_string(&path).unwrap();
assert!(content.contains("*.png binary"));
}

#[test]
fn apply_presets_both_presets() {
let dir = make_git_repo();
let path = dir.path().join(".gitattributes");
fs::write(&path, "").unwrap();
let result = apply_presets_at(&["line-endings", "binary-files"], dir.path());
assert!(result.is_ok());
let content = fs::read_to_string(&path).unwrap();
assert!(content.contains("eol=lf"));
assert!(content.contains("*.png binary"));
}

#[test]
fn apply_presets_skips_unknown_labels() {
let dir = make_git_repo();
let path = dir.path().join(".gitattributes");
fs::write(&path, "").unwrap();
let result = apply_presets_at(&["unknown-preset"], dir.path());
assert!(result.is_ok());
let content = fs::read_to_string(&path).unwrap();
assert!(content.is_empty());
}

#[test]
fn apply_presets_does_not_duplicate() {
let dir = make_git_repo();
let path = dir.path().join(".gitattributes");
fs::write(&path, "* text=auto eol=lf\n").unwrap();
let result = apply_presets_at(&["line-endings"], dir.path());
assert!(result.is_ok());
let content = fs::read_to_string(&path).unwrap();
assert_eq!(content.matches("eol=lf").count(), 1);
}

#[test]
fn apply_presets_appends_to_existing_content() {
let dir = make_git_repo();
let path = dir.path().join(".gitattributes");
fs::write(&path, "# custom\n*.txt text\n").unwrap();
let result = apply_presets_at(&["line-endings"], dir.path());
assert!(result.is_ok());
let content = fs::read_to_string(&path).unwrap();
assert!(content.contains("# custom"));
assert!(content.contains("*.txt text"));
assert!(content.contains("eol=lf"));
}

#[test]
fn preset_binary_all_expected_extensions() {
let extensions = [
"png", "jpg", "jpeg", "gif", "ico", "pdf", "zip", "tar", "gz", "wasm",
];
for ext in &extensions {
assert!(PRESET_BINARY.contains(&format!("*.{ext} binary")));
}
}

#[test]
fn preset_lf_exact_content() {
assert_eq!(PRESET_LF, "* text=auto eol=lf\n");
}
}
Loading
Loading

Back | FazBrowse Home | New Git URL