Skip to content

Commit 140d9a9

Browse files
authored
Add test gh action (#16)
* add test gh action * oops * clippy * fmt
1 parent 9949044 commit 140d9a9

File tree

11 files changed

+57
-23
lines changed

11 files changed

+57
-23
lines changed

.github/workflows/test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
test:
14+
name: Run tests
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Install Rust toolchain
20+
uses: dtolnay/rust-toolchain@stable
21+
22+
- name: Cache dependencies
23+
uses: Swatinem/rust-cache@v2
24+
25+
- name: Run tests
26+
run: cargo test --verbose
27+
28+
- name: Run clippy
29+
run: cargo clippy -- -D warnings
30+
31+
- name: Check formatting
32+
run: cargo fmt -- --check

build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn main() {
3838
code.push_str("pub static SOURCE_EXTENSIONS: Lazy<HashSet<&'static str>> = Lazy::new(|| {\n");
3939
code.push_str(" let mut set = HashSet::new();\n\n");
4040

41-
for (_, lang) in &languages {
41+
for lang in languages.values() {
4242
for ext in &lang.extensions {
4343
let ext = ext.trim_start_matches('.');
4444
code.push_str(&format!(" set.insert(\"{}\");\n", ext));
@@ -52,7 +52,7 @@ fn main() {
5252
code.push_str("pub static KNOWN_FILENAMES: Lazy<HashSet<&'static str>> = Lazy::new(|| {\n");
5353
code.push_str(" let mut set = HashSet::new();\n\n");
5454

55-
for (_, lang) in &languages {
55+
for lang in languages.values() {
5656
for filename in &lang.filenames {
5757
code.push_str(&format!(" set.insert(\"{}\");\n", filename));
5858
}
@@ -65,7 +65,7 @@ fn main() {
6565
code.push_str("pub static INTERPRETER_NAMES: Lazy<HashSet<&'static str>> = Lazy::new(|| {\n");
6666
code.push_str(" let mut set = HashSet::new();\n\n");
6767

68-
for (_, lang) in &languages {
68+
for lang in languages.values() {
6969
for interpreter in &lang.interpreters {
7070
code.push_str(&format!(" set.insert(\"{}\");\n", interpreter));
7171
}

src/analyzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn process_directory(args: &Cli) -> Result<()> {
3333
.output
3434
.clone()
3535
.expect("output format should be set from config");
36-
let entries = process_entries(&args)?;
36+
let entries = process_entries(args)?;
3737
pb.finish();
3838

3939
if let Some(pdf_path) = &args.pdf {

src/cli.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ impl Cli {
178178
}
179179
}
180180

181-
182181
fn parse_exclude(value: &str) -> Result<Exclude, String> {
183182
let path = PathBuf::from(value);
184183
if path.exists() {

src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ impl<'de> Deserialize<'de> for BackwardsCompatOutputFormat {
3636
let format = match s.to_lowercase().as_str() {
3737
"tree" => OutputFormat::Tree,
3838
"files" => OutputFormat::Files,
39-
"both" | _ => OutputFormat::Both, // Default to Both for unknown values
39+
"both" => OutputFormat::Both,
40+
_ => OutputFormat::Both, // Default to Both for unknown values
4041
};
4142
Ok(BackwardsCompatOutputFormat(format))
4243
}

src/file_picker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl FilePicker {
208208
if !self.show_hidden
209209
&& path
210210
.file_name()
211-
.map_or(false, |n| n.to_string_lossy().starts_with('.'))
211+
.is_some_and(|n| n.to_string_lossy().starts_with('.'))
212212
{
213213
continue;
214214
}

src/git_processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl GitProcessor {
1919
let parsed_url = Url::parse(url)?;
2020
let repo_name = parsed_url
2121
.path_segments()
22-
.and_then(|segments| segments.last())
22+
.and_then(|mut segments| segments.next_back())
2323
.map(|name| name.trim_end_matches(".git"))
2424
.unwrap_or("repo")
2525
.to_string();

src/main.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ fn main() -> anyhow::Result<()> {
6666
} else {
6767
// Process only the specified subpaths inside the repo
6868
let mut new_args = args.clone();
69-
new_args.paths = subpaths.iter().map(|sub| {
70-
// Join with repo_path
71-
let mut joined = std::path::PathBuf::from(&repo_path);
72-
joined.push(sub);
73-
joined.to_string_lossy().to_string()
74-
}).collect();
69+
new_args.paths = subpaths
70+
.iter()
71+
.map(|sub| {
72+
// Join with repo_path
73+
let mut joined = std::path::PathBuf::from(&repo_path);
74+
joined.push(sub);
75+
joined.to_string_lossy().to_string()
76+
})
77+
.collect();
7578
new_args
7679
};
7780
process_directory(&process_args)?;

src/output.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ pub fn generate_pdf(entries: &[FileEntry], format: OutputFormat) -> Result<Vec<u
201201
// New page for files
202202
let (next_page, next_layer) = doc.add_page(Mm(210.0), Mm(297.0), "New Layer");
203203
current_layer = doc.get_page(next_page).get_layer(next_layer);
204-
y_position = 280.0;
205204
}
206205
_ => {}
207206
}
@@ -212,7 +211,7 @@ pub fn generate_pdf(entries: &[FileEntry], format: OutputFormat) -> Result<Vec<u
212211

213212
// Add file path as header
214213
current_layer.use_text(
215-
&format!("File: {}", entry.path.display()),
214+
format!("File: {}", entry.path.display()),
216215
14.0,
217216
Mm(10.0),
218217
Mm(y_position),
@@ -221,7 +220,7 @@ pub fn generate_pdf(entries: &[FileEntry], format: OutputFormat) -> Result<Vec<u
221220
y_position -= 10.0;
222221

223222
// Add separator line
224-
current_layer.use_text(&"=".repeat(48), 12.0, Mm(10.0), Mm(y_position), &font);
223+
current_layer.use_text("=".repeat(48), 12.0, Mm(10.0), Mm(y_position), &font);
225224
y_position -= 10.0;
226225

227226
// Add file content in smaller font

src/source_detection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include!(concat!(env!("OUT_DIR"), "/languages.rs"));
88
fn extract_interpreter(data: &str) -> Option<String> {
99
let lines: Vec<&str> = data.lines().take(2).collect();
1010

11-
if !lines.get(0).map_or(false, |l| l.starts_with("#!")) {
11+
if !lines.first().is_some_and(|l| l.starts_with("#!")) {
1212
return None;
1313
}
1414

@@ -33,7 +33,7 @@ fn extract_interpreter(data: &str) -> Option<String> {
3333
return None;
3434
}
3535

36-
let mut script = first_part.split('/').last()?.to_string();
36+
let mut script = first_part.split('/').next_back()?.to_string();
3737

3838
// Handle /usr/bin/env
3939
if script == "env" {

0 commit comments

Comments
 (0)