This commit is contained in:
2025-04-05 04:45:56 +02:00
parent 9f33c94020
commit e48063a79c
22 changed files with 2661 additions and 1384 deletions

View File

@@ -17,9 +17,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Print a header
print("=== Testing Git Module Functions ===\n");
// Test git_list function
print("Listing git repositories...");
let repos = git_list();
// Create a new GitTree object
let home_dir = env("HOME");
let git_tree = gittree_new(`${home_dir}/code`);
print(`Created GitTree with base path: ${home_dir}/code`);
// Test list method
print("\nListing git repositories...");
let repos = git_tree.list();
print(`Found ${repos.len()} repositories`);
// Print the first few repositories
@@ -31,7 +36,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
// Test find_matching_repos function
// Test find method
if repos.len() > 0 {
print("\nTesting repository search...");
// Extract a part of the first repo name to search for
@@ -40,17 +45,35 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let repo_name = parts[parts.len() - 1];
print(`Searching for repositories containing "${repo_name}"`);
let matching = find_matching_repos(repo_name);
let matching = git_tree.find(repo_name + "*");
print(`Found ${matching.len()} matching repositories`);
for repo in matching {
print(` - ${repo}`);
}
// Check if a repository has changes
print("\nChecking for changes in repository...");
let has_changes = git_has_changes(repo_path);
print(`Repository ${repo_path} has changes: ${has_changes}`);
// Test get method
print("\nTesting get method...");
let git_repos = git_tree.get(repo_name);
print(`Found ${git_repos.len()} GitRepo objects`);
// Test GitRepo methods
if git_repos.len() > 0 {
let git_repo = git_repos[0];
print(`\nTesting GitRepo methods on: ${git_repo.path()}`);
// Check if a repository has changes
print("Checking for changes in repository...");
let has_changes = git_repo.has_changes();
print(`Repository has changes: ${has_changes}`);
// Test method chaining (only if there are no changes to avoid errors)
if !has_changes {
print("\nTesting method chaining (pull)...");
let result = git_repo.pull();
print("Pull operation completed successfully");
}
}
}
print("\n=== Git Module Test Complete ===");

View File

@@ -17,9 +17,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Print a header
print("=== Testing Git Module Functions ===\n");
// Test git_list function
print("Listing git repositories...");
let repos = git_list();
// Create a new GitTree object
let home_dir = env("HOME");
let git_tree = gittree_new(`${home_dir}/code`);
print(`Created GitTree with base path: ${home_dir}/code`);
// Test list method
print("\nListing git repositories...");
let repos = git_tree.list();
print(`Found ${repos.len()} repositories`);
// Print the first few repositories
@@ -31,7 +36,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
// Test find_matching_repos function
// Test find method
if repos.len() > 0 {
print("\nTesting repository search...");
// Extract a part of the first repo name to search for
@@ -40,17 +45,35 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let repo_name = parts[parts.len() - 1];
print(`Searching for repositories containing "${repo_name}"`);
let matching = find_matching_repos(repo_name);
let matching = git_tree.find(repo_name + "*");
print(`Found ${matching.len()} matching repositories`);
for repo in matching {
print(` - ${repo}`);
}
// Check if a repository has changes
print("\nChecking for changes in repository...");
let has_changes = git_has_changes(repo_path);
print(`Repository ${repo_path} has changes: ${has_changes}`);
// Test get method
print("\nTesting get method...");
let git_repos = git_tree.get(repo_name);
print(`Found ${git_repos.len()} GitRepo objects`);
// Test GitRepo methods
if git_repos.len() > 0 {
let git_repo = git_repos[0];
print(`\nTesting GitRepo methods on: ${git_repo.path()}`);
// Check if a repository has changes
print("Checking for changes in repository...");
let has_changes = git_repo.has_changes();
print(`Repository has changes: ${has_changes}`);
// Test method chaining (only if there are no changes to avoid errors)
if !has_changes {
print("\nTesting method chaining (pull)...");
let result = git_repo.pull();
print("Pull operation completed successfully");
}
}
}
print("\n=== Git Module Test Complete ===");

View File

@@ -0,0 +1,27 @@
//! Example of running the test_git.rhai script
//!
//! This example demonstrates how to run the test_git.rhai script
//! through the Rhai scripting engine.
use sal::rhai::{self, Engine};
use std::fs;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
// Create a new Rhai engine
let mut engine = Engine::new();
// Register SAL functions with the engine
rhai::register(&mut engine)?;
// Read the test script
let script = fs::read_to_string("src/test_git.rhai")?;
// Evaluate the script
match engine.eval::<()>(&script) {
Ok(_) => println!("Script executed successfully"),
Err(e) => eprintln!("Script execution error: {}", e),
}
Ok(())
}

View File

@@ -0,0 +1,27 @@
//! Simple example of using the Git module with Rhai
//!
//! This example demonstrates how to use the Git module functions
//! through the Rhai scripting language.
use sal::rhai::{self, Engine};
use std::fs;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
// Create a new Rhai engine
let mut engine = Engine::new();
// Register SAL functions with the engine
rhai::register(&mut engine)?;
// Read the test script
let script = fs::read_to_string("simple_git_test.rhai")?;
// Evaluate the script
match engine.eval::<()>(&script) {
Ok(_) => println!("Script executed successfully"),
Err(e) => eprintln!("Script execution error: {}", e),
}
Ok(())
}