feat: Add support for new OS package
Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
- Add a new `sal-os` package containing OS interaction utilities. - Update workspace members to include the new package. - Add README and basic usage examples for the new package.
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
//! Unit tests for text replacement functionality
|
||||
//!
|
||||
//! These tests validate the TextReplacer and TextReplacerBuilder including:
|
||||
//! These tests validate the TextReplacer including:
|
||||
//! - Literal string replacement
|
||||
//! - Regex pattern replacement
|
||||
//! - Multiple chained replacements
|
||||
//! - File operations (read, write, in-place)
|
||||
//! - Error handling and edge cases
|
||||
|
||||
use sal_text::{TextReplacer, TextReplacerBuilder};
|
||||
use sal_text::TextReplacer;
|
||||
use std::fs;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
@@ -141,7 +141,7 @@ fn test_text_replacer_no_matches() {
|
||||
#[test]
|
||||
fn test_text_replacer_file_operations() {
|
||||
// Create a temporary file with test content
|
||||
let mut temp_file = NamedTempFile::new().expect("Failed to create temp file");
|
||||
let temp_file = NamedTempFile::new().expect("Failed to create temp file");
|
||||
let test_content = "Hello world, there are 123 items";
|
||||
fs::write(temp_file.path(), test_content).expect("Failed to write to temp file");
|
||||
|
||||
@@ -157,18 +157,21 @@ fn test_text_replacer_file_operations() {
|
||||
.expect("Failed to build replacer");
|
||||
|
||||
// Test replace_file
|
||||
let result = replacer.replace_file(temp_file.path()).expect("Failed to replace file content");
|
||||
let result = replacer
|
||||
.replace_file(temp_file.path())
|
||||
.expect("Failed to replace file content");
|
||||
assert_eq!(result, "Hello universe, there are NUMBER items");
|
||||
|
||||
// Verify original file is unchanged
|
||||
let original_content = fs::read_to_string(temp_file.path()).expect("Failed to read original file");
|
||||
let original_content =
|
||||
fs::read_to_string(temp_file.path()).expect("Failed to read original file");
|
||||
assert_eq!(original_content, test_content);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_text_replacer_file_in_place() {
|
||||
// Create a temporary file with test content
|
||||
let mut temp_file = NamedTempFile::new().expect("Failed to create temp file");
|
||||
let temp_file = NamedTempFile::new().expect("Failed to create temp file");
|
||||
let test_content = "Hello world, there are 123 items";
|
||||
fs::write(temp_file.path(), test_content).expect("Failed to write to temp file");
|
||||
|
||||
@@ -180,7 +183,9 @@ fn test_text_replacer_file_in_place() {
|
||||
.expect("Failed to build replacer");
|
||||
|
||||
// Test replace_file_in_place
|
||||
replacer.replace_file_in_place(temp_file.path()).expect("Failed to replace file in place");
|
||||
replacer
|
||||
.replace_file_in_place(temp_file.path())
|
||||
.expect("Failed to replace file in place");
|
||||
|
||||
// Verify file content was changed
|
||||
let new_content = fs::read_to_string(temp_file.path()).expect("Failed to read modified file");
|
||||
@@ -190,7 +195,7 @@ fn test_text_replacer_file_in_place() {
|
||||
#[test]
|
||||
fn test_text_replacer_file_to_file() {
|
||||
// Create source file
|
||||
let mut source_file = NamedTempFile::new().expect("Failed to create source file");
|
||||
let source_file = NamedTempFile::new().expect("Failed to create source file");
|
||||
let test_content = "Hello world, there are 123 items";
|
||||
fs::write(source_file.path(), test_content).expect("Failed to write to source file");
|
||||
|
||||
@@ -205,11 +210,13 @@ fn test_text_replacer_file_to_file() {
|
||||
.expect("Failed to build replacer");
|
||||
|
||||
// Test replace_file_to
|
||||
replacer.replace_file_to(source_file.path(), dest_file.path())
|
||||
replacer
|
||||
.replace_file_to(source_file.path(), dest_file.path())
|
||||
.expect("Failed to replace file to destination");
|
||||
|
||||
// Verify source file is unchanged
|
||||
let source_content = fs::read_to_string(source_file.path()).expect("Failed to read source file");
|
||||
let source_content =
|
||||
fs::read_to_string(source_file.path()).expect("Failed to read source file");
|
||||
assert_eq!(source_content, test_content);
|
||||
|
||||
// Verify destination file has replaced content
|
||||
@@ -263,9 +270,10 @@ fn test_text_replacer_multiline_text() {
|
||||
.build()
|
||||
.expect("Failed to build replacer");
|
||||
|
||||
let input = "function test() {\n // This is a comment\n return true;\n // Another comment\n}";
|
||||
let input =
|
||||
"function test() {\n // This is a comment\n return true;\n // Another comment\n}";
|
||||
let result = replacer.replace(input);
|
||||
|
||||
|
||||
// Note: This test depends on how the regex engine handles multiline mode
|
||||
// The actual behavior might need adjustment based on regex flags
|
||||
assert!(result.contains("function test()"));
|
||||
@@ -288,7 +296,7 @@ fn test_text_replacer_unicode_text() {
|
||||
#[test]
|
||||
fn test_text_replacer_large_text() {
|
||||
let large_text = "word ".repeat(10000);
|
||||
|
||||
|
||||
let replacer = TextReplacer::builder()
|
||||
.pattern("word")
|
||||
.replacement("term")
|
||||
|
Reference in New Issue
Block a user