#![allow(missing_docs)]
use assert_cmd::Command;
use predicates::prelude::*;
use std::fs;
use std::path::PathBuf;
fn ruchy_cmd() -> Command {
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
}
fn test_code(code: &str) {
use std::thread;
use std::time::{SystemTime, UNIX_EPOCH};
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_nanos();
let thread_id = thread::current().id();
let temp_file = PathBuf::from(format!("/tmp/test_pub_mod_{timestamp}_{thread_id:?}.ruchy"));
fs::write(&temp_file, code).expect("Failed to write temp file");
ruchy_cmd()
.arg("check")
.arg(&temp_file)
.assert()
.success()
.stdout(predicate::str::contains("Syntax is valid"));
let _ = fs::remove_file(&temp_file);
}
#[test]
fn test_pub_mod_basic() {
test_code(
r"
pub mod utils {
fn helper() {}
}
",
);
}
#[test]
fn test_pub_mod_nested() {
test_code(
r"
mod graphics {
pub mod shapes {
pub fn draw_circle() {}
}
}
",
);
}
#[test]
fn test_pub_mod_empty() {
test_code(
r"
pub mod empty {}
",
);
}
#[test]
fn test_pub_mod_with_functions() {
test_code(
r"
pub mod network {
fn connect() {}
pub fn public_function() {}
}
",
);
}
#[test]
fn test_regular_mod_still_works() {
test_code(
r"
mod private {
fn helper() {}
}
",
);
}