use ahk::desktop::{
Clipboard, Com, Desktop, Dialogs, Files, Folders, Hotkeys, Idle, Keyboard, Machine, Native,
Network, Pictures, Pointer, Processes, Screen, Sound, Timers, Windows,
};
use ahk::parse;
use ahk::runtime::{Report, Runtime};
use std::time::Duration;
#[derive(Debug)]
struct Fake {
clipboard: String,
folders: Folders,
working_dir: String,
cursor: Result<String, String>,
script_window: Result<i64, String>,
}
fn the_folders() -> Folders {
Folders {
app_data: Some("/home/<user>/.local/share".to_string()),
app_data_common: Some("/usr/share".to_string()),
desktop: Some("/home/<user>/Desktop".to_string()),
desktop_common: None,
start_menu: Some("/home/<user>/.local/share/applications".to_string()),
start_menu_common: Some("/usr/share/applications".to_string()),
programs: Some("/home/<user>/.local/share/applications".to_string()),
programs_common: Some("/usr/share/applications".to_string()),
startup: Some("/home/<user>/.config/autostart".to_string()),
startup_common: Some("/etc/xdg/autostart".to_string()),
my_documents: Some("/home/<user>/Documents".to_string()),
temp: Some("/tmp".to_string()),
}
}
impl Default for Fake {
fn default() -> Self {
Fake {
clipboard: String::new(),
folders: the_folders(),
working_dir: "/work".to_string(),
cursor: Ok("Arrow".to_string()),
script_window: Ok(6557770),
}
}
}
impl Desktop for Fake {}
impl Pictures for Fake {}
impl Network for Fake {}
impl Sound for Fake {}
impl Machine for Fake {
fn executable(&mut self) -> Result<String, String> {
Ok("/usr/bin/ahk".to_string())
}
fn user_name(&mut self) -> Result<String, String> {
Ok("<user>".to_string())
}
fn computer_name(&mut self) -> Result<String, String> {
Ok("<host>".to_string())
}
fn shell(&mut self) -> Result<String, String> {
Ok("/usr/bin/zsh".to_string())
}
fn folders(&mut self) -> Result<Folders, String> {
Ok(self.folders.clone())
}
fn os_version(&mut self) -> Result<String, String> {
Ok("<kernel>".to_string())
}
fn language(&mut self) -> Result<String, String> {
Ok("en_US.UTF-8".to_string())
}
fn is_admin(&mut self) -> Result<bool, String> {
Ok(false)
}
fn idle_times(&mut self) -> Result<Idle, String> {
Ok(Idle {
any: 1000,
physical: 2000,
keyboard: 3000,
mouse: 4000,
})
}
fn program_files(&mut self) -> Result<String, String> {
Ok("C:\\Program Files".to_string())
}
fn windows_directory(&mut self) -> Result<String, String> {
Ok("C:\\Windows".to_string())
}
}
impl Dialogs for Fake {}
impl Files for Fake {
fn working_directory(&mut self) -> Result<String, String> {
Ok(self.working_dir.clone())
}
fn initial_working_directory(&mut self) -> Result<String, String> {
Ok("/work".to_string())
}
fn set_working_directory(&mut self, directory: &str) -> Result<String, String> {
self.working_dir = directory.to_string();
Ok(format!("the working directory is now {directory}"))
}
}
impl Clipboard for Fake {
fn clipboard_read(&mut self) -> Result<String, String> {
Ok(self.clipboard.clone())
}
fn clipboard_write(&mut self, text: &str) -> Result<String, String> {
self.clipboard = text.to_string();
Ok(text.to_string())
}
}
impl Timers for Fake {}
impl Hotkeys for Fake {}
impl Windows for Fake {
fn script_window(&mut self) -> Result<i64, String> {
self.script_window.clone()
}
}
impl Keyboard for Fake {
fn type_text(&mut self, _text: &str) -> Result<String, String> {
Ok(String::new())
}
fn press_key(&mut self, _name: &str, _modifiers: &[String]) -> Result<String, String> {
Ok(String::new())
}
}
impl Pointer for Fake {
fn cursor_shape(&mut self) -> Result<String, String> {
self.cursor.clone()
}
fn click(&mut self, _x: i64, _y: i64, _button: &str, _count: u32) -> Result<String, String> {
Ok(String::new())
}
}
impl Screen for Fake {
fn capture(
&mut self,
_x: i64,
_y: i64,
_width: i64,
_height: i64,
_filename: &str,
) -> Result<String, String> {
Ok(String::new())
}
fn pixel(&mut self, _x: i64, _y: i64) -> Result<String, String> {
Ok(String::new())
}
fn screen_size(&mut self) -> Result<(i64, i64), String> {
Ok((1920, 1080))
}
}
impl Processes for Fake {
fn run(&mut self, _command: &str, _window: &str) -> Result<(i32, String, String), String> {
Ok((0, String::new(), String::new()))
}
}
impl Native for Fake {}
impl Com for Fake {}
fn run(script: &str) -> Report {
run_with(Fake::default(), script)
}
fn run_with(desktop: Fake, script: &str) -> Report {
let statements = parse(script).expect("parses");
let mut desktop = desktop;
Runtime::new(&mut desktop, Duration::from_secs(10)).run(&statements)
}
fn run_with_a_file(script: &str, path: &str) -> Report {
let statements = parse(script).expect("parses");
let mut desktop = Fake::default();
Runtime::new(&mut desktop, Duration::from_secs(10))
.with_script_path(path)
.run(&statements)
}
#[test]
fn the_names_of_the_script_are_the_names_of_the_file() {
let report = run_with_a_file(
"FileAppend A_ScriptFullPath \"|\" A_ScriptName \"|\" A_ScriptDir, \"*\"",
"C:\\scripts\\the one.ahk",
);
assert!(report.ok, "{:?}", report.error);
assert_eq!(
report.output,
vec!["C:\\scripts\\the one.ahk|the one.ahk|C:\\scripts".to_string()]
);
}
#[test]
fn the_file_of_the_line_is_the_script_of_the_run() {
let report = run("MsgBox A_LineFile \"|\" A_ScriptFullPath");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["*|*"]);
}
#[test]
fn the_line_of_the_statement_and_the_name_of_the_function_that_runs() {
let report = run("x := 1\nFileAppend A_LineNumber, \"*\"");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["2".to_string()]);
let report = run("f() {\n FileAppend A_ThisFunc, \"*\"\n}\nf()");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["f".to_string()]);
let report = run("f() {\n FileAppend A_LineNumber, \"*\"\n}\nf()");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["2".to_string()]);
let report = run("FileAppend A_ThisFunc, \"*\"");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["".to_string()]);
}
fn run_with_clipboard(script: &str, clipboard: &str) -> (Report, String) {
let statements = parse(script).expect("parses");
let mut desktop = Fake {
clipboard: clipboard.to_string(),
..Fake::default()
};
let report = Runtime::new(&mut desktop, Duration::from_secs(10)).run(&statements);
(report, desktop.clipboard)
}
#[test]
fn a_script_that_asks_for_the_version_is_told_the_version_of_the_dialect() {
let report = run("MsgBox A_AhkVersion");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["2.0.32"]);
}
#[test]
fn a_script_that_asks_for_the_size_of_the_screen_is_told_it() {
let report = run("MsgBox A_ScreenWidth \", \" A_ScreenHeight");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["1920, 1080"]);
}
#[test]
fn a_script_that_asks_for_the_space_is_told_a_space() {
let report = run("MsgBox A_Space");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec![" "]);
}
#[test]
fn a_script_that_asks_for_the_tick_count_is_told_a_number_of_milliseconds() {
let report = run("MsgBox A_TickCount");
assert!(report.ok, "{:?}", report.error);
assert!(
report.output[0].parse::<u64>().is_ok(),
"{:?}",
report.output
);
}
#[test]
fn a_script_that_asks_for_the_date_is_told_the_date() {
let report = run("MsgBox A_Now");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output[0].len(), 14);
}
#[test]
fn a_name_of_the_machine_answers_with_the_value_of_the_desktop() {
let report = run("MsgBox A_UserName \", \" A_ComputerName \", \" A_ComSpec \", \" A_Language");
assert!(report.ok, "{:?}", report.error);
assert_eq!(
report.output,
vec!["<user>, <host>, /usr/bin/zsh, en_US.UTF-8"]
);
}
#[test]
fn the_path_of_the_interpreter_is_the_path_of_the_executable() {
let report = run("MsgBox A_AhkPath");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["/usr/bin/ahk"]);
}
#[test]
fn a_script_that_asks_whether_it_is_elevated_is_told_a_number() {
let report = run("MsgBox A_IsAdmin");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["0"]);
}
#[test]
fn an_idle_time_answers_with_the_milliseconds_of_the_desktop() {
let report = run(
"MsgBox A_TimeIdle \", \" A_TimeIdlePhysical \", \" A_TimeIdleKeyboard \", \" A_TimeIdleMouse",
);
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["1000, 2000, 3000, 4000"]);
}
#[test]
fn a_folder_of_the_machine_answers_with_the_folder() {
let report = run("MsgBox A_Desktop \", \" A_Temp \", \" A_MyDocuments");
assert!(report.ok, "{:?}", report.error);
assert_eq!(
report.output,
vec!["/home/<user>/Desktop, /tmp, /home/<user>/Documents"]
);
}
#[test]
fn a_folder_that_the_machine_does_not_have_refuses_with_the_reason_of_the_name() {
let report = run("MsgBox A_DesktopCommon");
assert!(!report.ok);
assert_eq!(
report.error.as_deref(),
Some(
"the machine has no desktop for everybody: the desktop of the session is the one of the user."
)
);
assert_eq!(report.error_line, Some(1));
}
#[test]
fn the_working_directory_answers_with_the_directory_of_the_desktop() {
let report = run("MsgBox A_WorkingDir");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["/work"]);
}
#[test]
fn a_name_of_windows_refuses_with_the_reason_of_the_contract() {
let report = run("MsgBox A_WinDir");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["C:\\Windows"]);
}
#[test]
fn the_settings_that_the_runtime_keeps_answer_with_the_value_of_v2() {
let report = run(
"MsgBox \"%A_TitleMatchMode% %A_TitleMatchModeSpeed% %A_DetectHiddenWindows% %A_DetectHiddenText% %A_WinDelay%\"",
);
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["2 Fast 0 1 100"]);
}
#[test]
fn the_settings_that_the_tree_keeps_answer_with_the_value_of_v2() {
let report = run(
"MsgBox \"%A_ControlDelay% %A_RegView% %A_CoordModeCaret% %A_CoordModeMenu% %A_CoordModeToolTip%\"",
);
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["20 Default Client Client Client"]);
}
#[test]
fn the_shape_of_the_cursor_is_asked_of_the_machine() {
let report = run("MsgBox A_Cursor");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["Arrow"]);
}
#[test]
fn the_window_of_the_script_is_asked_of_the_machine() {
let report = run("MsgBox A_ScriptHwnd");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["6557770"]);
}
#[test]
fn a_machine_that_cannot_say_says_why_and_never_says_zero() {
let desktop = Fake {
cursor: Err("this desktop cannot tell the shape of the cursor".to_string()),
script_window: Err("this desktop has no window of the script".to_string()),
..Fake::default()
};
let report = run_with(desktop, "MsgBox A_ScriptHwnd");
assert!(!report.ok);
assert_eq!(
report.error.as_deref(),
Some("this desktop has no window of the script")
);
assert_eq!(report.error_line, Some(1));
let desktop = Fake {
cursor: Err("this desktop cannot tell the shape of the cursor".to_string()),
script_window: Err("this desktop has no window of the script".to_string()),
..Fake::default()
};
let report = run_with(desktop, "MsgBox A_Cursor");
assert!(!report.ok);
assert_eq!(
report.error.as_deref(),
Some("this desktop cannot tell the shape of the cursor")
);
assert_eq!(report.error_line, Some(1));
}
#[test]
fn the_reason_of_a_name_is_the_same_in_the_read_and_in_the_refusal() {
for name in ["A_Cursor", "A_ScriptHwnd"] {
assert!(ahk::variables::refusal_of(name).is_none(), "{name}");
}
let report = run("MsgBox A_Cursor \", \" A_ScriptHwnd");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["Arrow, 6557770"]);
}
#[test]
fn a_script_that_asks_for_the_clipboard_is_told_the_text_of_the_desktop() {
let (report, _) = run_with_clipboard("MsgBox A_Clipboard", "the text of the clipboard");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["the text of the clipboard"]);
}
#[test]
fn a_clipboard_that_is_empty_is_an_empty_text() {
let (report, _) = run_with_clipboard("MsgBox A_Clipboard", "");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec![""]);
}
#[test]
fn a_script_that_writes_the_clipboard_puts_the_text_on_it() {
let (report, clipboard) = run_with_clipboard("A_Clipboard := \"the new text\"", "");
assert!(report.ok, "{:?}", report.error);
assert_eq!(clipboard, "the new text");
}
#[test]
fn a_script_that_appends_to_the_clipboard_adds_to_what_is_there() {
let (report, clipboard) = run_with_clipboard("A_Clipboard .= \" and more\"", "the first part");
assert!(report.ok, "{:?}", report.error);
assert_eq!(clipboard, "the first part and more");
}
#[test]
fn the_clipboard_is_not_a_variable_of_the_script() {
let (report, _) = run_with_clipboard("A_Clipboard := \"the new text\"", "");
assert!(report.ok, "{:?}", report.error);
assert!(
!report.variables.contains_key("A_Clipboard"),
"{:?}",
report.variables
);
}
#[test]
fn the_name_without_the_prefix_is_a_variable_of_the_script() {
let report = run("MsgBox Clipboard");
assert!(!report.ok);
assert_eq!(
report.error.as_deref(),
Some("This global variable has not been assigned a value.")
);
assert_eq!(report.error_line, Some(1));
}
#[test]
fn the_name_of_the_elevation_without_the_prefix_is_a_variable_of_the_script() {
let report = run("MsgBox IsAdmin");
assert!(!report.ok);
assert_eq!(
report.error.as_deref(),
Some("This global variable has not been assigned a value.")
);
}
#[test]
fn a_variable_of_the_script_named_like_the_clipboard_is_kept_by_the_script() {
let (report, clipboard) = run_with_clipboard(
"Clipboard := \"the text of the script\"\nMsgBox Clipboard",
"the text of the clipboard",
);
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["the text of the script"]);
assert_eq!(clipboard, "the text of the clipboard");
}
#[test]
fn the_directory_where_the_run_started_is_the_one_of_the_run() {
let report = run("MsgBox A_InitialWorkingDir \", \" A_ScriptDir");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["/work, /work"]);
}
#[test]
fn a_script_that_comes_from_the_standard_input_has_no_file_of_its_own() {
let report = run("MsgBox A_ScriptName \", \" A_ScriptFullPath");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["*, *"]);
}
#[test]
fn the_script_writes_the_working_directory() {
let report = run("A_WorkingDir := \"/tmp\"\nMsgBox A_WorkingDir \", \" A_InitialWorkingDir");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["/tmp, /work"]);
}
#[test]
fn the_script_writes_the_name_of_the_script() {
let report = run("A_ScriptName := \"x\"\nMsgBox A_ScriptName");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["x"]);
}
#[test]
fn the_script_writes_the_information_of_an_event() {
let report = run(
"A_EventInfo := \"20x\"\na := A_EventInfo\nA_EventInfo := 7\nb := A_EventInfo\nMsgBox \"%a% %b%\"",
);
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["20 7"]);
}
#[test]
fn the_script_writes_the_tip_of_the_icon() {
let report = run("A_IconTip := \"x\"\nMsgBox A_IconTip");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["x"]);
}
#[test]
fn the_script_writes_the_hidden_of_the_icon() {
let report = run(
"A_IconHidden := \"x\"\na := A_IconHidden\nA_IconHidden := false\nb := A_IconHidden\nMsgBox \"%a% %b%\"",
);
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["1 0"]);
}
#[test]
fn the_script_writes_the_last_error() {
let report = run(
"A_LastError := -1\na := A_LastError\nA_LastError := \"20x\"\nb := A_LastError\nMsgBox \"%a% %b%\"",
);
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["4294967295 20"]);
}
#[test]
fn the_script_writes_the_interval_of_the_hotkeys() {
let report = run(
"A_HotkeyInterval := \"2\"\na := A_HotkeyInterval\nA_HotkeyInterval := 7\nb := A_HotkeyInterval\nMsgBox \"%a% %b%\"",
);
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["2 7"]);
}
#[test]
fn a_text_that_holds_no_number_is_refused_by_the_interval_of_the_hotkeys() {
let report = run(
"try {\n A_HotkeyInterval := \"text\"\n} catch Any as e {\n MsgBox e.Message \" | \" e.__Class\n}",
);
assert!(report.ok, "{:?}", report.error);
assert_eq!(
report.output,
vec!["Expected a Number but got a String. | TypeError"]
);
}
#[test]
fn the_script_writes_the_number_of_the_hotkeys() {
let report = run("A_MaxHotkeysPerInterval := 7\na := A_MaxHotkeysPerInterval\nMsgBox \"%a%\"");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["7"]);
}
#[test]
fn a_number_of_hotkeys_that_is_not_one_is_refused() {
let report = run(
"try {\n A_MaxHotkeysPerInterval := 0\n} catch Any as e {\n MsgBox e.Message \" | \" e.__Class\n}",
);
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["Invalid value. | ValueError"]);
}
#[test]
fn the_timeout_of_the_change_of_a_hotkey_is_fifty() {
let report = run("MsgBox A_HotkeyModifierTimeout");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["50"]);
}
#[test]
fn the_timeout_of_the_change_of_a_hotkey_keeps_the_value_that_was_written() {
let report = run("A_HotkeyModifierTimeout := 5\nMsgBox A_HotkeyModifierTimeout");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["5"]);
}
#[test]
fn the_name_that_is_not_a_built_in_variable_has_no_value() {
let report = run("MsgBox A_HotkeyModifyTimeout");
assert!(!report.ok);
assert_eq!(
report.error.as_deref(),
Some("This global variable has not been assigned a value.")
);
assert_eq!(report.error_line, Some(1));
}
#[test]
fn the_index_of_the_turn_is_the_number_of_it() {
let report = run(
"Loop 3 {\n MsgBox A_Index\n}\nn := 0\nwhile n < 2 {\n MsgBox A_Index\n n += 1\n}",
);
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["1", "2", "3", "1", "2"]);
}
#[test]
fn the_index_that_the_body_writes_changes_the_course_of_the_loop() {
let report = run("Loop 5 {\n A_Index := 9\n MsgBox A_Index\n}");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["9"]);
}
#[test]
fn the_index_of_the_turn_goes_back_when_the_loop_ends() {
let report = run("Loop 2 {\n}\nMsgBox A_Index");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["0"]);
}
#[test]
fn the_index_of_the_outer_loop_is_not_disturbed_by_the_inner_one() {
let report = run("Loop 2 {\n Loop 2 {\n MsgBox A_Index\n }\n}");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["1", "2", "1", "2"]);
}
#[test]
fn the_index_of_the_turn_is_zero_outside_a_loop() {
let report = run("A_Index += 1\nMsgBox A_Index");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["1"]);
}
#[test]
fn a_built_in_variable_that_the_dialect_does_not_let_a_script_write_is_refused() {
let error = parse("A_AhkVersion := \"x\"").expect_err("does not parse");
assert_eq!(
error.message,
"This built-in variable cannot be used as an output variable.\n Specifically: A_AhkVersion"
);
assert_eq!(error.line, 1);
}
#[test]
fn the_compound_operator_says_that_the_variable_cannot_be_assigned_a_value() {
let error = parse("A_ScriptDir += 1").expect_err("does not parse");
assert_eq!(
error.message,
"This built-in variable cannot be assigned a value.\n Specifically: A_ScriptDir"
);
assert_eq!(error.line, 1);
}
#[test]
fn the_refusal_of_a_built_in_variable_is_the_one_of_every_scope() {
let error = parse("f() {\n A_ScriptDir := 1\n}").expect_err("does not parse");
assert_eq!(
error.message,
"This built-in variable cannot be used as an output variable.\n Specifically: A_ScriptDir"
);
assert_eq!(error.line, 2);
}
#[test]
fn the_shape_of_the_cursor_may_not_be_written() {
let error = parse("A_Cursor := \"Arrow\"").expect_err("does not parse");
assert_eq!(
error.message,
"This built-in variable cannot be used as an output variable.\n Specifically: A_Cursor"
);
assert_eq!(error.line, 1);
}
#[test]
fn the_names_that_the_runtime_owns_may_not_be_written() {
let error = parse("A_LoopField := 1").expect_err("does not parse");
assert_eq!(
error.message,
"This built-in variable cannot be used as an output variable.\n Specifically: A_LoopField"
);
assert_eq!(error.line, 1);
}
#[test]
fn the_index_of_the_loop_may_be_written() {
let report = run("A_Index := 5\nMsgBox A_Index");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["5"]);
}
#[test]
fn the_body_of_a_class_may_hold_the_name_of_a_built_in_variable() {
let report = run("class C {\n A_ScriptDir := 1\n}");
assert!(report.ok, "{:?}", report.error);
}
#[test]
fn a_parameter_may_not_carry_the_name_of_a_built_in_variable() {
let error = parse("f(A_ScriptDir) {\n}").expect_err("does not parse");
assert_eq!(
error.message,
"This parameter declaration conflicts with an existing built-in variable.\n Specifically: A_ScriptDir"
);
assert_eq!(error.line, 1);
}
#[test]
fn a_static_declaration_may_not_carry_the_name_of_a_built_in_variable() {
let error = parse("f() {\n static A_ScriptName := 1\n}").expect_err("does not parse");
assert_eq!(
error.message,
"This static variable declaration conflicts with an existing built-in variable.\n Specifically: A_ScriptName"
);
assert_eq!(error.line, 2);
}
#[test]
fn a_global_declaration_may_carry_the_name_of_a_built_in_variable() {
let report = run("global A_ScriptDir");
assert!(report.ok, "{:?}", report.error);
}
#[test]
fn the_variable_of_a_for_may_not_carry_the_name_of_a_read_only_variable() {
let error = parse("for A_ScriptDir in [1] {\n}").expect_err("does not parse");
assert_eq!(
error.message,
"This built-in variable cannot be used as an output variable.\n Specifically: A_ScriptDir"
);
assert_eq!(error.line, 1);
}
#[test]
fn a_variable_that_has_no_value_is_an_unset_error() {
let report =
run("try {\n x += 5\n} catch Any as e {\n MsgBox e.Message \" | \" e.__Class\n}");
assert!(report.ok, "{:?}", report.error);
assert_eq!(
report.output,
vec!["This global variable has not been assigned a value. | UnsetError"]
);
}
#[test]
fn the_compound_operator_checks_the_value_that_is_written_first() {
let report = run(
"try {\n x += \"text\"\n} catch Any as e {\n MsgBox e.Message \" | \" e.__Class\n}",
);
assert!(report.ok, "{:?}", report.error);
assert_eq!(
report.output,
vec!["Expected a Number but got a String. | TypeError"]
);
}
#[test]
fn the_windows_of_the_machine_are_the_ones_the_machine_says() {
let report = run("MsgBox A_WinDir \", \" A_ProgramFiles");
assert!(report.ok, "{:?}", report.error);
assert_eq!(report.output, vec!["C:\\Windows, C:\\Program Files"]);
}