From 89056c4dd83c39562c149f3140f0969fdbe00385 Mon Sep 17 00:00:00 2001 From: BrettMayson Date: Sat, 19 Oct 2024 20:27:57 -0600 Subject: [PATCH] use insta for snapshots (#808) --- .gitignore | 3 + CONTRIBUTING.md | 31 + Cargo.lock | 2 + libs/config/Cargo.toml | 1 + libs/config/tests/lints.rs | 68 +- .../source.hpp => c01_invalid_value.hpp} | 0 ...ource.hpp => c01m_invalid_value_macro.hpp} | 0 ...02_duplicate_property_shadow_property.hpp} | 0 .../source.hpp => c03_duplicate_class.hpp} | 0 .../source.hpp => c03_duplicate_external.hpp} | 0 .../source.hpp => c04_missing_parent.hpp} | 0 .../source.hpp => c05_parent_case.hpp} | 0 .../source.hpp => c06_unexpected_array.hpp} | 0 .../source.hpp => c07_expected_array.hpp} | 0 .../source.hpp => c08_missing_semicolon.hpp} | 0 ...e.hpp => c09_magwell_missing_magazine.hpp} | 0 ...ource.hpp => c10_class_missing_braces.hpp} | 0 libs/config/tests/rapify.rs | 34 +- ...ints__config_error_c01_invalid_value.snap} | 11 +- ...onfig_error_c01m_invalid_value_macro.snap} | 9 +- ...2_duplicate_property_shadow_property.snap} | 7 +- ...ts__config_error_c03_duplicate_class.snap} | 7 +- ..._config_error_c03_duplicate_external.snap} | 7 +- ...nts__config_error_c04_missing_parent.snap} | 7 +- .../lints__config_error_c05_parent_case.snap} | 7 +- ...s__config_error_c06_unexpected_array.snap} | 7 +- ...nts__config_error_c07_expected_array.snap} | 7 +- ...__config_error_c08_missing_semicolon.snap} | 13 +- ...g_error_c09_magwell_missing_magazine.snap} | 7 +- ...onfig_error_c10_class_missing_braces.snap} | 7 +- libs/sqf/Cargo.toml | 1 + libs/sqf/tests/errors.rs | 31 +- .../source.sqf => spe1_invalid_token.sqf} | 0 .../source.sqf => spe2_unparseable.sqf} | 0 libs/sqf/tests/lints.rs | 62 +- .../source.sqf => s02_event_handler_case.sqf} | 0 .../source.sqf => s03_static_typename.sqf} | 0 .../source.sqf => s04_command_case.sqf} | 0 .../source.sqf => s05_if_assign.sqf} | 0 .../source.sqf => s06_find_in_str.sqf} | 0 ...source.sqf => s07_select_parse_number.sqf} | 0 .../source.sqf => s08_format_args.sqf} | 0 .../source.sqf => s09_banned_command.sqf} | 0 .../source.sqf => s11_if_not_else.sqf} | 0 .../source.sqf => s17_var_all_caps.sqf} | 0 .../source.sqf => s18_in_vehicle_check.sqf} | 0 ...rce.sqf => s20_bool_static_comparison.sqf} | 0 ...source.sqf => s21_invalid_comparisons.sqf} | 0 .../source.sqf => s22_this_call.sqf} | 0 ...sqf => s23_reassign_reserved_variable.sqf} | 0 .../source.sqf => s24_marker_spam.sqf} | 0 libs/sqf/tests/optimizer.rs | 177 +- .../{test_1/source.sqf => consume_array.sqf} | 15 +- libs/sqf/tests/optimizer/scalar.sqf | 1 + libs/sqf/tests/optimizer/static_math.sqf | 6 + libs/sqf/tests/optimizer/string_case.sqf | 1 + libs/sqf/tests/preprocessor.rs | 40 - libs/sqf/tests/preprocessor/gvars.sqf | 4 - .../tests/preprocessor/script_component.hpp | 13 - libs/sqf/tests/preprocessor/script_macros.hpp | 39 - .../preprocessor/script_macros_common.hpp | 1833 ----------------- libs/sqf/tests/preprocessor/script_mod.hpp | 14 - libs/sqf/tests/simple.rs | 33 +- .../errors__errors_spe1_invalid_token.snap} | 7 +- .../errors__errors_spe2_unparseable.snap} | 7 +- ...lints__simple_s02_event_handler_case.snap} | 7 +- .../lints__simple_s03_static_typename.snap} | 11 +- .../lints__simple_s04_command_case.snap} | 9 +- .../lints__simple_s05_if_assign.snap} | 13 +- .../lints__simple_s06_find_in_str.snap} | 9 +- ...ints__simple_s07_select_parse_number.snap} | 11 +- .../lints__simple_s08_format_args.snap} | 15 +- .../lints__simple_s09_banned_command.snap} | 7 +- .../lints__simple_s11_if_not_else.snap} | 7 +- .../lints__simple_s17_var_all_caps.snap} | 11 +- .../lints__simple_s18_in_vehicle_check.snap} | 9 +- ...s__simple_s20_bool_static_comparison.snap} | 13 +- ...ints__simple_s21_invalid_comparisons.snap} | 11 +- .../lints__simple_s22_this_call.snap} | 7 +- ...imple_s23_reassign_reserved_variable.snap} | 13 +- .../lints__simple_s24_marker_spam.snap} | 13 +- .../optimizer__simple_consume_array.snap | 383 ++++ .../snapshots/optimizer__simple_scalar.snap | 19 + .../optimizer__simple_static_math.snap | 49 + .../optimizer__simple_string_case.snap | 18 + .../tests/snapshots/simple__simple_dev-2.snap | 16 + .../tests/snapshots/simple__simple_dev.snap | 153 ++ .../simple__simple_eventhandler-2.snap | 282 +++ .../simple__simple_eventhandler.snap | 728 +++++++ .../snapshots/simple__simple_foreach-2.snap | 140 ++ .../snapshots/simple__simple_foreach.snap | 455 ++++ .../simple__simple_format_font-2.snap | 56 + .../snapshots/simple__simple_format_font.snap | 316 +++ .../simple__simple_get_visibility-2.snap | 334 +++ .../simple__simple_get_visibility.snap | 955 +++++++++ .../simple__simple_hash_select-2.snap | 23 + .../snapshots/simple__simple_hash_select.snap | 137 ++ .../snapshots/simple__simple_hello-2.snap | 44 + .../tests/snapshots/simple__simple_hello.snap | 229 ++ .../snapshots/simple__simple_include-2.snap | 187 ++ .../snapshots/simple__simple_include.snap | 419 ++++ .../snapshots/simple__simple_oneline-2.snap | 23 + .../snapshots/simple__simple_oneline.snap | 152 ++ .../simple__simple_semicolons-2.snap | 101 + .../snapshots/simple__simple_semicolons.snap | 359 ++++ 105 files changed, 5935 insertions(+), 2328 deletions(-) create mode 100644 CONTRIBUTING.md rename libs/config/tests/lints/{c01_invalid_value/source.hpp => c01_invalid_value.hpp} (100%) rename libs/config/tests/lints/{c01m_invalid_value_macro/source.hpp => c01m_invalid_value_macro.hpp} (100%) rename libs/config/tests/lints/{c02_duplicate_property_shadow_property/source.hpp => c02_duplicate_property_shadow_property.hpp} (100%) rename libs/config/tests/lints/{c03_duplicate_class/source.hpp => c03_duplicate_class.hpp} (100%) rename libs/config/tests/lints/{c03_duplicate_external/source.hpp => c03_duplicate_external.hpp} (100%) rename libs/config/tests/lints/{c04_missing_parent/source.hpp => c04_missing_parent.hpp} (100%) rename libs/config/tests/lints/{c05_parent_case/source.hpp => c05_parent_case.hpp} (100%) rename libs/config/tests/lints/{c06_unexpected_array/source.hpp => c06_unexpected_array.hpp} (100%) rename libs/config/tests/lints/{c07_expected_array/source.hpp => c07_expected_array.hpp} (100%) rename libs/config/tests/lints/{c08_missing_semicolon/source.hpp => c08_missing_semicolon.hpp} (100%) rename libs/config/tests/lints/{c09_magwell_missing_magazine/source.hpp => c09_magwell_missing_magazine.hpp} (100%) rename libs/config/tests/lints/{c10_class_missing_braces/source.hpp => c10_class_missing_braces.hpp} (100%) rename libs/config/tests/{lints/c01_invalid_value/stdout.ansi => snapshots/lints__config_error_c01_invalid_value.snap} (80%) rename libs/config/tests/{lints/c01m_invalid_value_macro/stdout.ansi => snapshots/lints__config_error_c01m_invalid_value_macro.snap} (81%) rename libs/config/tests/{lints/c02_duplicate_property_shadow_property/stdout.ansi => snapshots/lints__config_error_c02_duplicate_property_shadow_property.snap} (66%) rename libs/config/tests/{lints/c03_duplicate_class/stdout.ansi => snapshots/lints__config_error_c03_duplicate_class.snap} (78%) rename libs/config/tests/{lints/c03_duplicate_external/stdout.ansi => snapshots/lints__config_error_c03_duplicate_external.snap} (76%) rename libs/config/tests/{lints/c04_missing_parent/stdout.ansi => snapshots/lints__config_error_c04_missing_parent.snap} (71%) rename libs/config/tests/{lints/c05_parent_case/stdout.ansi => snapshots/lints__config_error_c05_parent_case.snap} (80%) rename libs/config/tests/{lints/c06_unexpected_array/stdout.ansi => snapshots/lints__config_error_c06_unexpected_array.snap} (75%) rename libs/config/tests/{lints/c07_expected_array/stdout.ansi => snapshots/lints__config_error_c07_expected_array.snap} (77%) rename libs/config/tests/{lints/c08_missing_semicolon/stdout.ansi => snapshots/lints__config_error_c08_missing_semicolon.snap} (82%) rename libs/config/tests/{lints/c09_magwell_missing_magazine/stdout.ansi => snapshots/lints__config_error_c09_magwell_missing_magazine.snap} (75%) rename libs/config/tests/{lints/c10_class_missing_braces/stdout.ansi => snapshots/lints__config_error_c10_class_missing_braces.snap} (67%) rename libs/sqf/tests/errors/{spe1_invalid_token/source.sqf => spe1_invalid_token.sqf} (100%) rename libs/sqf/tests/errors/{spe2_unparseable/source.sqf => spe2_unparseable.sqf} (100%) rename libs/sqf/tests/lints/{s02_event_handler_case/source.sqf => s02_event_handler_case.sqf} (100%) rename libs/sqf/tests/lints/{s03_static_typename/source.sqf => s03_static_typename.sqf} (100%) rename libs/sqf/tests/lints/{s04_command_case/source.sqf => s04_command_case.sqf} (100%) rename libs/sqf/tests/lints/{s05_if_assign/source.sqf => s05_if_assign.sqf} (100%) rename libs/sqf/tests/lints/{s06_find_in_str/source.sqf => s06_find_in_str.sqf} (100%) rename libs/sqf/tests/lints/{s07_select_parse_number/source.sqf => s07_select_parse_number.sqf} (100%) rename libs/sqf/tests/lints/{s08_format_args/source.sqf => s08_format_args.sqf} (100%) rename libs/sqf/tests/lints/{s09_banned_command/source.sqf => s09_banned_command.sqf} (100%) rename libs/sqf/tests/lints/{s11_if_not_else/source.sqf => s11_if_not_else.sqf} (100%) rename libs/sqf/tests/lints/{s17_var_all_caps/source.sqf => s17_var_all_caps.sqf} (100%) rename libs/sqf/tests/lints/{s18_in_vehicle_check/source.sqf => s18_in_vehicle_check.sqf} (100%) rename libs/sqf/tests/lints/{s20_bool_static_comparison/source.sqf => s20_bool_static_comparison.sqf} (100%) rename libs/sqf/tests/lints/{s21_invalid_comparisons/source.sqf => s21_invalid_comparisons.sqf} (100%) rename libs/sqf/tests/lints/{s22_this_call/source.sqf => s22_this_call.sqf} (100%) rename libs/sqf/tests/lints/{s23_reassign_reserved_variable/source.sqf => s23_reassign_reserved_variable.sqf} (100%) rename libs/sqf/tests/lints/{s24_marker_spam/source.sqf => s24_marker_spam.sqf} (100%) rename libs/sqf/tests/optimizer/{test_1/source.sqf => consume_array.sqf} (68%) create mode 100644 libs/sqf/tests/optimizer/scalar.sqf create mode 100644 libs/sqf/tests/optimizer/static_math.sqf create mode 100644 libs/sqf/tests/optimizer/string_case.sqf delete mode 100644 libs/sqf/tests/preprocessor.rs delete mode 100644 libs/sqf/tests/preprocessor/gvars.sqf delete mode 100644 libs/sqf/tests/preprocessor/script_component.hpp delete mode 100644 libs/sqf/tests/preprocessor/script_macros.hpp delete mode 100644 libs/sqf/tests/preprocessor/script_macros_common.hpp delete mode 100644 libs/sqf/tests/preprocessor/script_mod.hpp rename libs/sqf/tests/{errors/spe1_invalid_token/stderr.ansi => snapshots/errors__errors_spe1_invalid_token.snap} (59%) rename libs/sqf/tests/{errors/spe2_unparseable/stderr.ansi => snapshots/errors__errors_spe2_unparseable.snap} (60%) rename libs/sqf/tests/{lints/s02_event_handler_case/stdout.ansi => snapshots/lints__simple_s02_event_handler_case.snap} (73%) rename libs/sqf/tests/{lints/s03_static_typename/stdout.ansi => snapshots/lints__simple_s03_static_typename.snap} (82%) rename libs/sqf/tests/{lints/s04_command_case/stdout.ansi => snapshots/lints__simple_s04_command_case.snap} (80%) rename libs/sqf/tests/{lints/s05_if_assign/stdout.ansi => snapshots/lints__simple_s05_if_assign.snap} (89%) rename libs/sqf/tests/{lints/s06_find_in_str/stdout.ansi => snapshots/lints__simple_s06_find_in_str.snap} (79%) rename libs/sqf/tests/{lints/s07_select_parse_number/stdout.ansi => snapshots/lints__simple_s07_select_parse_number.snap} (84%) rename libs/sqf/tests/{lints/s08_format_args/stdout.ansi => snapshots/lints__simple_s08_format_args.snap} (89%) rename libs/sqf/tests/{lints/s09_banned_command/stdout.ansi => snapshots/lints__simple_s09_banned_command.snap} (63%) rename libs/sqf/tests/{lints/s11_if_not_else/stdout.ansi => snapshots/lints__simple_s11_if_not_else.snap} (65%) rename libs/sqf/tests/{lints/s17_var_all_caps/stdout.ansi => snapshots/lints__simple_s17_var_all_caps.snap} (85%) rename libs/sqf/tests/{lints/s18_in_vehicle_check/stdout.ansi => snapshots/lints__simple_s18_in_vehicle_check.snap} (80%) rename libs/sqf/tests/{lints/s20_bool_static_comparison/stdout.ansi => snapshots/lints__simple_s20_bool_static_comparison.snap} (79%) rename libs/sqf/tests/{lints/s21_invalid_comparisons/stdout.ansi => snapshots/lints__simple_s21_invalid_comparisons.snap} (75%) rename libs/sqf/tests/{lints/s22_this_call/stdout.ansi => snapshots/lints__simple_s22_this_call.snap} (73%) rename libs/sqf/tests/{lints/s23_reassign_reserved_variable/stdout.ansi => snapshots/lints__simple_s23_reassign_reserved_variable.snap} (82%) rename libs/sqf/tests/{lints/s24_marker_spam/stdout.ansi => snapshots/lints__simple_s24_marker_spam.snap} (92%) create mode 100644 libs/sqf/tests/snapshots/optimizer__simple_consume_array.snap create mode 100644 libs/sqf/tests/snapshots/optimizer__simple_scalar.snap create mode 100644 libs/sqf/tests/snapshots/optimizer__simple_static_math.snap create mode 100644 libs/sqf/tests/snapshots/optimizer__simple_string_case.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_dev-2.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_dev.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_eventhandler-2.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_eventhandler.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_foreach-2.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_foreach.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_format_font-2.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_format_font.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_get_visibility-2.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_get_visibility.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_hash_select-2.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_hash_select.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_hello-2.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_hello.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_include-2.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_include.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_oneline-2.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_oneline.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_semicolons-2.snap create mode 100644 libs/sqf/tests/snapshots/simple__simple_semicolons.snap diff --git a/.gitignore b/.gitignore index 3e75e5e0..00b138d4 100644 --- a/.gitignore +++ b/.gitignore @@ -28,5 +28,8 @@ hls/languages/sqf.json hls/hemtt-language-server hls/hemtt-language-server.exe +# Insta Pending Snpashots +*.snap.new + # Cargo Mutants mutants.*/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..84d27858 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,31 @@ +# Contributing + +## Testing + +When running tests locally, it is highly recommended to use `cargo-nextest`. + +It runs the tests much faster, and can detect slow and leaky tests, among other features. + +```bash +cargo install cargo-nextest +cargo nextest run +``` + +## Lint Tests + +Tests for lints are using [insta](https://docs.rs/insta) for snapshot testing. + +When you make changes to the lints, that causes tests to fail, you will need to review the changes. + +```bash +cargo install cargo-insta +# Run the tests before reviewing, you can just run an individual test, or use any testing tool +cargo nextest run +# Review the changes +cargo insta review + +# Alternatively, you can run the tests with insta to review the changes in one command +cargo insta test --review +``` + +When reviewing changes with ANSI characters, you can press `d` to toggle between the diff and a rendered view. diff --git a/Cargo.lock b/Cargo.lock index e8ce802d..6e3dc1b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1480,6 +1480,7 @@ dependencies = [ "hemtt-common", "hemtt-preprocessor", "hemtt-workspace", + "insta", "linkme", "lsp-types 0.97.0", "paste", @@ -1598,6 +1599,7 @@ dependencies = [ "hemtt-lzo", "hemtt-preprocessor", "hemtt-workspace", + "insta", "linkme", "paste", "toml 0.8.19", diff --git a/libs/config/Cargo.toml b/libs/config/Cargo.toml index cd86419e..2fddc28e 100644 --- a/libs/config/Cargo.toml +++ b/libs/config/Cargo.toml @@ -25,4 +25,5 @@ vfs = { workspace = true } [dev-dependencies] hemtt-preprocessor = { path = "../preprocessor" } +insta = { workspace = true } paste = { workspace = true } diff --git a/libs/config/tests/lints.rs b/libs/config/tests/lints.rs index 0140e7fc..9ee39372 100644 --- a/libs/config/tests/lints.rs +++ b/libs/config/tests/lints.rs @@ -1,26 +1,37 @@ #![allow(clippy::unwrap_used)] -use std::io::Read; - use hemtt_common::config::ProjectConfig; use hemtt_preprocessor::Processor; use hemtt_workspace::{reporting::WorkspaceFiles, LayerType}; const ROOT: &str = "tests/lints/"; -macro_rules! bootstrap { +macro_rules! lint { ($dir:ident) => { paste::paste! { #[test] fn []() { - check(stringify!($dir)); + insta::assert_snapshot!(lint(stringify!($dir))); } } }; } -fn check(dir: &str) { - let folder = std::path::PathBuf::from(ROOT).join(dir); +lint!(c01_invalid_value); +lint!(c01m_invalid_value_macro); +lint!(c02_duplicate_property_shadow_property); +lint!(c03_duplicate_class); +lint!(c03_duplicate_external); +lint!(c04_missing_parent); +lint!(c05_parent_case); +lint!(c06_unexpected_array); +lint!(c07_expected_array); +lint!(c08_missing_semicolon); +lint!(c09_magwell_missing_magazine); +lint!(c10_class_missing_braces); + +fn lint(file: &str) -> String { + let folder = std::path::PathBuf::from(ROOT); let workspace = hemtt_workspace::Workspace::builder() .physical(&folder, LayerType::Source) .finish( @@ -29,34 +40,18 @@ fn check(dir: &str) { &hemtt_common::config::PDriveOption::Disallow, ) .unwrap(); - let source = workspace.join("source.hpp").unwrap(); + let source = workspace.join(format!("{file}.hpp")).unwrap(); let processed = Processor::run(&source).unwrap(); let parsed = hemtt_config::parse(Some(&ProjectConfig::test_project()), &processed); let workspacefiles = WorkspaceFiles::new(); match parsed { - Ok(config) => { - let mut expected = Vec::new(); - std::fs::File::open(folder.join("stdout.ansi")) - .unwrap() - .read_to_end(&mut expected) - .unwrap(); - let codes = config - .codes() - .iter() - .map(|e| e.diagnostic().unwrap().to_string(&workspacefiles)) - .collect::>(); - if expected.is_empty() { - std::fs::write( - folder.join("stdout.ansi"), - codes.join("\n").replace('\r', "").as_bytes(), - ) - .unwrap(); - } - assert_eq!( - codes.join("\n").replace('\r', ""), - String::from_utf8(expected).unwrap().replace('\r', "") - ); - } + Ok(config) => config + .codes() + .iter() + .map(|e| e.diagnostic().unwrap().to_string(&workspacefiles)) + .collect::>() + .join("\n") + .replace('\r', ""), // Errors may occur, but they should be handled, if one is not a handler should be created Err(e) => { for e in &e { @@ -66,16 +61,3 @@ fn check(dir: &str) { } } } - -bootstrap!(c01_invalid_value); -bootstrap!(c01m_invalid_value_macro); -bootstrap!(c02_duplicate_property_shadow_property); -bootstrap!(c03_duplicate_class); -bootstrap!(c03_duplicate_external); -bootstrap!(c04_missing_parent); -bootstrap!(c05_parent_case); -bootstrap!(c06_unexpected_array); -bootstrap!(c07_expected_array); -bootstrap!(c08_missing_semicolon); -bootstrap!(c09_magwell_missing_magazine); -bootstrap!(c10_class_missing_braces); diff --git a/libs/config/tests/lints/c01_invalid_value/source.hpp b/libs/config/tests/lints/c01_invalid_value.hpp similarity index 100% rename from libs/config/tests/lints/c01_invalid_value/source.hpp rename to libs/config/tests/lints/c01_invalid_value.hpp diff --git a/libs/config/tests/lints/c01m_invalid_value_macro/source.hpp b/libs/config/tests/lints/c01m_invalid_value_macro.hpp similarity index 100% rename from libs/config/tests/lints/c01m_invalid_value_macro/source.hpp rename to libs/config/tests/lints/c01m_invalid_value_macro.hpp diff --git a/libs/config/tests/lints/c02_duplicate_property_shadow_property/source.hpp b/libs/config/tests/lints/c02_duplicate_property_shadow_property.hpp similarity index 100% rename from libs/config/tests/lints/c02_duplicate_property_shadow_property/source.hpp rename to libs/config/tests/lints/c02_duplicate_property_shadow_property.hpp diff --git a/libs/config/tests/lints/c03_duplicate_class/source.hpp b/libs/config/tests/lints/c03_duplicate_class.hpp similarity index 100% rename from libs/config/tests/lints/c03_duplicate_class/source.hpp rename to libs/config/tests/lints/c03_duplicate_class.hpp diff --git a/libs/config/tests/lints/c03_duplicate_external/source.hpp b/libs/config/tests/lints/c03_duplicate_external.hpp similarity index 100% rename from libs/config/tests/lints/c03_duplicate_external/source.hpp rename to libs/config/tests/lints/c03_duplicate_external.hpp diff --git a/libs/config/tests/lints/c04_missing_parent/source.hpp b/libs/config/tests/lints/c04_missing_parent.hpp similarity index 100% rename from libs/config/tests/lints/c04_missing_parent/source.hpp rename to libs/config/tests/lints/c04_missing_parent.hpp diff --git a/libs/config/tests/lints/c05_parent_case/source.hpp b/libs/config/tests/lints/c05_parent_case.hpp similarity index 100% rename from libs/config/tests/lints/c05_parent_case/source.hpp rename to libs/config/tests/lints/c05_parent_case.hpp diff --git a/libs/config/tests/lints/c06_unexpected_array/source.hpp b/libs/config/tests/lints/c06_unexpected_array.hpp similarity index 100% rename from libs/config/tests/lints/c06_unexpected_array/source.hpp rename to libs/config/tests/lints/c06_unexpected_array.hpp diff --git a/libs/config/tests/lints/c07_expected_array/source.hpp b/libs/config/tests/lints/c07_expected_array.hpp similarity index 100% rename from libs/config/tests/lints/c07_expected_array/source.hpp rename to libs/config/tests/lints/c07_expected_array.hpp diff --git a/libs/config/tests/lints/c08_missing_semicolon/source.hpp b/libs/config/tests/lints/c08_missing_semicolon.hpp similarity index 100% rename from libs/config/tests/lints/c08_missing_semicolon/source.hpp rename to libs/config/tests/lints/c08_missing_semicolon.hpp diff --git a/libs/config/tests/lints/c09_magwell_missing_magazine/source.hpp b/libs/config/tests/lints/c09_magwell_missing_magazine.hpp similarity index 100% rename from libs/config/tests/lints/c09_magwell_missing_magazine/source.hpp rename to libs/config/tests/lints/c09_magwell_missing_magazine.hpp diff --git a/libs/config/tests/lints/c10_class_missing_braces/source.hpp b/libs/config/tests/lints/c10_class_missing_braces.hpp similarity index 100% rename from libs/config/tests/lints/c10_class_missing_braces/source.hpp rename to libs/config/tests/lints/c10_class_missing_braces.hpp diff --git a/libs/config/tests/rapify.rs b/libs/config/tests/rapify.rs index 985096fd..b0ea4057 100644 --- a/libs/config/tests/rapify.rs +++ b/libs/config/tests/rapify.rs @@ -8,18 +8,32 @@ use hemtt_workspace::LayerType; const ROOT: &str = "tests/rapify/"; -macro_rules! bootstrap { +macro_rules! rapify { ($dir:ident) => { paste::paste! { #[test] fn []() { - check(stringify!($dir)); + rapify(stringify!($dir)); } } }; } -fn check(dir: &str) { +rapify!(ace_main); +rapify!(cba_multiline); +rapify!(delete_class); +rapify!(eval); +rapify!(external_class); +rapify!(inheritence_array_extend); +rapify!(join_digit); +rapify!(join_in_ident); +rapify!(join); +rapify!(nested_array); +rapify!(numbers); +rapify!(procedural_texture); +rapify!(single_class); + +fn rapify(dir: &str) { let folder = std::path::PathBuf::from(ROOT).join(dir); let workspace = hemtt_workspace::Workspace::builder() .physical(&folder, LayerType::Source) @@ -62,17 +76,3 @@ fn check(dir: &str) { assert_eq!(output, expected); }; } - -bootstrap!(ace_main); -bootstrap!(cba_multiline); -bootstrap!(delete_class); -bootstrap!(eval); -bootstrap!(external_class); -bootstrap!(inheritence_array_extend); -bootstrap!(join_digit); -bootstrap!(join_in_ident); -bootstrap!(join); -bootstrap!(nested_array); -bootstrap!(numbers); -bootstrap!(procedural_texture); -bootstrap!(single_class); diff --git a/libs/config/tests/lints/c01_invalid_value/stdout.ansi b/libs/config/tests/snapshots/lints__config_error_c01_invalid_value.snap similarity index 80% rename from libs/config/tests/lints/c01_invalid_value/stdout.ansi rename to libs/config/tests/snapshots/lints__config_error_c01_invalid_value.snap index d2498cdf..2a5f47f6 100644 --- a/libs/config/tests/lints/c01_invalid_value/stdout.ansi +++ b/libs/config/tests/snapshots/lints__config_error_c01_invalid_value.snap @@ -1,5 +1,9 @@ +--- +source: libs/config/tests/lints.rs +expression: lint(stringify! (c01_invalid_value)) +--- error[L-C01]: property's value could not be parsed - ┌─ source.hpp:2:13 + ┌─ c01_invalid_value.hpp:2:13 │ 2 │ value = something; │ ^^^^^^^^^ invalid value @@ -8,7 +12,7 @@ error[L-C01]: property's value could not be parsed - ┌─ source.hpp:3:15 + ┌─ c01_invalid_value.hpp:3:15 │ 3 │ default = false; │ ^^^^^ invalid value @@ -17,10 +21,9 @@ error[L-C01]: property's value could not be parsed - ┌─ source.hpp:4:14 + ┌─ c01_invalid_value.hpp:4:14 │ 4 │ string = 'test'; │ ^^^^^^ invalid value │ = help: quotes need to be `"` instead of `'` - diff --git a/libs/config/tests/lints/c01m_invalid_value_macro/stdout.ansi b/libs/config/tests/snapshots/lints__config_error_c01m_invalid_value_macro.snap similarity index 81% rename from libs/config/tests/lints/c01m_invalid_value_macro/stdout.ansi rename to libs/config/tests/snapshots/lints__config_error_c01m_invalid_value_macro.snap index 5a5d361f..99add0f8 100644 --- a/libs/config/tests/lints/c01m_invalid_value_macro/stdout.ansi +++ b/libs/config/tests/snapshots/lints__config_error_c01m_invalid_value_macro.snap @@ -1,5 +1,9 @@ +--- +source: libs/config/tests/lints.rs +expression: lint(stringify! (c01m_invalid_value_macro)) +--- error[L-C01M]: macro's result could not be parsed - ┌─ source.hpp:5:8 + ┌─ c01m_invalid_value_macro.hpp:5:8 │ 5 │ path = PATHTO(thing); │ ^^^^^^^^^^^^^ invalid macro result @@ -10,7 +14,7 @@ error[L-C01M]: macro's result could not be parsed - ┌─ source.hpp:7:12 + ┌─ c01m_invalid_value_macro.hpp:7:12 │ 7 │ path = PATHTO(thing); │ ^^^^^^^^^^^^^ invalid macro result @@ -18,4 +22,3 @@ = note: The processed output was: \some\thing = help: perhaps this macro has a `Q_` variant or you need `QUOTE(..)` - diff --git a/libs/config/tests/lints/c02_duplicate_property_shadow_property/stdout.ansi b/libs/config/tests/snapshots/lints__config_error_c02_duplicate_property_shadow_property.snap similarity index 66% rename from libs/config/tests/lints/c02_duplicate_property_shadow_property/stdout.ansi rename to libs/config/tests/snapshots/lints__config_error_c02_duplicate_property_shadow_property.snap index 197d04da..7c8c2794 100644 --- a/libs/config/tests/lints/c02_duplicate_property_shadow_property/stdout.ansi +++ b/libs/config/tests/snapshots/lints__config_error_c02_duplicate_property_shadow_property.snap @@ -1,8 +1,11 @@ +--- +source: libs/config/tests/lints.rs +expression: lint(stringify! (c02_duplicate_property_shadow_property)) +--- error[L-C02]: property was defined more than once - ┌─ source.hpp:3:11 + ┌─ c02_duplicate_property_shadow_property.hpp:3:11 │ 2 │ thing = 1; │ ----- also defined here 3 │ class thing { │ ^^^^^ duplicate property - diff --git a/libs/config/tests/lints/c03_duplicate_class/stdout.ansi b/libs/config/tests/snapshots/lints__config_error_c03_duplicate_class.snap similarity index 78% rename from libs/config/tests/lints/c03_duplicate_class/stdout.ansi rename to libs/config/tests/snapshots/lints__config_error_c03_duplicate_class.snap index 624b3b41..5f3c37d6 100644 --- a/libs/config/tests/lints/c03_duplicate_class/stdout.ansi +++ b/libs/config/tests/snapshots/lints__config_error_c03_duplicate_class.snap @@ -1,5 +1,9 @@ +--- +source: libs/config/tests/lints.rs +expression: lint(stringify! (c03_duplicate_class)) +--- error[L-C03]: class defined multiple times - ┌─ source.hpp:3:11 + ┌─ c03_duplicate_class.hpp:3:11 │ 3 │ class MissileBase; │ ^^^^^^^^^^^ defined multiple times @@ -7,4 +11,3 @@ │ ----------- also defined here │ = help: remove all but the first definition of `class MissileBase;` - diff --git a/libs/config/tests/lints/c03_duplicate_external/stdout.ansi b/libs/config/tests/snapshots/lints__config_error_c03_duplicate_external.snap similarity index 76% rename from libs/config/tests/lints/c03_duplicate_external/stdout.ansi rename to libs/config/tests/snapshots/lints__config_error_c03_duplicate_external.snap index c3cb407d..ff2002ef 100644 --- a/libs/config/tests/lints/c03_duplicate_external/stdout.ansi +++ b/libs/config/tests/snapshots/lints__config_error_c03_duplicate_external.snap @@ -1,5 +1,9 @@ +--- +source: libs/config/tests/lints.rs +expression: lint(stringify! (c03_duplicate_external)) +--- error[L-C03]: class defined multiple times - ┌─ source.hpp:2:11 + ┌─ c03_duplicate_external.hpp:2:11 │ 2 │ class BulletBase; │ ^^^^^^^^^^ defined multiple times @@ -7,4 +11,3 @@ │ ---------- also defined here │ = help: remove all but the first definition of `class BulletBase;` - diff --git a/libs/config/tests/lints/c04_missing_parent/stdout.ansi b/libs/config/tests/snapshots/lints__config_error_c04_missing_parent.snap similarity index 71% rename from libs/config/tests/lints/c04_missing_parent/stdout.ansi rename to libs/config/tests/snapshots/lints__config_error_c04_missing_parent.snap index 17d7563b..4fd6f50a 100644 --- a/libs/config/tests/lints/c04_missing_parent/stdout.ansi +++ b/libs/config/tests/snapshots/lints__config_error_c04_missing_parent.snap @@ -1,8 +1,11 @@ +--- +source: libs/config/tests/lints.rs +expression: lint(stringify! (c04_missing_parent)) +--- error[L-C04]: class's parent is not present - ┌─ source.hpp:8:14 + ┌─ c04_missing_parent.hpp:8:14 │ 8 │ class third: other { │ ^^^^^ not present in config │ = help: add `class other;` to the config to declare it as external - diff --git a/libs/config/tests/lints/c05_parent_case/stdout.ansi b/libs/config/tests/snapshots/lints__config_error_c05_parent_case.snap similarity index 80% rename from libs/config/tests/lints/c05_parent_case/stdout.ansi rename to libs/config/tests/snapshots/lints__config_error_c05_parent_case.snap index 28f8e1af..14aa1d7d 100644 --- a/libs/config/tests/lints/c05_parent_case/stdout.ansi +++ b/libs/config/tests/snapshots/lints__config_error_c05_parent_case.snap @@ -1,5 +1,9 @@ +--- +source: libs/config/tests/lints.rs +expression: lint(stringify! (c05_parent_case)) +--- error[L-C05]: parent case does not match parent definition - ┌─ source.hpp:2:14 + ┌─ c05_parent_case.hpp:2:14 │ 1 │ class imported; │ -------- parent definition here @@ -8,4 +12,3 @@ │ = help: change the parent case to match the parent definition = try: imported - diff --git a/libs/config/tests/lints/c06_unexpected_array/stdout.ansi b/libs/config/tests/snapshots/lints__config_error_c06_unexpected_array.snap similarity index 75% rename from libs/config/tests/lints/c06_unexpected_array/stdout.ansi rename to libs/config/tests/snapshots/lints__config_error_c06_unexpected_array.snap index 5f34a507..6740b31d 100644 --- a/libs/config/tests/lints/c06_unexpected_array/stdout.ansi +++ b/libs/config/tests/snapshots/lints__config_error_c06_unexpected_array.snap @@ -1,5 +1,9 @@ +--- +source: libs/config/tests/lints.rs +expression: lint(stringify! (c06_unexpected_array)) +--- error[L-C06]: property was not expected to be an array - ┌─ source.hpp:1:1 + ┌─ c06_unexpected_array.hpp:1:1 │ 1 │ array = {1,2,3}; │ ^^^^^ ------- unexpected array @@ -8,4 +12,3 @@ │ = help: add [] to the property = try: array[] - diff --git a/libs/config/tests/lints/c07_expected_array/stdout.ansi b/libs/config/tests/snapshots/lints__config_error_c07_expected_array.snap similarity index 77% rename from libs/config/tests/lints/c07_expected_array/stdout.ansi rename to libs/config/tests/snapshots/lints__config_error_c07_expected_array.snap index 01a48190..efbc33d0 100644 --- a/libs/config/tests/lints/c07_expected_array/stdout.ansi +++ b/libs/config/tests/snapshots/lints__config_error_c07_expected_array.snap @@ -1,5 +1,9 @@ +--- +source: libs/config/tests/lints.rs +expression: lint(stringify! (c07_expected_array)) +--- error[L-C07]: property was expected to be an array - ┌─ source.hpp:1:1 + ┌─ c07_expected_array.hpp:1:1 │ 1 │ not_array[] = "hello"; │ ^^^^^^^^^^^ ------- not an array @@ -8,4 +12,3 @@ │ = help: remove the [] from the property = try: not_array - diff --git a/libs/config/tests/lints/c08_missing_semicolon/stdout.ansi b/libs/config/tests/snapshots/lints__config_error_c08_missing_semicolon.snap similarity index 82% rename from libs/config/tests/lints/c08_missing_semicolon/stdout.ansi rename to libs/config/tests/snapshots/lints__config_error_c08_missing_semicolon.snap index 0c1bc5dc..cb5987db 100644 --- a/libs/config/tests/lints/c08_missing_semicolon/stdout.ansi +++ b/libs/config/tests/snapshots/lints__config_error_c08_missing_semicolon.snap @@ -1,5 +1,9 @@ +--- +source: libs/config/tests/lints.rs +expression: lint(stringify! (c08_missing_semicolon)) +--- error[L-C08]: property is missing a semicolon - ┌─ source.hpp:1:17 + ┌─ c08_missing_semicolon.hpp:1:17 │ 1 │ outer = "nosemi" │ ^ missing semicolon @@ -8,7 +12,7 @@ error[L-C08]: property is missing a semicolon - ┌─ source.hpp:3:21 + ┌─ c08_missing_semicolon.hpp:3:21 │ 3 │ inner = "nosemi" │ ^ missing semicolon @@ -17,7 +21,7 @@ error[L-C08]: property is missing a semicolon - ┌─ source.hpp:5:32 + ┌─ c08_missing_semicolon.hpp:5:32 │ 5 │ class inline { inner = "nosemi" }; │ ^ missing semicolon @@ -26,10 +30,9 @@ error[L-C08]: property is missing a semicolon - ┌─ source.hpp:6:32 + ┌─ c08_missing_semicolon.hpp:6:32 │ 6 │ class inline2 {inner = "nosemi"}; │ ^ missing semicolon │ = help: add a semicolon ; to the end of the property - diff --git a/libs/config/tests/lints/c09_magwell_missing_magazine/stdout.ansi b/libs/config/tests/snapshots/lints__config_error_c09_magwell_missing_magazine.snap similarity index 75% rename from libs/config/tests/lints/c09_magwell_missing_magazine/stdout.ansi rename to libs/config/tests/snapshots/lints__config_error_c09_magwell_missing_magazine.snap index bfbc5258..7d941e9d 100644 --- a/libs/config/tests/lints/c09_magwell_missing_magazine/stdout.ansi +++ b/libs/config/tests/snapshots/lints__config_error_c09_magwell_missing_magazine.snap @@ -1,9 +1,12 @@ +--- +source: libs/config/tests/lints.rs +expression: lint(stringify! (c09_magwell_missing_magazine)) +--- error[L-C09]: magazine defined in CfgMagazineWells was not found in CfgMagazines - ┌─ source.hpp:5:13 + ┌─ c09_magwell_missing_magazine.hpp:5:13 │ 3 │ abe_main[] = { │ -------- magazine well defined here 4 │ "abe_cavendish", 5 │ "abe_plantain", │ ^^^^^^^^^^^^^^ no matching magazine was found - diff --git a/libs/config/tests/lints/c10_class_missing_braces/stdout.ansi b/libs/config/tests/snapshots/lints__config_error_c10_class_missing_braces.snap similarity index 67% rename from libs/config/tests/lints/c10_class_missing_braces/stdout.ansi rename to libs/config/tests/snapshots/lints__config_error_c10_class_missing_braces.snap index b8f79be1..d87b94a9 100644 --- a/libs/config/tests/lints/c10_class_missing_braces/stdout.ansi +++ b/libs/config/tests/snapshots/lints__config_error_c10_class_missing_braces.snap @@ -1,8 +1,11 @@ +--- +source: libs/config/tests/lints.rs +expression: lint(stringify! (c10_class_missing_braces)) +--- error[L-C10]: classes must use braces when inheriting - ┌─ source.hpp:2:29 + ┌─ c10_class_missing_braces.hpp:2:29 │ 2 │ class AlsoExternal: External; │ ^ missing braces │ = try: {}; - diff --git a/libs/sqf/Cargo.toml b/libs/sqf/Cargo.toml index ae9872b7..c71b402b 100644 --- a/libs/sqf/Cargo.toml +++ b/libs/sqf/Cargo.toml @@ -32,4 +32,5 @@ parser = ["chumsky"] [dev-dependencies] hemtt-preprocessor = { path = "../preprocessor" } +insta = { workspace = true } paste = { workspace = true } diff --git a/libs/sqf/tests/errors.rs b/libs/sqf/tests/errors.rs index f9561153..5c0f5648 100644 --- a/libs/sqf/tests/errors.rs +++ b/libs/sqf/tests/errors.rs @@ -1,51 +1,40 @@ #![allow(clippy::unwrap_used)] -use std::io::Read; - use hemtt_preprocessor::Processor; use hemtt_sqf::parser::database::Database; use hemtt_workspace::{reporting::WorkspaceFiles, LayerType}; -const ROOT: &str = "tests/errors/"; - macro_rules! errors { ($dir:ident) => { paste::paste! { #[test] fn []() { - errors(stringify!($dir)); + insta::assert_snapshot!(errors(stringify!($dir))); } } }; } -fn errors(dir: &str) { - let folder = std::path::PathBuf::from(ROOT).join(dir); +errors!(spe1_invalid_token); +errors!(spe2_unparseable); + +const ROOT: &str = "tests/errors/"; + +fn errors(file: &str) -> String { + let folder = std::path::PathBuf::from(ROOT); let workspace = hemtt_workspace::Workspace::builder() .physical(&folder, LayerType::Source) .finish(None, false, &hemtt_common::config::PDriveOption::Disallow) .unwrap(); - let source = workspace.join("source.sqf").unwrap(); + let source = workspace.join(format!("{file}.sqf")).unwrap(); let processed = Processor::run(&source).unwrap(); let parsed = hemtt_sqf::parser::run(&Database::a3(false), &processed).unwrap_err(); let codes = parsed.codes(); - let mut expected = Vec::new(); - std::fs::File::open(folder.join("stderr.ansi")) - .unwrap() - .read_to_end(&mut expected) - .unwrap(); let errors = codes .iter() .map(|e| e.diagnostic().unwrap().to_string(&WorkspaceFiles::new())) .collect::>() .join("\n") .replace('\r', ""); - if expected.is_empty() { - std::fs::write(folder.join("stderr.ansi"), errors.as_bytes()).unwrap(); - } - let expected = String::from_utf8_lossy(&expected).replace('\r', ""); - assert_eq!(errors, expected); + errors } - -errors!(spe1_invalid_token); -errors!(spe2_unparseable); diff --git a/libs/sqf/tests/errors/spe1_invalid_token/source.sqf b/libs/sqf/tests/errors/spe1_invalid_token.sqf similarity index 100% rename from libs/sqf/tests/errors/spe1_invalid_token/source.sqf rename to libs/sqf/tests/errors/spe1_invalid_token.sqf diff --git a/libs/sqf/tests/errors/spe2_unparseable/source.sqf b/libs/sqf/tests/errors/spe2_unparseable.sqf similarity index 100% rename from libs/sqf/tests/errors/spe2_unparseable/source.sqf rename to libs/sqf/tests/errors/spe2_unparseable.sqf diff --git a/libs/sqf/tests/lints.rs b/libs/sqf/tests/lints.rs index 900b826a..484bffc0 100644 --- a/libs/sqf/tests/lints.rs +++ b/libs/sqf/tests/lints.rs @@ -1,6 +1,6 @@ #![allow(clippy::unwrap_used)] -use std::{io::Read, sync::Arc}; +use std::sync::Arc; use hemtt_common::config::ProjectConfig; use hemtt_preprocessor::Processor; @@ -9,24 +9,41 @@ use hemtt_workspace::{addons::Addon, reporting::WorkspaceFiles, LayerType}; const ROOT: &str = "tests/lints/"; -macro_rules! analyze { +macro_rules! lint { ($dir:ident) => { paste::paste! { #[test] fn []() { - test_analyze(stringify!($dir)); + insta::assert_snapshot!(lint(stringify!($dir))); } } }; } -fn test_analyze(dir: &str) { - let folder = std::path::PathBuf::from(ROOT).join(dir); +lint!(s02_event_handler_case); +lint!(s03_static_typename); +lint!(s04_command_case); +lint!(s05_if_assign); +lint!(s06_find_in_str); +lint!(s07_select_parse_number); +lint!(s08_format_args); +lint!(s09_banned_command); +lint!(s11_if_not_else); +lint!(s17_var_all_caps); +lint!(s18_in_vehicle_check); +lint!(s20_bool_static_comparison); +lint!(s21_invalid_comparisons); +lint!(s22_this_call); +lint!(s23_reassign_reserved_variable); +lint!(s24_marker_spam); + +fn lint(file: &str) -> String { + let folder = std::path::PathBuf::from(ROOT); let workspace = hemtt_workspace::Workspace::builder() .physical(&folder, LayerType::Source) .finish(None, false, &hemtt_common::config::PDriveOption::Disallow) .unwrap(); - let source = workspace.join("source.sqf").unwrap(); + let source = workspace.join(format!("{file}.sqf")).unwrap(); let processed = Processor::run(&source).unwrap(); let database = Arc::new(Database::a3(false)); let workspace_files = WorkspaceFiles::new(); @@ -43,22 +60,12 @@ fn test_analyze(dir: &str) { Arc::new(Addon::test_addon()), database.clone(), ); - let stdout = codes + codes .iter() .map(|e| e.diagnostic().unwrap().to_string(&workspace_files)) .collect::>() .join("\n") - .replace('\r', ""); - let mut expected = Vec::new(); - std::fs::File::open(folder.join("stdout.ansi")) - .unwrap() - .read_to_end(&mut expected) - .unwrap(); - if expected.is_empty() { - std::fs::write(folder.join("stdout.ansi"), stdout.as_bytes()).unwrap(); - } - let expected = String::from_utf8_lossy(&expected).replace('\r', ""); - assert_eq!(stdout, expected); + .replace('\r', "") } Err(hemtt_sqf::parser::ParserError::ParsingError(e)) => { for error in e { @@ -70,22 +77,5 @@ fn test_analyze(dir: &str) { panic!("failed to parse"); } Err(e) => panic!("{e:?}"), - }; + } } - -analyze!(s02_event_handler_case); -analyze!(s03_static_typename); -analyze!(s04_command_case); -analyze!(s05_if_assign); -analyze!(s06_find_in_str); -analyze!(s07_select_parse_number); -analyze!(s08_format_args); -analyze!(s09_banned_command); -analyze!(s11_if_not_else); -analyze!(s17_var_all_caps); -analyze!(s18_in_vehicle_check); -analyze!(s20_bool_static_comparison); -analyze!(s21_invalid_comparisons); -analyze!(s22_this_call); -analyze!(s23_reassign_reserved_variable); -analyze!(s24_marker_spam); diff --git a/libs/sqf/tests/lints/s02_event_handler_case/source.sqf b/libs/sqf/tests/lints/s02_event_handler_case.sqf similarity index 100% rename from libs/sqf/tests/lints/s02_event_handler_case/source.sqf rename to libs/sqf/tests/lints/s02_event_handler_case.sqf diff --git a/libs/sqf/tests/lints/s03_static_typename/source.sqf b/libs/sqf/tests/lints/s03_static_typename.sqf similarity index 100% rename from libs/sqf/tests/lints/s03_static_typename/source.sqf rename to libs/sqf/tests/lints/s03_static_typename.sqf diff --git a/libs/sqf/tests/lints/s04_command_case/source.sqf b/libs/sqf/tests/lints/s04_command_case.sqf similarity index 100% rename from libs/sqf/tests/lints/s04_command_case/source.sqf rename to libs/sqf/tests/lints/s04_command_case.sqf diff --git a/libs/sqf/tests/lints/s05_if_assign/source.sqf b/libs/sqf/tests/lints/s05_if_assign.sqf similarity index 100% rename from libs/sqf/tests/lints/s05_if_assign/source.sqf rename to libs/sqf/tests/lints/s05_if_assign.sqf diff --git a/libs/sqf/tests/lints/s06_find_in_str/source.sqf b/libs/sqf/tests/lints/s06_find_in_str.sqf similarity index 100% rename from libs/sqf/tests/lints/s06_find_in_str/source.sqf rename to libs/sqf/tests/lints/s06_find_in_str.sqf diff --git a/libs/sqf/tests/lints/s07_select_parse_number/source.sqf b/libs/sqf/tests/lints/s07_select_parse_number.sqf similarity index 100% rename from libs/sqf/tests/lints/s07_select_parse_number/source.sqf rename to libs/sqf/tests/lints/s07_select_parse_number.sqf diff --git a/libs/sqf/tests/lints/s08_format_args/source.sqf b/libs/sqf/tests/lints/s08_format_args.sqf similarity index 100% rename from libs/sqf/tests/lints/s08_format_args/source.sqf rename to libs/sqf/tests/lints/s08_format_args.sqf diff --git a/libs/sqf/tests/lints/s09_banned_command/source.sqf b/libs/sqf/tests/lints/s09_banned_command.sqf similarity index 100% rename from libs/sqf/tests/lints/s09_banned_command/source.sqf rename to libs/sqf/tests/lints/s09_banned_command.sqf diff --git a/libs/sqf/tests/lints/s11_if_not_else/source.sqf b/libs/sqf/tests/lints/s11_if_not_else.sqf similarity index 100% rename from libs/sqf/tests/lints/s11_if_not_else/source.sqf rename to libs/sqf/tests/lints/s11_if_not_else.sqf diff --git a/libs/sqf/tests/lints/s17_var_all_caps/source.sqf b/libs/sqf/tests/lints/s17_var_all_caps.sqf similarity index 100% rename from libs/sqf/tests/lints/s17_var_all_caps/source.sqf rename to libs/sqf/tests/lints/s17_var_all_caps.sqf diff --git a/libs/sqf/tests/lints/s18_in_vehicle_check/source.sqf b/libs/sqf/tests/lints/s18_in_vehicle_check.sqf similarity index 100% rename from libs/sqf/tests/lints/s18_in_vehicle_check/source.sqf rename to libs/sqf/tests/lints/s18_in_vehicle_check.sqf diff --git a/libs/sqf/tests/lints/s20_bool_static_comparison/source.sqf b/libs/sqf/tests/lints/s20_bool_static_comparison.sqf similarity index 100% rename from libs/sqf/tests/lints/s20_bool_static_comparison/source.sqf rename to libs/sqf/tests/lints/s20_bool_static_comparison.sqf diff --git a/libs/sqf/tests/lints/s21_invalid_comparisons/source.sqf b/libs/sqf/tests/lints/s21_invalid_comparisons.sqf similarity index 100% rename from libs/sqf/tests/lints/s21_invalid_comparisons/source.sqf rename to libs/sqf/tests/lints/s21_invalid_comparisons.sqf diff --git a/libs/sqf/tests/lints/s22_this_call/source.sqf b/libs/sqf/tests/lints/s22_this_call.sqf similarity index 100% rename from libs/sqf/tests/lints/s22_this_call/source.sqf rename to libs/sqf/tests/lints/s22_this_call.sqf diff --git a/libs/sqf/tests/lints/s23_reassign_reserved_variable/source.sqf b/libs/sqf/tests/lints/s23_reassign_reserved_variable.sqf similarity index 100% rename from libs/sqf/tests/lints/s23_reassign_reserved_variable/source.sqf rename to libs/sqf/tests/lints/s23_reassign_reserved_variable.sqf diff --git a/libs/sqf/tests/lints/s24_marker_spam/source.sqf b/libs/sqf/tests/lints/s24_marker_spam.sqf similarity index 100% rename from libs/sqf/tests/lints/s24_marker_spam/source.sqf rename to libs/sqf/tests/lints/s24_marker_spam.sqf diff --git a/libs/sqf/tests/optimizer.rs b/libs/sqf/tests/optimizer.rs index 10b03933..953a5c82 100644 --- a/libs/sqf/tests/optimizer.rs +++ b/libs/sqf/tests/optimizer.rs @@ -5,166 +5,33 @@ use hemtt_preprocessor::Processor; use hemtt_sqf::{parser::database::Database, Statements}; use hemtt_workspace::LayerType; +macro_rules! optimize { + ($dir:ident) => { + paste::paste! { + #[test] + fn []() { + insta::assert_debug_snapshot!(optimize(stringify!($dir))); + } + } + }; +} + +optimize!(consume_array); +optimize!(static_math); +optimize!(scalar); +optimize!(string_case); + const ROOT: &str = "tests/optimizer/"; -fn get_statements(dir: &str) -> Statements { - let folder = std::path::PathBuf::from(ROOT).join(dir); +fn optimize(file: &str) -> Statements { + let folder = std::path::PathBuf::from(ROOT); let workspace = hemtt_workspace::Workspace::builder() .physical(&folder, LayerType::Source) .finish(None, false, &hemtt_common::config::PDriveOption::Disallow) .unwrap(); - let source = workspace.join("source.sqf").unwrap(); + let source = workspace.join(format!("{file}.sqf")).unwrap(); let processed = Processor::run(&source).unwrap(); - hemtt_sqf::parser::run(&Database::a3(false), &processed).unwrap() -} - -#[cfg(test)] -mod tests { - use crate::get_statements; - use hemtt_sqf::{Expression, Scalar, Statement, UnaryCommand}; - - #[test] - pub fn test_1() { - let sqf = get_statements("test_1").optimize(); - // println!("debug sqf: {:?}", sqf); - - // -5; - let Statement::Expression(Expression::Number(value, _), _) = sqf.content()[0].clone() - else { - panic!(); - }; - assert_eq!(value, Scalar(-5.0)); - - // toLower "A" + toUpper "b" + toUpperAnsi "C" + toLowerAnsi "d"; - let Statement::Expression(Expression::String(value, _, _), _) = sqf.content()[1].clone() - else { - panic!(); - }; - assert_eq!(*value, *"aBCd"); - - // 1 + (2 * 2) + (36 % 31) + (36 / 6) + (sqrt 100) - 8; - let Statement::Expression(Expression::Number(value, _), _) = sqf.content()[2].clone() - else { - panic!(); - }; - assert_eq!(value, Scalar(23.0)); - - // z + z; - let Statement::Expression(Expression::BinaryCommand(..), _) = sqf.content()[3].clone() - else { - panic!(); - }; - - // params ["_a", "_b"]; - let Statement::Expression(Expression::UnaryCommand(_, arg_right, _), _) = - sqf.content()[4].clone() - else { - panic!(); - }; - assert!(matches!(*arg_right, Expression::ConsumeableArray(..))); - - // params ["_a", "_b", ["_c", []]]; - let Statement::Expression(Expression::UnaryCommand(_, arg_right, _), _) = - sqf.content()[5].clone() - else { - panic!(); - }; - let Expression::UnaryCommand(UnaryCommand::Plus, arg_plus, ..) = *arg_right else { - panic!(); - }; - assert!(matches!(*arg_plus, Expression::ConsumeableArray(..))); - - // missionNamespace getVariable ["a", -1]; - let Statement::Expression(Expression::BinaryCommand(_, _, arg_right, _), _) = - sqf.content()[6].clone() - else { - panic!(); - }; - assert!(matches!(*arg_right, Expression::ConsumeableArray(..))); - - // z setVariable ["b", [], true]; - let Statement::Expression(Expression::BinaryCommand(_, _, arg_right, _), _) = - sqf.content()[7].clone() - else { - panic!(); - }; - let Expression::UnaryCommand(UnaryCommand::Plus, arg_plus, ..) = *arg_right else { - panic!(); - }; - let Expression::ConsumeableArray(vec, ..) = *arg_plus else { - panic!(); - }; - assert_eq!(vec.len(), 3); - - // [1,0] vectorAdd p; - let Statement::Expression(Expression::BinaryCommand(_, arg_left, arg_right, _), _) = - sqf.content()[8].clone() - else { - panic!(); - }; - assert!(matches!(*arg_left, Expression::ConsumeableArray(..))); - assert!(matches!(*arg_right, Expression::Variable(..))); - - // positionCameraToWorld [10000, 0, 10000]; - let Statement::Expression(Expression::UnaryCommand(_, arg_right, _), _) = - sqf.content()[9].clone() - else { - panic!(); - }; - assert!(matches!(*arg_right, Expression::ConsumeableArray(..))); - - // random [0, _x, 1]; - let Statement::Expression(Expression::UnaryCommand(_, arg_right, _), _) = - sqf.content()[10].clone() - else { - panic!(); - }; - assert!(matches!(*arg_right, Expression::Array(..))); - - // private _z = if (time > 10) then { 1;2;3;4; } else { -1;-2; }; - let Statement::AssignLocal(_, Expression::BinaryCommand(_, _, arg_right, _), _) = - sqf.content()[11].clone() - else { - panic!(); - }; - let Expression::ConsumeableArray(else_vec, _) = *arg_right else { - panic!(); - }; - assert_eq!(else_vec.len(), 2); - let (Expression::Code(then_statements), Expression::Code(else_statements)) = - (else_vec[0].clone(), else_vec[1].clone()) - else { - panic!(); - }; - assert_eq!(then_statements.content().len(), 4); - assert_eq!(else_statements.content().len(), 2); - - // sqrt -100; - let Statement::Expression( - Expression::UnaryCommand(UnaryCommand::Named(_), arg_right, _), - _, - ) = sqf.content()[12].clone() - else { - panic!(); - }; - assert!(matches!(*arg_right, Expression::Number(..))); - - // param ["_d"]; - let Statement::Expression(Expression::UnaryCommand(_, arg_right, _), _) = - sqf.content()[13].clone() - else { - panic!(); - }; - assert!(matches!(*arg_right, Expression::ConsumeableArray(..))); - - // [] param ["_e"]; - let Statement::Expression(Expression::BinaryCommand(_, _, arg_right, _), _) = - sqf.content()[14].clone() - else { - panic!(); - }; - assert!(matches!(*arg_right, Expression::ConsumeableArray(..))); - - assert!(sqf.content().len() == 15); - } + hemtt_sqf::parser::run(&Database::a3(false), &processed) + .unwrap() + .optimize() } diff --git a/libs/sqf/tests/optimizer/test_1/source.sqf b/libs/sqf/tests/optimizer/consume_array.sqf similarity index 68% rename from libs/sqf/tests/optimizer/test_1/source.sqf rename to libs/sqf/tests/optimizer/consume_array.sqf index 4f34ca15..2ffc1bce 100644 --- a/libs/sqf/tests/optimizer/test_1/source.sqf +++ b/libs/sqf/tests/optimizer/consume_array.sqf @@ -1,15 +1,20 @@ --5; -toLower "A" + toUpper "b" + toUpperAnsi "C" + toLowerAnsi "d"; -1 + (2 * 2) + (36 % 31) + (36 / 6) + (sqrt 100) - 3; -z + z; params ["_a", "_b"]; + params ["_a", "_b", ["_c", []]]; + missionNamespace getVariable ["a", -1]; + z setVariable ["b", [], true]; + [1,0] vectorAdd p; + positionCameraToWorld [10000, 0, 10000]; + +// not consumable array random [0, _x, 1]; + private _z = if (time > 10) then { 1;2;3;4; } else { -1;-2; }; -sqrt -100; + param ["_d"]; + [] param ["_e"]; diff --git a/libs/sqf/tests/optimizer/scalar.sqf b/libs/sqf/tests/optimizer/scalar.sqf new file mode 100644 index 00000000..935b9cb5 --- /dev/null +++ b/libs/sqf/tests/optimizer/scalar.sqf @@ -0,0 +1 @@ +-5; diff --git a/libs/sqf/tests/optimizer/static_math.sqf b/libs/sqf/tests/optimizer/static_math.sqf new file mode 100644 index 00000000..6119ebbd --- /dev/null +++ b/libs/sqf/tests/optimizer/static_math.sqf @@ -0,0 +1,6 @@ +1 + (2 * 2) + (36 % 31) + (36 / 6) + (sqrt 100) - 3; + +sqrt -100; + +// ignored +z + z; diff --git a/libs/sqf/tests/optimizer/string_case.sqf b/libs/sqf/tests/optimizer/string_case.sqf new file mode 100644 index 00000000..dd219bfc --- /dev/null +++ b/libs/sqf/tests/optimizer/string_case.sqf @@ -0,0 +1 @@ +toLower "A" + toUpper "b" + toUpperAnsi "C" + toLowerAnsi "d"; diff --git a/libs/sqf/tests/preprocessor.rs b/libs/sqf/tests/preprocessor.rs deleted file mode 100644 index 08986fdb..00000000 --- a/libs/sqf/tests/preprocessor.rs +++ /dev/null @@ -1,40 +0,0 @@ -#![allow(clippy::unwrap_used)] - -use std::path::PathBuf; - -use hemtt_preprocessor::Processor; -use hemtt_sqf::parser::database::Database; -use hemtt_workspace::LayerType; - -const ROOT: &str = "tests/preprocessor/"; - -macro_rules! preprocess { - ($dir:ident) => { - paste::paste! { - #[test] - fn []() { - preprocess(stringify!($dir)); - } - } - }; -} - -fn preprocess(file: &str) { - let workspace = hemtt_workspace::Workspace::builder() - .physical(&PathBuf::from(ROOT), LayerType::Source) - .finish(None, false, &hemtt_common::config::PDriveOption::Disallow) - .unwrap(); - let source = workspace.join(format!("{file}.sqf")).unwrap(); - let processed = Processor::run(&source).unwrap(); - std::fs::write( - format!("tests/preprocessor/{file}.sqfp"), - processed.as_str(), - ) - .unwrap(); - let parsed = hemtt_sqf::parser::run(&Database::a3(false), &processed).unwrap(); - assert_ne!(parsed.content().len(), 0); - let mut buffer = Vec::new(); - parsed.compile_to_writer(&processed, &mut buffer).unwrap(); -} - -preprocess!(gvars); diff --git a/libs/sqf/tests/preprocessor/gvars.sqf b/libs/sqf/tests/preprocessor/gvars.sqf deleted file mode 100644 index 112fed21..00000000 --- a/libs/sqf/tests/preprocessor/gvars.sqf +++ /dev/null @@ -1,4 +0,0 @@ -#include "script_component.hpp" - -GVAR(test) = 1; -systemChat format ["%1 is %2", QGVAR(test), GVAR(test)]; diff --git a/libs/sqf/tests/preprocessor/script_component.hpp b/libs/sqf/tests/preprocessor/script_component.hpp deleted file mode 100644 index fa3fb34f..00000000 --- a/libs/sqf/tests/preprocessor/script_component.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#define COMPONENT main -#define COMPONENT_BEAUTIFIED Main -#include "script_mod.hpp" - -#ifdef DEBUG_ENABLED_MAIN - #define DEBUG_MODE_FULL -#endif - -#ifdef DEBUG_SETTINGS_MAIN - #define DEBUG_SETTINGS DEBUG_SETTINGS_MAIN -#endif - -#include "script_macros.hpp" diff --git a/libs/sqf/tests/preprocessor/script_macros.hpp b/libs/sqf/tests/preprocessor/script_macros.hpp deleted file mode 100644 index 940669a3..00000000 --- a/libs/sqf/tests/preprocessor/script_macros.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#define DEBUG_SYNCHRONOUS -#include "script_macros_common.hpp" - -// Default versioning level -#define DEFAULT_VERSIONING_LEVEL 2 - -#define DGVAR(varName) if(isNil "ABE_DEBUG_NAMESPACE") then { ABE_DEBUG_NAMESPACE = []; }; if(!(QUOTE(GVAR(varName)) in ABE_DEBUG_NAMESPACE)) then { PUSH(ABE_DEBUG_NAMESPACE, QUOTE(GVAR(varName))); }; GVAR(varName) -#define DVAR(varName) if(isNil "ABE_DEBUG_NAMESPACE") then { ABE_DEBUG_NAMESPACE = []; }; if(!(QUOTE(varName) in ABE_DEBUG_NAMESPACE)) then { PUSH(ABE_DEBUG_NAMESPACE, QUOTE(varName)); }; varName -#define DFUNC(var1) TRIPLES(ADDON,fnc,var1) -#define DEFUNC(var1,var2) TRIPLES(DOUBLES(PREFIX,var1),fnc,var2) - -#undef QFUNC -#undef QEFUNC -#define QFUNC(var1) QUOTE(DFUNC(var1)) -#define QEFUNC(var1,var2) QUOTE(DEFUNC(var1,var2)) - -#define GETVAR_SYS(var1,var2) getVariable [ARR_2(QUOTE(var1),var2)] -#define SETVAR_SYS(var1,var2) setVariable [ARR_2(QUOTE(var1),var2)] -#define SETPVAR_SYS(var1,var2) setVariable [ARR_3(QUOTE(var1),var2,true)] - -#undef GETVAR -#define GETVAR(var1,var2,var3) (var1 GETVAR_SYS(var2,var3)) -#define GETMVAR(var1,var2) (missionNamespace GETVAR_SYS(var1,var2)) -#define GETUVAR(var1,var2) (uiNamespace GETVAR_SYS(var1,var2)) -#define GETPRVAR(var1,var2) (profileNamespace GETVAR_SYS(var1,var2)) -#define GETPAVAR(var1,var2) (parsingNamespace GETVAR_SYS(var1,var2)) - -#undef SETVAR -#define SETVAR(var1,var2,var3) var1 SETVAR_SYS(var2,var3) -#define SETPVAR(var1,var2,var3) var1 SETPVAR_SYS(var2,var3) -#define SETMVAR(var1,var2) missionNamespace SETVAR_SYS(var1,var2) -#define SETUVAR(var1,var2) uiNamespace SETVAR_SYS(var1,var2) -#define SETPRVAR(var1,var2) profileNamespace SETVAR_SYS(var1,var2) -#define SETPAVAR(var1,var2) parsingNamespace SETVAR_SYS(var1,var2) - -#define GETGVAR(var1,var2) GETMVAR(GVAR(var1),var2) -#define GETEGVAR(var1,var2,var3) GETMVAR(EGVAR(var1,var2),var3) - -#define ARR_SELECT(ARRAY,INDEX,DEFAULT) (if (count ARRAY > INDEX) then {ARRAY select INDEX} else {DEFAULT}) diff --git a/libs/sqf/tests/preprocessor/script_macros_common.hpp b/libs/sqf/tests/preprocessor/script_macros_common.hpp deleted file mode 100644 index be13021c..00000000 --- a/libs/sqf/tests/preprocessor/script_macros_common.hpp +++ /dev/null @@ -1,1833 +0,0 @@ -/* - Header: script_macros_common.hpp - - Description: - A general set of useful macro functions for use by CBA itself or by any module that uses CBA. - - Authors: - Sickboy and Spooner -*/ - -/* **************************************************** - New - Should be exported to general addon - Aim: - - Simplify (shorten) the amount of characters required for repetitive tasks - - Provide a solid structure that can be dynamic and easy editable (Which sometimes means we cannot adhere to Aim #1 ;-) - An example is the path that is built from defines. Some available in this file, others in mods and addons. - - Follows Standard: - Object variables: PREFIX_COMPONENT - Main-object variables: PREFIX_main - Paths: MAINPREFIX\PREFIX\SUBPREFIX\COMPONENT\SCRIPTNAME.sqf - e.g: x\six\addons\sys_menu\fDate.sqf - - Usage: - define PREFIX and COMPONENT, then include this file - (Note, you could have a main addon for your mod, define the PREFIX in a macros.hpp, - and include this script_macros_common.hpp file. - Then in your addons, add a component.hpp, define the COMPONENT, - and include your mod's script_macros.hpp - In your scripts you can then include the addon's component.hpp with relative path) - - TODO: - - Try only to use 1 string type " vs ' - - Evaluate double functions, and simplification - - Evaluate naming scheme; current = prototype - - Evaluate "Debug" features.. - - Evaluate "create mini function per precompiled script, that will load the script on first usage, rather than on init" - - Also saw "Namespace" typeName, evaluate which we need :P - - Single/Multi player gamelogics? (Incase of MP, you would want only 1 gamelogic per component, which is pv'ed from server, etc) - */ - -#ifndef MAINPREFIX - #define MAINPREFIX x -#endif - -#ifndef SUBPREFIX - #define SUBPREFIX addons -#endif - -#ifndef MAINLOGIC - #define MAINLOGIC main -#endif - -#define ADDON DOUBLES(PREFIX,COMPONENT) -#define MAIN_ADDON DOUBLES(PREFIX,main) - -/* ------------------------------------------- -Macro: VERSION_CONFIG - Define CBA Versioning System config entries. - - VERSION should be a floating-point number (1 separator). - VERSION_STR is a string representation of the version. - VERSION_AR is an array representation of the version. - - VERSION must always be defined, otherwise it is 0. - VERSION_STR and VERSION_AR default to VERSION if undefined. - -Parameters: - None - -Example: - (begin example) - #define VERSION 1.0 - #define VERSION_STR 1.0.1 - #define VERSION_AR 1,0,1 - - class CfgPatches { - class MyMod_main { - VERSION_CONFIG; - }; - }; - (end) - -Author: - ?, Jonpas -------------------------------------------- */ -#ifndef VERSION - #define VERSION 0 -#endif - -#ifndef VERSION_STR - #define VERSION_STR VERSION -#endif - -#ifndef VERSION_AR - #define VERSION_AR VERSION -#endif - -#ifndef VERSION_CONFIG - #define VERSION_CONFIG version = VERSION; versionStr = QUOTE(VERSION_STR); versionAr[] = {VERSION_AR} -#endif - -/* ------------------------------------------- -Group: Debugging -------------------------------------------- */ - -/* ------------------------------------------- -Macros: DEBUG_MODE_x - Managing debugging based on debug level. - - According to the *highest* level of debugging that has been defined *before* script_macros_common.hpp is included, - only the appropriate debugging commands will be functional. With no level explicitely defined, assume DEBUG_MODE_NORMAL. - - DEBUG_MODE_FULL - Full debugging output. - DEBUG_MODE_NORMAL - All debugging except and (Default setting if none specified). - DEBUG_MODE_MINIMAL - Only and enabled. - -Examples: - In order to turn on full debugging for a single file, - (begin example) - // Top of individual script file. - #define DEBUG_MODE_FULL - #include "script_component.hpp" - (end) - - In order to force minimal debugging for a single component, - (begin example) - // Top of addons\\script_component.hpp - // Ensure that any FULL and NORMAL setting from the individual files are undefined and MINIMAL is set. - #ifdef DEBUG_MODE_FULL - #undef DEBUG_MODE_FULL - #endif - #ifdef DEBUG_MODE_NORMAL - #undef DEBUG_MODE_NORMAL - #endif - #ifndef DEBUG_MODE_MINIMAL - #define DEBUG_MODE_MINIMAL - #endif - #include "script_macros.hpp" - (end) - - In order to turn on full debugging for a whole addon, - (begin example) - // Top of addons\main\script_macros.hpp - #ifndef DEBUG_MODE_FULL - #define DEBUG_MODE_FULL - #endif - #include "\x\cba\addons\main\script_macros_common.hpp" - (end) - -Author: - Spooner -------------------------------------------- */ - -// If DEBUG_MODE_FULL, then also enable DEBUG_MODE_NORMAL. -#ifdef DEBUG_MODE_FULL -#define DEBUG_MODE_NORMAL -#endif - -// If DEBUG_MODE_NORMAL, then also enable DEBUG_MODE_MINIMAL. -#ifdef DEBUG_MODE_NORMAL -#define DEBUG_MODE_MINIMAL -#endif - -// If no debug modes specified, use DEBUG_MODE_NORMAL (+ DEBUG_MODE_MINIMAL). -#ifndef DEBUG_MODE_MINIMAL -#define DEBUG_MODE_NORMAL -#define DEBUG_MODE_MINIMAL -#endif - -#define LOG_SYS_FORMAT(LEVEL,MESSAGE) format ['[%1] (%2) %3: %4', toUpper 'PREFIX', 'COMPONENT', LEVEL, MESSAGE] - -#ifdef DEBUG_SYNCHRONOUS -#define LOG_SYS(LEVEL,MESSAGE) diag_log text LOG_SYS_FORMAT(LEVEL,MESSAGE) -#else -#define LOG_SYS(LEVEL,MESSAGE) LOG_SYS_FORMAT(LEVEL,MESSAGE) call CBA_fnc_log -#endif - -#define LOG_SYS_FILELINENUMBERS(LEVEL,MESSAGE) LOG_SYS(LEVEL,format [ARR_4('%1 %2:%3',MESSAGE,__FILE__,__LINE__ + 1)]) - -/* ------------------------------------------- -Macro: LOG() - Log a debug message into the RPT log. - - Only run if is defined. - -Parameters: - MESSAGE - Message to record - -Example: - (begin example) - LOG("Initiated clog-dancing simulator."); - (end) - -Author: - Spooner -------------------------------------------- */ -#ifdef DEBUG_MODE_FULL - -#define LOG(MESSAGE) LOG_SYS('LOG',MESSAGE) -#define LOG_1(MESSAGE,ARG1) LOG(FORMAT_1(MESSAGE,ARG1)) -#define LOG_2(MESSAGE,ARG1,ARG2) LOG(FORMAT_2(MESSAGE,ARG1,ARG2)) -#define LOG_3(MESSAGE,ARG1,ARG2,ARG3) LOG(FORMAT_3(MESSAGE,ARG1,ARG2,ARG3)) -#define LOG_4(MESSAGE,ARG1,ARG2,ARG3,ARG4) LOG(FORMAT_4(MESSAGE,ARG1,ARG2,ARG3,ARG4)) -#define LOG_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5) LOG(FORMAT_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5)) -#define LOG_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6) LOG(FORMAT_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6)) -#define LOG_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7) LOG(FORMAT_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7)) -#define LOG_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8) LOG(FORMAT_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8)) - -#else - -#define LOG(MESSAGE) /* disabled */ -#define LOG_1(MESSAGE,ARG1) /* disabled */ -#define LOG_2(MESSAGE,ARG1,ARG2) /* disabled */ -#define LOG_3(MESSAGE,ARG1,ARG2,ARG3) /* disabled */ -#define LOG_4(MESSAGE,ARG1,ARG2,ARG3,ARG4) /* disabled */ -#define LOG_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5) /* disabled */ -#define LOG_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6) /* disabled */ -#define LOG_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7) /* disabled */ -#define LOG_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8) /* disabled */ - -#endif - -/* ------------------------------------------- -Macro: INFO() - Record a message without file and line number in the RPT log. - -Parameters: - MESSAGE - Message to record - -Example: - (begin example) - INFO("Mod X is loaded, do Y"); - (end) - -Author: - commy2 -------------------------------------------- */ -#define INFO(MESSAGE) LOG_SYS('INFO',MESSAGE) -#define INFO_1(MESSAGE,ARG1) INFO(FORMAT_1(MESSAGE,ARG1)) -#define INFO_2(MESSAGE,ARG1,ARG2) INFO(FORMAT_2(MESSAGE,ARG1,ARG2)) -#define INFO_3(MESSAGE,ARG1,ARG2,ARG3) INFO(FORMAT_3(MESSAGE,ARG1,ARG2,ARG3)) -#define INFO_4(MESSAGE,ARG1,ARG2,ARG3,ARG4) INFO(FORMAT_4(MESSAGE,ARG1,ARG2,ARG3,ARG4)) -#define INFO_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5) INFO(FORMAT_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5)) -#define INFO_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6) INFO(FORMAT_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6)) -#define INFO_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7) INFO(FORMAT_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7)) -#define INFO_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8) INFO(FORMAT_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8)) - -/* ------------------------------------------- -Macro: WARNING() - Record a non-critical error in the RPT log. - - Only run if or higher is defined. - -Parameters: - MESSAGE - Message to record - -Example: - (begin example) - WARNING("This function has been deprecated. Please don't use it in future!"); - (end) - -Author: - Spooner -------------------------------------------- */ -#ifdef DEBUG_MODE_NORMAL - -#define WARNING(MESSAGE) LOG_SYS('WARNING',MESSAGE) -#define WARNING_1(MESSAGE,ARG1) WARNING(FORMAT_1(MESSAGE,ARG1)) -#define WARNING_2(MESSAGE,ARG1,ARG2) WARNING(FORMAT_2(MESSAGE,ARG1,ARG2)) -#define WARNING_3(MESSAGE,ARG1,ARG2,ARG3) WARNING(FORMAT_3(MESSAGE,ARG1,ARG2,ARG3)) -#define WARNING_4(MESSAGE,ARG1,ARG2,ARG3,ARG4) WARNING(FORMAT_4(MESSAGE,ARG1,ARG2,ARG3,ARG4)) -#define WARNING_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5) WARNING(FORMAT_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5)) -#define WARNING_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6) WARNING(FORMAT_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6)) -#define WARNING_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7) WARNING(FORMAT_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7)) -#define WARNING_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8) WARNING(FORMAT_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8)) - -#else - -#define WARNING(MESSAGE) /* disabled */ -#define WARNING_1(MESSAGE,ARG1) /* disabled */ -#define WARNING_2(MESSAGE,ARG1,ARG2) /* disabled */ -#define WARNING_3(MESSAGE,ARG1,ARG2,ARG3) /* disabled */ -#define WARNING_4(MESSAGE,ARG1,ARG2,ARG3,ARG4) /* disabled */ -#define WARNING_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5) /* disabled */ -#define WARNING_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6) /* disabled */ -#define WARNING_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7) /* disabled */ -#define WARNING_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8) /* disabled */ - -#endif - -/* ------------------------------------------- -Macro: ERROR() - Record a critical error in the RPT log. - -Parameters: - MESSAGE - Message to record - -Example: - (begin example) - ERROR("value of frog not found in config ...yada...yada..."); - (end) - -Author: - Spooner -------------------------------------------- */ -#define ERROR(MESSAGE) LOG_SYS('ERROR',MESSAGE) -#define ERROR_1(MESSAGE,ARG1) ERROR(FORMAT_1(MESSAGE,ARG1)) -#define ERROR_2(MESSAGE,ARG1,ARG2) ERROR(FORMAT_2(MESSAGE,ARG1,ARG2)) -#define ERROR_3(MESSAGE,ARG1,ARG2,ARG3) ERROR(FORMAT_3(MESSAGE,ARG1,ARG2,ARG3)) -#define ERROR_4(MESSAGE,ARG1,ARG2,ARG3,ARG4) ERROR(FORMAT_4(MESSAGE,ARG1,ARG2,ARG3,ARG4)) -#define ERROR_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5) ERROR(FORMAT_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5)) -#define ERROR_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6) ERROR(FORMAT_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6)) -#define ERROR_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7) ERROR(FORMAT_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7)) -#define ERROR_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8) ERROR(FORMAT_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8)) - -/* ------------------------------------------- -Macro: ERROR_MSG() - Record a critical error in the RPT log and display on screen error message. - - Newlines (\n) in the MESSAGE will be put on separate lines. - -Parameters: - MESSAGE - Message to record - -Example: - (begin example) - ERROR_MSG("value of frog not found in config ...yada...yada..."); - (end) - -Author: - commy2 -------------------------------------------- */ -#define ERROR_MSG(MESSAGE) ['PREFIX', 'COMPONENT', nil, MESSAGE, __FILE__, __LINE__ + 1] call CBA_fnc_error -#define ERROR_MSG_1(MESSAGE,ARG1) ERROR_MSG(FORMAT_1(MESSAGE,ARG1)) -#define ERROR_MSG_2(MESSAGE,ARG1,ARG2) ERROR_MSG(FORMAT_2(MESSAGE,ARG1,ARG2)) -#define ERROR_MSG_3(MESSAGE,ARG1,ARG2,ARG3) ERROR_MSG(FORMAT_3(MESSAGE,ARG1,ARG2,ARG3)) -#define ERROR_MSG_4(MESSAGE,ARG1,ARG2,ARG3,ARG4) ERROR_MSG(FORMAT_4(MESSAGE,ARG1,ARG2,ARG3,ARG4)) -#define ERROR_MSG_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5) ERROR_MSG(FORMAT_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5)) -#define ERROR_MSG_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6) ERROR_MSG(FORMAT_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6)) -#define ERROR_MSG_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7) ERROR_MSG(FORMAT_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7)) -#define ERROR_MSG_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8) ERROR_MSG(FORMAT_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8)) - -/* ------------------------------------------- -Macro: ERROR_WITH_TITLE() - Record a critical error in the RPT log. - - The title can be specified (in the heading is always just "ERROR") - Newlines (\n) in the MESSAGE will be put on separate lines. - -Parameters: - TITLE - Title of error message - MESSAGE - Body of error message - -Example: - (begin example) - ERROR_WITH_TITLE("Value not found","Value of frog not found in config ...yada...yada..."); - (end) - -Author: - Spooner -------------------------------------------- */ -#define ERROR_WITH_TITLE(TITLE,MESSAGE) ['PREFIX', 'COMPONENT', TITLE, MESSAGE, __FILE__, __LINE__ + 1] call CBA_fnc_error -#define ERROR_WITH_TITLE_1(TITLE,MESSAGE,ARG1) ERROR_WITH_TITLE(TITLE,FORMAT_1(MESSAGE,ARG1)) -#define ERROR_WITH_TITLE_2(TITLE,MESSAGE,ARG1,ARG2) ERROR_WITH_TITLE(TITLE,FORMAT_2(MESSAGE,ARG1,ARG2)) -#define ERROR_WITH_TITLE_3(TITLE,MESSAGE,ARG1,ARG2,ARG3) ERROR_WITH_TITLE(TITLE,FORMAT_3(MESSAGE,ARG1,ARG2,ARG3)) -#define ERROR_WITH_TITLE_4(TITLE,MESSAGE,ARG1,ARG2,ARG3,ARG4) ERROR_WITH_TITLE(TITLE,FORMAT_4(MESSAGE,ARG1,ARG2,ARG3,ARG4)) -#define ERROR_WITH_TITLE_5(TITLE,MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5) ERROR_WITH_TITLE(TITLE,FORMAT_5(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5)) -#define ERROR_WITH_TITLE_6(TITLE,MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6) ERROR_WITH_TITLE(TITLE,FORMAT_6(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6)) -#define ERROR_WITH_TITLE_7(TITLE,MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7) ERROR_WITH_TITLE(TITLE,FORMAT_7(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7)) -#define ERROR_WITH_TITLE_8(TITLE,MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8) ERROR_WITH_TITLE(TITLE,FORMAT_8(MESSAGE,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8)) - -/* ------------------------------------------- -Macro: MESSAGE_WITH_TITLE() - Record a single line in the RPT log. - -Parameters: - TITLE - Title of log message - MESSAGE - Body of message - -Example: - (begin example) - MESSAGE_WITH_TITLE("Value found","Value of frog found in config "); - (end) - -Author: - Killswitch -------------------------------------------- */ -#define MESSAGE_WITH_TITLE(TITLE,MESSAGE) LOG_SYS_FILELINENUMBERS(TITLE,MESSAGE) - -/* ------------------------------------------- -Macro: RETDEF() - If a variable is undefined, return the default value. Otherwise, return the - variable itself. - -Parameters: - VARIABLE - the variable to check - DEFAULT_VALUE - the default value to use if variable is undefined - -Example: - (begin example) - // _var is undefined - hintSilent format ["_var=%1", RETDEF(_var,5)]; // "_var=5" - _var = 7; - hintSilent format ["_var=%1", RETDEF(_var,5)]; // "_var=7" - (end example) -Author: - 654wak654 -------------------------------------------- */ -#define RETDEF(VARIABLE,DEFAULT_VALUE) (if (isNil {VARIABLE}) then [{DEFAULT_VALUE}, {VARIABLE}]) - -/* ------------------------------------------- -Macro: RETNIL() - If a variable is undefined, return the value nil. Otherwise, return the - variable itself. - -Parameters: - VARIABLE - the variable to check - -Example: - (begin example) - // _var is undefined - hintSilent format ["_var=%1", RETNIL(_var)]; // "_var=any" - (end example) - -Author: - Alef (see CBA issue #8514) -------------------------------------------- */ -#define RETNIL(VARIABLE) RETDEF(VARIABLE,nil) - -/* ------------------------------------------- -Macros: TRACE_n() - Log a message and 1-8 variables to the RPT log. - - Only run if is defined. - - TRACE_1(MESSAGE,A) - Log 1 variable. - TRACE_2(MESSAGE,A,B) - Log 2 variables. - TRACE_3(MESSAGE,A,B,C) - Log 3 variables. - TRACE_4(MESSAGE,A,B,C,D) - Log 4 variables. - TRACE_5(MESSAGE,A,B,C,D,E) - Log 5 variables. - TRACE_6(MESSAGE,A,B,C,D,E,F) - Log 6 variables. - TRACE_7(MESSAGE,A,B,C,D,E,F,G) - Log 7 variables. - TRACE_8(MESSAGE,A,B,C,D,E,F,G,H) - Log 8 variables. - TRACE_9(MESSAGE,A,B,C,D,E,F,G,H,I) - Log 9 variables. - -Parameters: - MESSAGE - Message to add to the trace [String] - A..H - Variable names to log values of [Any] - -Example: - (begin example) - TRACE_3("After takeoff",_vehicle player,getPos (_vehicle player), getPosASL (_vehicle player)); - (end) - -Author: - Spooner -------------------------------------------- */ -#define PFORMAT_1(MESSAGE,A) \ - format ['%1: A=%2', MESSAGE, RETNIL(A)] - -#define PFORMAT_2(MESSAGE,A,B) \ - format ['%1: A=%2, B=%3', MESSAGE, RETNIL(A), RETNIL(B)] - -#define PFORMAT_3(MESSAGE,A,B,C) \ - format ['%1: A=%2, B=%3, C=%4', MESSAGE, RETNIL(A), RETNIL(B), RETNIL(C)] - -#define PFORMAT_4(MESSAGE,A,B,C,D) \ - format ['%1: A=%2, B=%3, C=%4, D=%5', MESSAGE, RETNIL(A), RETNIL(B), RETNIL(C), RETNIL(D)] - -#define PFORMAT_5(MESSAGE,A,B,C,D,E) \ - format ['%1: A=%2, B=%3, C=%4, D=%5, E=%6', MESSAGE, RETNIL(A), RETNIL(B), RETNIL(C), RETNIL(D), RETNIL(E)] - -#define PFORMAT_6(MESSAGE,A,B,C,D,E,F) \ - format ['%1: A=%2, B=%3, C=%4, D=%5, E=%6, F=%7', MESSAGE, RETNIL(A), RETNIL(B), RETNIL(C), RETNIL(D), RETNIL(E), RETNIL(F)] - -#define PFORMAT_7(MESSAGE,A,B,C,D,E,F,G) \ - format ['%1: A=%2, B=%3, C=%4, D=%5, E=%6, F=%7, G=%8', MESSAGE, RETNIL(A), RETNIL(B), RETNIL(C), RETNIL(D), RETNIL(E), RETNIL(F), RETNIL(G)] - -#define PFORMAT_8(MESSAGE,A,B,C,D,E,F,G,H) \ - format ['%1: A=%2, B=%3, C=%4, D=%5, E=%6, F=%7, G=%8, H=%9', MESSAGE, RETNIL(A), RETNIL(B), RETNIL(C), RETNIL(D), RETNIL(E), RETNIL(F), RETNIL(G), RETNIL(H)] - -#define PFORMAT_9(MESSAGE,A,B,C,D,E,F,G,H,I) \ - format ['%1: A=%2, B=%3, C=%4, D=%5, E=%6, F=%7, G=%8, H=%9, I=%10', MESSAGE, RETNIL(A), RETNIL(B), RETNIL(C), RETNIL(D), RETNIL(E), RETNIL(F), RETNIL(G), RETNIL(H), RETNIL(I)] - - -#ifdef DEBUG_MODE_FULL -#define TRACE_1(MESSAGE,A) LOG_SYS_FILELINENUMBERS('TRACE',PFORMAT_1(str diag_frameNo + ' ' + (MESSAGE),A)) -#define TRACE_2(MESSAGE,A,B) LOG_SYS_FILELINENUMBERS('TRACE',PFORMAT_2(str diag_frameNo + ' ' + (MESSAGE),A,B)) -#define TRACE_3(MESSAGE,A,B,C) LOG_SYS_FILELINENUMBERS('TRACE',PFORMAT_3(str diag_frameNo + ' ' + (MESSAGE),A,B,C)) -#define TRACE_4(MESSAGE,A,B,C,D) LOG_SYS_FILELINENUMBERS('TRACE',PFORMAT_4(str diag_frameNo + ' ' + (MESSAGE),A,B,C,D)) -#define TRACE_5(MESSAGE,A,B,C,D,E) LOG_SYS_FILELINENUMBERS('TRACE',PFORMAT_5(str diag_frameNo + ' ' + (MESSAGE),A,B,C,D,E)) -#define TRACE_6(MESSAGE,A,B,C,D,E,F) LOG_SYS_FILELINENUMBERS('TRACE',PFORMAT_6(str diag_frameNo + ' ' + (MESSAGE),A,B,C,D,E,F)) -#define TRACE_7(MESSAGE,A,B,C,D,E,F,G) LOG_SYS_FILELINENUMBERS('TRACE',PFORMAT_7(str diag_frameNo + ' ' + (MESSAGE),A,B,C,D,E,F,G)) -#define TRACE_8(MESSAGE,A,B,C,D,E,F,G,H) LOG_SYS_FILELINENUMBERS('TRACE',PFORMAT_8(str diag_frameNo + ' ' + (MESSAGE),A,B,C,D,E,F,G,H)) -#define TRACE_9(MESSAGE,A,B,C,D,E,F,G,H,I) LOG_SYS_FILELINENUMBERS('TRACE',PFORMAT_9(str diag_frameNo + ' ' + (MESSAGE),A,B,C,D,E,F,G,H,I)) -#else -#define TRACE_1(MESSAGE,A) /* disabled */ -#define TRACE_2(MESSAGE,A,B) /* disabled */ -#define TRACE_3(MESSAGE,A,B,C) /* disabled */ -#define TRACE_4(MESSAGE,A,B,C,D) /* disabled */ -#define TRACE_5(MESSAGE,A,B,C,D,E) /* disabled */ -#define TRACE_6(MESSAGE,A,B,C,D,E,F) /* disabled */ -#define TRACE_7(MESSAGE,A,B,C,D,E,F,G) /* disabled */ -#define TRACE_8(MESSAGE,A,B,C,D,E,F,G,H) /* disabled */ -#define TRACE_9(MESSAGE,A,B,C,D,E,F,G,H,I) /* disabled */ -#endif - -/* ------------------------------------------- -Group: General -------------------------------------------- */ - -// ************************************* -// Internal Functions -#define DOUBLES(var1,var2) var1##_##var2 -#define TRIPLES(var1,var2,var3) var1##_##var2##_##var3 -#define QUOTE(var1) #var1 - -#ifdef MODULAR - #define COMPONENT_T DOUBLES(t,COMPONENT) - #define COMPONENT_M DOUBLES(m,COMPONENT) - #define COMPONENT_S DOUBLES(s,COMPONENT) - #define COMPONENT_C DOUBLES(c,COMPONENT) - #define COMPONENT_F COMPONENT_C -#else - #define COMPONENT_T COMPONENT - #define COMPONENT_M COMPONENT - #define COMPONENT_S COMPONENT - #define COMPONENT_F COMPONENT - #define COMPONENT_C COMPONENT -#endif - -/* ------------------------------------------- -Macro: INC() - -Description: - Increase a number by one. - -Parameters: - VAR - Variable to increment [Number] - -Example: - (begin example) - _counter = 0; - INC(_counter); - // _counter => 1 - (end) - -Author: - Spooner -------------------------------------------- */ -#define INC(var) var = (var) + 1 - -/* ------------------------------------------- -Macro: DEC() - -Description: - Decrease a number by one. - -Parameters: - VAR - Variable to decrement [Number] - -Example: - (begin example) - _counter = 99; - DEC(_counter); - // _counter => 98 - (end) - -Author: - Spooner -------------------------------------------- */ -#define DEC(var) var = (var) - 1 - -/* ------------------------------------------- -Macro: ADD() - -Description: - Add a value to a variable. Variable and value should be both Numbers or both Strings. - -Parameters: - VAR - Variable to add to [Number or String] - VALUE - Value to add [Number or String] - -Examples: - (begin example) - _counter = 2; - ADD(_counter,3); - // _counter => 5 - (end) - (begin example) - _str = "hello"; - ADD(_str," "); - ADD(_str,"Fred"); - // _str => "hello Fred" - (end) - -Author: - Sickboy -------------------------------------------- */ -#define ADD(var1,var2) var1 = (var1) + (var2) - -/* ------------------------------------------- -Macro: SUB() - -Description: - Subtract a value from a number variable. VAR and VALUE should both be Numbers. - -Parameters: - VAR - Variable to subtract from [Number] - VALUE - Value to subtract [Number] - -Examples: - (begin example) - _numChickens = 2; - SUB(_numChickens,3); - // _numChickens => -1 - (end) -------------------------------------------- */ -#define SUB(var1,var2) var1 = (var1) - (var2) - -/* ------------------------------------------- -Macro: REM() - -Description: - Remove an element from an array each time it occurs. - - This recreates the entire array, so use BIS_fnc_removeIndex if modification of the original array is required - or if only one of the elements that matches ELEMENT needs to be removed. - -Parameters: - ARRAY - Array to modify [Array] - ELEMENT - Element to remove [Any] - -Examples: - (begin example) - _array = [1, 2, 3, 4, 3, 8]; - REM(_array,3); - // _array = [1, 2, 4, 8]; - (end) - -Author: - Spooner -------------------------------------------- */ -#define REM(var1,var2) SUB(var1,[var2]) - -/* ------------------------------------------- -Macro: PUSH() - -Description: - Appends a single value onto the end of an ARRAY. Change is made to the ARRAY itself, not creating a new array. - -Parameters: - ARRAY - Array to push element onto [Array] - ELEMENT - Element to push [Any] - -Examples: - (begin example) - _fish = ["blue", "green", "smelly"]; - PUSH(_fish,"monkey-flavoured"); - // _fish => ["blue", "green", "smelly", "monkey-flavoured"] - (end) - -Author: - Spooner -------------------------------------------- */ -#define PUSH(var1,var2) (var1) pushBack (var2) - -/* ------------------------------------------- -Macro: MAP() -Description: - Applies given code to each element of the array, then assigns the - resulting array to the original -Parameters: - ARRAY - Array to be modified - CODE - Code that'll be applied to each element of the array. -Example: - (begin example) - _array = [1, 2, 3, 4, 3, 8]; - MAP(_array,_x + 1); - // _array is now [2, 3, 4, 5, 4, 9]; - (end) -Author: - 654wak654 -------------------------------------------- */ -#define MAP(ARR,CODE) ARR = ARR apply {CODE} - -/* ------------------------------------------- -Macro: FILTER() -Description: - Filters an array based on given code, then assigns the resulting array - to the original -Parameters: - ARRAY - Array to be filtered - CODE - Condition to pick elements -Example: - (begin example) - _array = [1, 2, 3, 4, 3, 8]; - FILTER(_array,_x % 2 == 0) - // _array is now [2, 4, 8]; - (end) -Author: - Commy2 -------------------------------------------- */ -#define FILTER(ARR,CODE) ARR = ARR select {CODE} - -/* ------------------------------------------- -Macro: UNIQUE() -Description: - Removes duplicate values in given array -Parameters: - ARRAY - The array to be modified -Example: - (begin example) - _someArray = [4, 4, 5, 5, 5, 2]; - UNIQUE(_someArray); - // _someArray is now [4, 5, 2] - (end) -Author: - Commy2 -------------------------------------------- */ -#define UNIQUE(ARR) ARR = ARR arrayIntersect ARR - -/* ------------------------------------------- -Macro: INTERSECTION() -Description: - Finds unique common elements between two arrays and assigns them - to the first array -Parameters: - ARRAY0 - The array to be modified - ARRAY1 - The array to find intersections with -Example: - (begin example) - _someArray = [1, 2, 3, 4, 5, 5]; - _anotherArray = [4, 5, 6, 7]; - INTERSECTION(_someArray,_anotherArray); - // _someArray is now [4, 5] - (end) -Author: - 654wak654 -------------------------------------------- */ -#define INTERSECTION(ARG0,ARG1) ARG0 = ARG0 arrayIntersect (ARG1) - -/* ------------------------------------------- -Macro: ISNILS() - -Description: - Sets a variable with a value, but only if it is undefined. - -Parameters: - VARIABLE - Variable to set [Any, not nil] - DEFAULT_VALUE - Value to set VARIABLE to if it is undefined [Any, not nil] - -Examples: - (begin example) - // _fish is undefined - ISNILS(_fish,0); - // _fish => 0 - (end) - (begin example) - _fish = 12; - // ...later... - ISNILS(_fish,0); - // _fish => 12 - (end) - -Author: - Sickboy -------------------------------------------- */ -#define ISNILS(VARIABLE,DEFAULT_VALUE) if (isNil #VARIABLE) then { VARIABLE = DEFAULT_VALUE } -#define ISNILS2(var1,var2,var3,var4) ISNILS(TRIPLES(var1,var2,var3),var4) -#define ISNILS3(var1,var2,var3) ISNILS(DOUBLES(var1,var2),var3) -#define ISNIL(var1,var2) ISNILS2(PREFIX,COMPONENT,var1,var2) -#define ISNILMAIN(var1,var2) ISNILS3(PREFIX,var1,var2) - -#define CREATELOGICS(var1,var2) var1##_##var2 = ([sideLogic] call CBA_fnc_getSharedGroup) createUnit ["LOGIC", [0, 0, 0], [], 0, "NONE"] -#define CREATELOGICLOCALS(var1,var2) var1##_##var2 = "LOGIC" createVehicleLocal [0, 0, 0] -#define CREATELOGICGLOBALS(var1,var2) var1##_##var2 = ([sideLogic] call CBA_fnc_getSharedGroup) createUnit ["LOGIC", [0, 0, 0], [], 0, "NONE"]; publicVariable QUOTE(DOUBLES(var1,var2)) -#define CREATELOGICGLOBALTESTS(var1,var2) var1##_##var2 = ([sideLogic] call CBA_fnc_getSharedGroup) createUnit [QUOTE(DOUBLES(ADDON,logic)), [0, 0, 0], [], 0, "NONE"] - -#define GETVARS(var1,var2,var3) (var1##_##var2 getVariable #var3) -#define GETVARMAINS(var1,var2) GETVARS(var1,MAINLOGIC,var2) - -#ifndef PATHTO_SYS - #define PATHTO_SYS(var1,var2,var3) \MAINPREFIX\var1\SUBPREFIX\var2\var3.sqf -#endif -#ifndef PATHTOF_SYS - #define PATHTOF_SYS(var1,var2,var3) \MAINPREFIX\var1\SUBPREFIX\var2\var3 -#endif - -#ifndef PATHTOF2_SYS - #define PATHTOF2_SYS(var1,var2,var3) MAINPREFIX\var1\SUBPREFIX\var2\var3 -#endif - -#define PATHTO_R(var1) PATHTOF2_SYS(PREFIX,COMPONENT_C,var1) -#define PATHTO_T(var1) PATHTOF_SYS(PREFIX,COMPONENT_T,var1) -#define PATHTO_M(var1) PATHTOF_SYS(PREFIX,COMPONENT_M,var1) -#define PATHTO_S(var1) PATHTOF_SYS(PREFIX,COMPONENT_S,var1) -#define PATHTO_C(var1) PATHTOF_SYS(PREFIX,COMPONENT_C,var1) -#define PATHTO_F(var1) PATHTO_SYS(PREFIX,COMPONENT_F,var1) - -// Already quoted "" -#define QPATHTO_R(var1) QUOTE(PATHTO_R(var1)) -#define QPATHTO_T(var1) QUOTE(PATHTO_T(var1)) -#define QPATHTO_M(var1) QUOTE(PATHTO_M(var1)) -#define QPATHTO_S(var1) QUOTE(PATHTO_S(var1)) -#define QPATHTO_C(var1) QUOTE(PATHTO_C(var1)) -#define QPATHTO_F(var1) QUOTE(PATHTO_F(var1)) - -// This only works for binarized configs after recompiling the pbos -// TODO: Reduce amount of calls / code.. -#define COMPILE_FILE2_CFG_SYS(var1) compile preprocessFileLineNumbers var1 -#define COMPILE_FILE2_SYS(var1) COMPILE_FILE2_CFG_SYS(var1) - -#define COMPILE_FILE_SYS(var1,var2,var3) COMPILE_FILE2_SYS('PATHTO_SYS(var1,var2,var3)') -#define COMPILE_FILE_CFG_SYS(var1,var2,var3) COMPILE_FILE2_CFG_SYS('PATHTO_SYS(var1,var2,var3)') - -#define SETVARS(var1,var2) var1##_##var2 setVariable -#define SETVARMAINS(var1) SETVARS(var1,MAINLOGIC) -#define GVARMAINS(var1,var2) var1##_##var2 -#define CFGSETTINGSS(var1,var2) configFile >> "CfgSettings" >> #var1 >> #var2 -//#define SETGVARS(var1,var2,var3) var1##_##var2##_##var3 = -//#define SETGVARMAINS(var1,var2) var1##_##var2 = - -// Compile-Once, JIT: On first use. -// #define PREPMAIN_SYS(var1,var2,var3) var1##_fnc_##var3 = { var1##_fnc_##var3 = COMPILE_FILE_SYS(var1,var2,DOUBLES(fnc,var3)); if (isNil "_this") then { call var1##_fnc_##var3 } else { _this call var1##_fnc_##var3 } } -// #define PREP_SYS(var1,var2,var3) var1##_##var2##_fnc_##var3 = { var1##_##var2##_fnc_##var3 = COMPILE_FILE_SYS(var1,var2,DOUBLES(fnc,var3)); if (isNil "_this") then { call var1##_##var2##_fnc_##var3 } else { _this call var1##_##var2##_fnc_##var3 } } -// #define PREP_SYS2(var1,var2,var3,var4) var1##_##var2##_fnc_##var4 = { var1##_##var2##_fnc_##var4 = COMPILE_FILE_SYS(var1,var3,DOUBLES(fnc,var4)); if (isNil "_this") then { call var1##_##var2##_fnc_##var4 } else { _this call var1##_##var2##_fnc_##var4 } } - -// Compile-Once, at Macro. As opposed to Compile-Once, on first use. -#define PREPMAIN_SYS(var1,var2,var3) var1##_fnc_##var3 = COMPILE_FILE_SYS(var1,var2,DOUBLES(fnc,var3)) -#define PREP_SYS(var1,var2,var3) var1##_##var2##_fnc_##var3 = COMPILE_FILE_SYS(var1,var2,DOUBLES(fnc,var3)) -#define PREP_SYS2(var1,var2,var3,var4) var1##_##var2##_fnc_##var4 = COMPILE_FILE_SYS(var1,var3,DOUBLES(fnc,var4)) - -#define LSTR(var1) TRIPLES(ADDON,STR,var1) - -#ifndef DEBUG_SETTINGS - #define DEBUG_SETTINGS [false, true, false] -#endif - -#define MSG_INIT QUOTE(Initializing: ADDON version: VERSION) - -// ************************************* -// User Functions -#define CFGSETTINGS CFGSETTINGSS(PREFIX,COMPONENT) -#define PATHTO(var1) PATHTO_SYS(PREFIX,COMPONENT_F,var1) -#define PATHTOF(var1) PATHTOF_SYS(PREFIX,COMPONENT,var1) -#define PATHTOEF(var1,var2) PATHTOF_SYS(PREFIX,var1,var2) -#define QPATHTOF(var1) QUOTE(PATHTOF(var1)) -#define QPATHTOEF(var1,var2) QUOTE(PATHTOEF(var1,var2)) - -#define COMPILE_FILE(var1) COMPILE_FILE_SYS(PREFIX,COMPONENT_F,var1) -#define COMPILE_FILE_CFG(var1) COMPILE_FILE_CFG_SYS(PREFIX,COMPONENT_F,var1) -#define COMPILE_FILE2(var1) COMPILE_FILE2_SYS('var1') -#define COMPILE_FILE2_CFG(var1) COMPILE_FILE2_CFG_SYS('var1') - -#define COMPILE_SCRIPT(var1) compileScript ['PATHTO_SYS(PREFIX,COMPONENT_F,var1)'] - - -#define VERSIONING_SYS(var1) class CfgSettings \ -{ \ - class CBA \ - { \ - class Versioning \ - { \ - class var1 \ - { \ - }; \ - }; \ - }; \ -}; - -#define VERSIONING VERSIONING_SYS(PREFIX) - -/* ------------------------------------------- -Macro: GVAR() - Get full variable identifier for a global variable owned by this component. - -Parameters: - VARIABLE - Partial name of global variable owned by this component [Any]. - -Example: - (begin example) - GVAR(frog) = 12; - // In SPON_FrogDancing component, equivalent to SPON_FrogDancing_frog = 12 - (end) - -Author: - Sickboy -------------------------------------------- */ -#define GVAR(var1) DOUBLES(ADDON,var1) -#define EGVAR(var1,var2) TRIPLES(PREFIX,var1,var2) -#define QGVAR(var1) QUOTE(GVAR(var1)) -#define QEGVAR(var1,var2) QUOTE(EGVAR(var1,var2)) -#define QQGVAR(var1) QUOTE(QGVAR(var1)) -#define QQEGVAR(var1,var2) QUOTE(QEGVAR(var1,var2)) - -/* ------------------------------------------- -Macro: GVARMAIN() - Get full variable identifier for a global variable owned by this addon. - -Parameters: - VARIABLE - Partial name of global variable owned by this addon [Any]. - -Example: - (begin example) - GVARMAIN(frog) = 12; - // In SPON_FrogDancing component, equivalent to SPON_frog = 12 - (end) - -Author: - Sickboy -------------------------------------------- */ -#define GVARMAIN(var1) GVARMAINS(PREFIX,var1) -#define QGVARMAIN(var1) QUOTE(GVARMAIN(var1)) -#define QQGVARMAIN(var1) QUOTE(QGVARMAIN(var1)) -// TODO: What's this? -#define SETTINGS DOUBLES(PREFIX,settings) -#define CREATELOGIC CREATELOGICS(PREFIX,COMPONENT) -#define CREATELOGICGLOBAL CREATELOGICGLOBALS(PREFIX,COMPONENT) -#define CREATELOGICGLOBALTEST CREATELOGICGLOBALTESTS(PREFIX,COMPONENT) -#define CREATELOGICLOCAL CREATELOGICLOCALS(PREFIX,COMPONENT) -#define CREATELOGICMAIN CREATELOGICS(PREFIX,MAINLOGIC) -#define GETVAR(var1) GETVARS(PREFIX,COMPONENT,var1) -#define SETVAR SETVARS(PREFIX,COMPONENT) -#define SETVARMAIN SETVARMAINS(PREFIX) -#define IFCOUNT(var1,var2,var3) if (count var1 > var2) then { var3 = var1 select var2 }; - -/* ------------------------------------------- -Macro: PREP() - -Description: - Defines a function. - - Full file path: - '\MAINPREFIX\PREFIX\SUBPREFIX\COMPONENT\fnc_.sqf' - - Resulting function name: - 'PREFIX_COMPONENT_' - - The PREP macro should be placed in a script run by a XEH preStart and XEH preInit event. - - The PREP macro allows for CBA function caching, which drastically speeds up load times. - Beware though that function caching is enabled by default and as such to disable it, you need to - #define DISABLE_COMPILE_CACHE above your #include "script_components.hpp" include! - - The function will be defined in ui and mission namespace. It can not be overwritten without - a mission restart. - -Parameters: - FUNCTION NAME - Name of the function, unquoted - -Examples: - (begin example) - PREP(banana); - call FUNC(banana); - (end) - -Author: - dixon13 - ------------------------------------------- */ -//#define PREP(var1) PREP_SYS(PREFIX,COMPONENT_F,var1) - -#ifdef DISABLE_COMPILE_CACHE - #define PREP(var1) TRIPLES(ADDON,fnc,var1) = compile preProcessFileLineNumbers 'PATHTO_SYS(PREFIX,COMPONENT_F,DOUBLES(fnc,var1))' - #define PREPMAIN(var1) TRIPLES(PREFIX,fnc,var1) = compile preProcessFileLineNumbers 'PATHTO_SYS(PREFIX,COMPONENT_F,DOUBLES(fnc,var1))' -#else - #define PREP(var1) ['PATHTO_SYS(PREFIX,COMPONENT_F,DOUBLES(fnc,var1))', 'TRIPLES(ADDON,fnc,var1)'] call SLX_XEH_COMPILE_NEW - #define PREPMAIN(var1) ['PATHTO_SYS(PREFIX,COMPONENT_F,DOUBLES(fnc,var1))', 'TRIPLES(PREFIX,fnc,var1)'] call SLX_XEH_COMPILE_NEW -#endif - -/* ------------------------------------------- -Macro: PATHTO_FNC() - -Description: - Defines a function inside CfgFunctions. - - Full file path in addons: - '\MAINPREFIX\PREFIX\SUBPREFIX\COMPONENT\fnc_.sqf' - Define 'RECOMPILE' to enable recompiling. - Define 'SKIP_FUNCTION_HEADER' to skip adding function header. - -Parameters: - FUNCTION NAME - Name of the function, unquoted - -Examples: - (begin example) - // file name: fnc_addPerFrameHandler.sqf - class CfgFunctions { - class CBA { - class Misc { - PATHTO_FNC(addPerFrameHandler); - }; - }; - }; - // -> CBA_fnc_addPerFrameHandler - (end) - -Author: - dixon13, commy2 - ------------------------------------------- */ -#ifdef RECOMPILE - #undef RECOMPILE - #define RECOMPILE recompile = 1 -#else - #define RECOMPILE recompile = 0 -#endif -// Set function header type: -1 - no header; 0 - default header; 1 - system header. -#ifdef SKIP_FUNCTION_HEADER - #define CFGFUNCTION_HEADER headerType = -1 -#else - #define CFGFUNCTION_HEADER headerType = 0 -#endif - -#define PATHTO_FNC(func) class func {\ - file = QPATHTOF(DOUBLES(fnc,func).sqf);\ - CFGFUNCTION_HEADER;\ - RECOMPILE;\ -} - -#define FUNC(var1) TRIPLES(ADDON,fnc,var1) -#define FUNCMAIN(var1) TRIPLES(PREFIX,fnc,var1) -#define FUNC_INNER(var1,var2) TRIPLES(DOUBLES(PREFIX,var1),fnc,var2) -#define EFUNC(var1,var2) FUNC_INNER(var1,var2) -#define QFUNC(var1) QUOTE(FUNC(var1)) -#define QFUNCMAIN(var1) QUOTE(FUNCMAIN(var1)) -#define QFUNC_INNER(var1,var2) QUOTE(FUNC_INNER(var1,var2)) -#define QEFUNC(var1,var2) QUOTE(EFUNC(var1,var2)) -#define QQFUNC(var1) QUOTE(QFUNC(var1)) -#define QQFUNCMAIN(var1) QUOTE(QFUNCMAIN(var1)) -#define QQFUNC_INNER(var1,var2) QUOTE(QFUNC_INNER(var1,var2)) -#define QQEFUNC(var1,var2) QUOTE(QEFUNC(var1,var2)) - -#ifndef PRELOAD_ADDONS - #define PRELOAD_ADDONS class CfgAddons \ -{ \ - class PreloadAddons \ - { \ - class ADDON \ - { \ - list[]={ QUOTE(ADDON) }; \ - }; \ - }; \ -} -#endif - -/* ------------------------------------------- -Macros: ARG_#() - Select from list of array arguments - -Parameters: - VARIABLE(1-8) - elements for the list - -Author: - Rommel -------------------------------------------- */ -#define ARG_1(A,B) ((A) select (B)) -#define ARG_2(A,B,C) (ARG_1(ARG_1(A,B),C)) -#define ARG_3(A,B,C,D) (ARG_1(ARG_2(A,B,C),D)) -#define ARG_4(A,B,C,D,E) (ARG_1(ARG_3(A,B,C,D),E)) -#define ARG_5(A,B,C,D,E,F) (ARG_1(ARG_4(A,B,C,D,E),F)) -#define ARG_6(A,B,C,D,E,F,G) (ARG_1(ARG_5(A,B,C,D,E,F),G)) -#define ARG_7(A,B,C,D,E,F,G,H) (ARG_1(ARG_6(A,B,C,D,E,E,F,G),H)) -#define ARG_8(A,B,C,D,E,F,G,H,I) (ARG_1(ARG_7(A,B,C,D,E,E,F,G,H),I)) - -/* ------------------------------------------- -Macros: ARR_#() - Create list from arguments. Useful for working around , in macro parameters. - 1-8 arguments possible. - -Parameters: - VARIABLE(1-8) - elements for the list - -Author: - Nou -------------------------------------------- */ -#define ARR_1(ARG1) ARG1 -#define ARR_2(ARG1,ARG2) ARG1, ARG2 -#define ARR_3(ARG1,ARG2,ARG3) ARG1, ARG2, ARG3 -#define ARR_4(ARG1,ARG2,ARG3,ARG4) ARG1, ARG2, ARG3, ARG4 -#define ARR_5(ARG1,ARG2,ARG3,ARG4,ARG5) ARG1, ARG2, ARG3, ARG4, ARG5 -#define ARR_6(ARG1,ARG2,ARG3,ARG4,ARG5,ARG6) ARG1, ARG2, ARG3, ARG4, ARG5, ARG6 -#define ARR_7(ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7) ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7 -#define ARR_8(ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8) ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8 - -/* ------------------------------------------- -Macros: FORMAT_#(STR, ARG1) - Format - Useful for working around , in macro parameters. - 1-8 arguments possible. - -Parameters: - STRING - string used by format - VARIABLE(1-8) - elements for usage in format - -Author: - Nou & Sickboy -------------------------------------------- */ -#define FORMAT_1(STR,ARG1) format[STR, ARG1] -#define FORMAT_2(STR,ARG1,ARG2) format[STR, ARG1, ARG2] -#define FORMAT_3(STR,ARG1,ARG2,ARG3) format[STR, ARG1, ARG2, ARG3] -#define FORMAT_4(STR,ARG1,ARG2,ARG3,ARG4) format[STR, ARG1, ARG2, ARG3, ARG4] -#define FORMAT_5(STR,ARG1,ARG2,ARG3,ARG4,ARG5) format[STR, ARG1, ARG2, ARG3, ARG4, ARG5] -#define FORMAT_6(STR,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6) format[STR, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6] -#define FORMAT_7(STR,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7) format[STR, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7] -#define FORMAT_8(STR,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8) format[STR, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8] - -// CONTROL(46) 12 -#define DISPLAY(A) (findDisplay A) -#define CONTROL(A) DISPLAY(A) displayCtrl - -/* ------------------------------------------- -Macros: IS_x() - Checking the data types of variables. - - IS_ARRAY() - Array - IS_BOOL() - Boolean - IS_BOOLEAN() - UI display handle(synonym for ) - IS_CODE() - Code block (i.e a compiled function) - IS_CONFIG() - Configuration - IS_CONTROL() - UI control handle. - IS_DISPLAY() - UI display handle. - IS_FUNCTION() - A compiled function (synonym for ) - IS_GROUP() - Group. - IS_INTEGER() - Is a number a whole number? - IS_LOCATION() - World location. - IS_NUMBER() - A floating point number (synonym for ) - IS_OBJECT() - World object. - IS_SCALAR() - Floating point number. - IS_SCRIPT() - A script handle (as returned by execVM and spawn commands). - IS_SIDE() - Game side. - IS_STRING() - World object. - IS_TEXT() - Structured text. - -Parameters: - VARIABLE - Variable to check if it is of a particular type [Any, not nil] - -Author: - Spooner -------------------------------------------- */ -#define IS_META_SYS(VAR,TYPE) (if (isNil {VAR}) then {false} else {(VAR) isEqualType TYPE}) -#define IS_ARRAY(VAR) IS_META_SYS(VAR,[]) -#define IS_BOOL(VAR) IS_META_SYS(VAR,false) -#define IS_CODE(VAR) IS_META_SYS(VAR,{}) -#define IS_CONFIG(VAR) IS_META_SYS(VAR,configNull) -#define IS_CONTROL(VAR) IS_META_SYS(VAR,controlNull) -#define IS_DISPLAY(VAR) IS_META_SYS(VAR,displayNull) -#define IS_GROUP(VAR) IS_META_SYS(VAR,grpNull) -#define IS_OBJECT(VAR) IS_META_SYS(VAR,objNull) -#define IS_SCALAR(VAR) IS_META_SYS(VAR,0) -#define IS_SCRIPT(VAR) IS_META_SYS(VAR,scriptNull) -#define IS_SIDE(VAR) IS_META_SYS(VAR,west) -#define IS_STRING(VAR) IS_META_SYS(VAR,"STRING") -#define IS_TEXT(VAR) IS_META_SYS(VAR,text "") -#define IS_LOCATION(VAR) IS_META_SYS(VAR,locationNull) - -#define IS_BOOLEAN(VAR) IS_BOOL(VAR) -#define IS_FUNCTION(VAR) IS_CODE(VAR) -#define IS_INTEGER(VAR) (if (IS_SCALAR(VAR)) then {floor (VAR) == (VAR)} else {false}) -#define IS_NUMBER(VAR) IS_SCALAR(VAR) - -#define FLOAT_TO_STRING(num) (if (_this == 0) then {"0"} else {str parseNumber (str (_this % _this) + str floor abs _this) + "." + (str (abs _this - floor abs _this) select [2]) + "0"}) - -/* ------------------------------------------- -Macro: SCRIPT() - Sets name of script (relies on PREFIX and COMPONENT values being #defined). - Define 'SKIP_SCRIPT_NAME' to skip adding scriptName. - -Parameters: - NAME - Name of script [Indentifier] - -Example: - (begin example) - SCRIPT(eradicateMuppets); - (end) - -Author: - Spooner -------------------------------------------- */ -#ifndef SKIP_SCRIPT_NAME - #define SCRIPT(NAME) scriptName 'PREFIX\COMPONENT\NAME' -#else - #define SCRIPT(NAME) /* nope */ -#endif - -/* ------------------------------------------- -Macros: EXPLODE_n() - DEPRECATED - Use param/params commands added in Arma 3 1.48 - - Splitting an ARRAY into a number of variables (A, B, C, etc). - - Note that this NOT does make the created variables private. - _PVT variants do. - - EXPLODE_1(ARRAY,A,B) - Split a 1-element array into separate variable. - EXPLODE_2(ARRAY,A,B) - Split a 2-element array into separate variables. - EXPLODE_3(ARRAY,A,B,C) - Split a 3-element array into separate variables. - EXPLODE_4(ARRAY,A,B,C,D) - Split a 4-element array into separate variables. - EXPLODE_5(ARRAY,A,B,C,D,E) - Split a 5-element array into separate variables. - EXPLODE_6(ARRAY,A,B,C,D,E,F) - Split a 6-element array into separate variables. - EXPLODE_7(ARRAY,A,B,C,D,E,F,G) - Split a 7-element array into separate variables. - EXPLODE_8(ARRAY,A,B,C,D,E,F,G,H) - Split a 8-element array into separate variables. - EXPLODE_9(ARRAY,A,B,C,D,E,F,G,H,I) - Split a 9-element array into separate variables. - -Parameters: - ARRAY - Array to read from [Array] - A..H - Names of variables to set from array [Identifier] - -Example: - (begin example) - _array = ["fred", 156.8, 120.9]; - EXPLODE_3(_array,_name,_height,_weight); - (end) - -Author: - Spooner -------------------------------------------- */ -#define EXPLODE_1_SYS(ARRAY,A) A = ARRAY param [0] -#define EXPLODE_1(ARRAY,A) EXPLODE_1_SYS(ARRAY,A); TRACE_1("EXPLODE_1, " + QUOTE(ARRAY),A) -#define EXPLODE_1_PVT(ARRAY,A) ARRAY params [#A]; TRACE_1("EXPLODE_1, " + QUOTE(ARRAY),A) - -#define EXPLODE_2_SYS(ARRAY,A,B) EXPLODE_1_SYS(ARRAY,A); B = ARRAY param [1] -#define EXPLODE_2(ARRAY,A,B) EXPLODE_2_SYS(ARRAY,A,B); TRACE_2("EXPLODE_2, " + QUOTE(ARRAY),A,B) -#define EXPLODE_2_PVT(ARRAY,A,B) ARRAY params [#A,#B]; TRACE_2("EXPLODE_2, " + QUOTE(ARRAY),A,B) - -#define EXPLODE_3_SYS(ARRAY,A,B,C) EXPLODE_2_SYS(ARRAY,A,B); C = ARRAY param [2] -#define EXPLODE_3(ARRAY,A,B,C) EXPLODE_3_SYS(ARRAY,A,B,C); TRACE_3("EXPLODE_3, " + QUOTE(ARRAY),A,B,C) -#define EXPLODE_3_PVT(ARRAY,A,B,C) ARRAY params [#A,#B,#C]; TRACE_3("EXPLODE_3, " + QUOTE(ARRAY),A,B,C) - -#define EXPLODE_4_SYS(ARRAY,A,B,C,D) EXPLODE_3_SYS(ARRAY,A,B,C); D = ARRAY param [3] -#define EXPLODE_4(ARRAY,A,B,C,D) EXPLODE_4_SYS(ARRAY,A,B,C,D); TRACE_4("EXPLODE_4, " + QUOTE(ARRAY),A,B,C,D) -#define EXPLODE_4_PVT(ARRAY,A,B,C,D) ARRAY params [#A,#B,#C,#D]; TRACE_4("EXPLODE_4, " + QUOTE(ARRAY),A,B,C,D) - -#define EXPLODE_5_SYS(ARRAY,A,B,C,D,E) EXPLODE_4_SYS(ARRAY,A,B,C,D); E = ARRAY param [4] -#define EXPLODE_5(ARRAY,A,B,C,D,E) EXPLODE_5_SYS(ARRAY,A,B,C,D,E); TRACE_5("EXPLODE_5, " + QUOTE(ARRAY),A,B,C,D,E) -#define EXPLODE_5_PVT(ARRAY,A,B,C,D,E) ARRAY params [#A,#B,#C,#D,#E]; TRACE_5("EXPLODE_5, " + QUOTE(ARRAY),A,B,C,D,E) - -#define EXPLODE_6_SYS(ARRAY,A,B,C,D,E,F) EXPLODE_5_SYS(ARRAY,A,B,C,D,E); F = ARRAY param [5] -#define EXPLODE_6(ARRAY,A,B,C,D,E,F) EXPLODE_6_SYS(ARRAY,A,B,C,D,E,F); TRACE_6("EXPLODE_6, " + QUOTE(ARRAY),A,B,C,D,E,F) -#define EXPLODE_6_PVT(ARRAY,A,B,C,D,E,F) ARRAY params [#A,#B,#C,#D,#E,#F]; TRACE_6("EXPLODE_6, " + QUOTE(ARRAY),A,B,C,D,E,F) - -#define EXPLODE_7_SYS(ARRAY,A,B,C,D,E,F,G) EXPLODE_6_SYS(ARRAY,A,B,C,D,E,F); G = ARRAY param [6] -#define EXPLODE_7(ARRAY,A,B,C,D,E,F,G) EXPLODE_7_SYS(ARRAY,A,B,C,D,E,F,G); TRACE_7("EXPLODE_7, " + QUOTE(ARRAY),A,B,C,D,E,F,G) -#define EXPLODE_7_PVT(ARRAY,A,B,C,D,E,F,G) ARRAY params [#A,#B,#C,#D,#E,#F,#G]; TRACE_7("EXPLODE_7, " + QUOTE(ARRAY),A,B,C,D,E,F,G) - -#define EXPLODE_8_SYS(ARRAY,A,B,C,D,E,F,G,H) EXPLODE_7_SYS(ARRAY,A,B,C,D,E,F,G); H = ARRAY param [7] -#define EXPLODE_8(ARRAY,A,B,C,D,E,F,G,H) EXPLODE_8_SYS(ARRAY,A,B,C,D,E,F,G,H); TRACE_8("EXPLODE_8, " + QUOTE(ARRAY),A,B,C,D,E,F,G,H) -#define EXPLODE_8_PVT(ARRAY,A,B,C,D,E,F,G,H) ARRAY params [#A,#B,#C,#D,#E,#F,#G,#H]; TRACE_8("EXPLODE_8, " + QUOTE(ARRAY),A,B,C,D,E,F,G,H) - -#define EXPLODE_9_SYS(ARRAY,A,B,C,D,E,F,G,H,I) EXPLODE_8_SYS(ARRAY,A,B,C,D,E,F,G,H); I = ARRAY param [8] -#define EXPLODE_9(ARRAY,A,B,C,D,E,F,G,H,I) EXPLODE_9_SYS(ARRAY,A,B,C,D,E,F,G,H,I); TRACE_9("EXPLODE_9, " + QUOTE(ARRAY),A,B,C,D,E,F,G,H,I) -#define EXPLODE_9_PVT(ARRAY,A,B,C,D,E,F,G,H,I) ARRAY params [#A,#B,#C,#D,#E,#F,#G,#H,#I]; TRACE_9("EXPLODE_9, " + QUOTE(ARRAY),A,B,C,D,E,F,G,H,I) - -/* ------------------------------------------- -Macro: xSTRING() - Get full string identifier from a stringtable owned by this component. - -Parameters: - VARIABLE - Partial name of global variable owned by this component [Any]. - -Example: - ADDON is CBA_Balls. - (begin example) - // Localized String (localize command must still be used with it) - LSTRING(Example); // STR_CBA_Balls_Example; - // Config String (note the $) - CSTRING(Example); // $STR_CBA_Balls_Example; - (end) - -Author: - Jonpas -------------------------------------------- */ -#ifndef STRING_MACROS_GUARD -#define STRING_MACROS_GUARD - #define LSTRING(var1) QUOTE(TRIPLES(STR,ADDON,var1)) - #define ELSTRING(var1,var2) QUOTE(TRIPLES(STR,DOUBLES(PREFIX,var1),var2)) - #define CSTRING(var1) QUOTE(TRIPLES($STR,ADDON,var1)) - #define ECSTRING(var1,var2) QUOTE(TRIPLES($STR,DOUBLES(PREFIX,var1),var2)) - - #define LLSTRING(var1) localize QUOTE(TRIPLES(STR,ADDON,var1)) - #define LELSTRING(var1,var2) localize QUOTE(TRIPLES(STR,DOUBLES(PREFIX,var1),var2)) -#endif - - -/* ------------------------------------------- -Group: Managing Function Parameters -------------------------------------------- */ - -/* ------------------------------------------- -Macros: PARAMS_n() - DEPRECATED - Use param/params commands added in Arma 3 1.48 - - Setting variables based on parameters passed to a function. - - Each parameter is defines as private and set to the appropriate value from _this. - - PARAMS_1(A) - Get 1 parameter from the _this array (or _this if it's not an array). - PARAMS_2(A,B) - Get 2 parameters from the _this array. - PARAMS_3(A,B,C) - Get 3 parameters from the _this array. - PARAMS_4(A,B,C,D) - Get 4 parameters from the _this array. - PARAMS_5(A,B,C,D,E) - Get 5 parameters from the _this array. - PARAMS_6(A,B,C,D,E,F) - Get 6 parameters from the _this array. - PARAMS_7(A,B,C,D,E,F,G) - Get 7 parameters from the _this array. - PARAMS_8(A,B,C,D,E,F,G,H) - Get 8 parameters from the _this array. - -Parameters: - A..H - Name of variable to read from _this [Identifier] - -Example: - A function called like this: - (begin example) - [_name,_address,_telephone] call recordPersonalDetails; - (end) - expects 3 parameters and those variables could be initialised at the start of the function definition with: - (begin example) - recordPersonalDetails = { - PARAMS_3(_name,_address,_telephone); - // Rest of function follows... - }; - (end) - -Author: - Spooner -------------------------------------------- */ -#define PARAMS_1(A) EXPLODE_1_PVT(_this,A) -#define PARAMS_2(A,B) EXPLODE_2_PVT(_this,A,B) -#define PARAMS_3(A,B,C) EXPLODE_3_PVT(_this,A,B,C) -#define PARAMS_4(A,B,C,D) EXPLODE_4_PVT(_this,A,B,C,D) -#define PARAMS_5(A,B,C,D,E) EXPLODE_5_PVT(_this,A,B,C,D,E) -#define PARAMS_6(A,B,C,D,E,F) EXPLODE_6_PVT(_this,A,B,C,D,E,F) -#define PARAMS_7(A,B,C,D,E,F,G) EXPLODE_7_PVT(_this,A,B,C,D,E,F,G) -#define PARAMS_8(A,B,C,D,E,F,G,H) EXPLODE_8_PVT(_this,A,B,C,D,E,F,G,H) -#define PARAMS_9(A,B,C,D,E,F,G,H,I) EXPLODE_9_PVT(_this,A,B,C,D,E,F,G,H,I) - -/* ------------------------------------------- -Macro: DEFAULT_PARAM() - DEPRECATED - Use param/params commands added in Arma 3 1.48 - - Getting a default function parameter. This may be used together with to have a mix of required and - optional parameters. - -Parameters: - INDEX - Index of parameter in _this [Integer, 0+] - NAME - Name of the variable to set [Identifier] - DEF_VALUE - Default value to use in case the array is too short or the value at INDEX is nil [Any] - -Example: - A function called with optional parameters: - (begin example) - [_name] call myFunction; - [_name, _numberOfLegs] call myFunction; - [_name, _numberOfLegs, _hasAHead] call myFunction; - (end) - 1 required parameter and 2 optional parameters. Those variables could be initialised at the start of the function - definition with: - (begin example) - myFunction = { - PARAMS_1(_name); - DEFAULT_PARAM(1,_numberOfLegs,2); - DEFAULT_PARAM(2,_hasAHead,true); - // Rest of function follows... - }; - (end) - -Author: - Spooner -------------------------------------------- */ -#define DEFAULT_PARAM(INDEX,NAME,DEF_VALUE) \ - private [#NAME,"_this"]; \ - ISNILS(_this,[]); \ - NAME = _this param [INDEX, DEF_VALUE]; \ - TRACE_3("DEFAULT_PARAM",INDEX,NAME,DEF_VALUE) - -/* ------------------------------------------- -Macro: KEY_PARAM() - Get value from key in _this list, return default when key is not included in list. - -Parameters: - KEY - Key name [String] - NAME - Name of the variable to set [Identifier] - DEF_VALUE - Default value to use in case key not found [ANY] - -Example: - - -Author: - Muzzleflash -------------------------------------------- */ -#define KEY_PARAM(KEY,NAME,DEF_VALUE) \ - private #NAME; \ - NAME = [toLower KEY, toUpper KEY, DEF_VALUE, RETNIL(_this)] call CBA_fnc_getArg; \ - TRACE_3("KEY_PARAM",KEY,NAME,DEF_VALUE) - -/* ------------------------------------------- -Group: Assertions -------------------------------------------- */ - -#define ASSERTION_ERROR(MESSAGE) ERROR_WITH_TITLE("Assertion failed!",MESSAGE) - -/* ------------------------------------------- -Macro: ASSERT_TRUE() - Asserts that a CONDITION is true. When an assertion fails, an error is raised with the given MESSAGE. - -Parameters: - CONDITION - Condition to assert as true [Boolean] - MESSSAGE - Message to display if (A OPERATOR B) is false [String] - -Example: - (begin example) - ASSERT_TRUE(_frogIsDead,"The frog is alive"); - (end) - -Author: - Spooner -------------------------------------------- */ -#define ASSERT_TRUE(CONDITION,MESSAGE) \ - if (not (CONDITION)) then \ - { \ - ASSERTION_ERROR('Assertion (CONDITION) failed!\n\n' + (MESSAGE)); \ - } - -/* ------------------------------------------- -Macro: ASSERT_FALSE() - Asserts that a CONDITION is false. When an assertion fails, an error is raised with the given MESSAGE. - -Parameters: - CONDITION - Condition to assert as false [Boolean] - MESSSAGE - Message to display if (A OPERATOR B) is true [String] - -Example: - (begin example) - ASSERT_FALSE(_frogIsDead,"The frog died"); - (end) - -Author: - Spooner -------------------------------------------- */ -#define ASSERT_FALSE(CONDITION,MESSAGE) \ - if (CONDITION) then \ - { \ - ASSERTION_ERROR('Assertion (not (CONDITION)) failed!\n\n' + (MESSAGE)) \ - } - -/* ------------------------------------------- -Macro: ASSERT_OP() - Asserts that (A OPERATOR B) is true. When an assertion fails, an error is raised with the given MESSAGE. - -Parameters: - A - First value [Any] - OPERATOR - Binary operator to use [Operator] - B - Second value [Any] - MESSSAGE - Message to display if (A OPERATOR B) is false. [String] - -Example: - (begin example) - ASSERT_OP(_fish,>,5,"Too few fish!"); - (end) - -Author: - Spooner -------------------------------------------- */ -#define ASSERT_OP(A,OPERATOR,B,MESSAGE) \ - if (not ((A) OPERATOR (B))) then \ - { \ - ASSERTION_ERROR('Assertion (A OPERATOR B) failed!\n' + 'A: ' + (str (A)) + '\n' + 'B: ' + (str (B)) + "\n\n" + (MESSAGE)); \ - } - -/* ------------------------------------------- -Macro: ASSERT_DEFINED() - Asserts that a VARIABLE is defined. When an assertion fails, an error is raised with the given MESSAGE.. - -Parameters: - VARIABLE - Variable to test if defined [String or Function]. - MESSAGE - Message to display if variable is undefined [String]. - -Examples: - (begin example) - ASSERT_DEFINED("_anUndefinedVar","Too few fish!"); - ASSERT_DEFINED({ obj getVariable "anUndefinedVar" },"Too many fish!"); - (end) - -Author: - Spooner -------------------------------------------- */ -#define ASSERT_DEFINED(VARIABLE,MESSAGE) \ - if (isNil VARIABLE) then \ - { \ - ASSERTION_ERROR('Assertion (VARIABLE is defined) failed!\n\n' + (MESSAGE)); \ - } - -/* ------------------------------------------- -Group: Unit tests -------------------------------------------- */ -#define TEST_SUCCESS(MESSAGE) MESSAGE_WITH_TITLE("Test OK",MESSAGE) -#define TEST_FAIL(MESSAGE) ERROR_WITH_TITLE("Test FAIL",MESSAGE) - -/* ------------------------------------------- -Macro: TEST_TRUE() - Tests that a CONDITION is true. - If the condition is not true, an error is raised with the given MESSAGE. - -Parameters: - CONDITION - Condition to assert as true [Boolean] - MESSSAGE - Message to display if (A OPERATOR B) is false [String] - -Example: - (begin example) - TEST_TRUE(_frogIsDead,"The frog is alive"); - (end) - -Author: - Killswitch -------------------------------------------- */ -#define TEST_TRUE(CONDITION, MESSAGE) \ - if (CONDITION) then \ - { \ - TEST_SUCCESS('(CONDITION)'); \ - } \ - else \ - { \ - TEST_FAIL('(CONDITION) ' + (MESSAGE)); \ - } - -/* ------------------------------------------- -Macro: TEST_FALSE() - Tests that a CONDITION is false. - If the condition is not false, an error is raised with the given MESSAGE. - -Parameters: - CONDITION - Condition to test as false [Boolean] - MESSSAGE - Message to display if (A OPERATOR B) is true [String] - -Example: - (begin example) - TEST_FALSE(_frogIsDead,"The frog died"); - (end) - -Author: - Killswitch -------------------------------------------- */ -#define TEST_FALSE(CONDITION, MESSAGE) \ - if (not (CONDITION)) then \ - { \ - TEST_SUCCESS('(not (CONDITION))'); \ - } \ - else \ - { \ - TEST_FAIL('(not (CONDITION)) ' + (MESSAGE)); \ - } - -/* ------------------------------------------- -Macro: TEST_OP() - Tests that (A OPERATOR B) is true. - If the test fails, an error is raised with the given MESSAGE. - -Parameters: - A - First value [Any] - OPERATOR - Binary operator to use [Operator] - B - Second value [Any] - MESSSAGE - Message to display if (A OPERATOR B) is false. [String] - -Example: - (begin example) - TEST_OP(_fish,>,5,"Too few fish!"); - (end) - -Author: - Killswitch -------------------------------------------- */ -#define TEST_OP(A,OPERATOR,B,MESSAGE) \ - if ((A) OPERATOR (B)) then \ - { \ - TEST_SUCCESS('(A OPERATOR B)') \ - } \ - else \ - { \ - TEST_FAIL('(A OPERATOR B)') \ - }; - -/* ------------------------------------------- -Macro: TEST_DEFINED_AND_OP() - Tests that A and B are defined and (A OPERATOR B) is true. - If the test fails, an error is raised with the given MESSAGE. - -Parameters: - A - First value [Any] - OPERATOR - Binary operator to use [Operator] - B - Second value [Any] - MESSSAGE - Message to display [String] - -Example: - (begin example) - TEST_OP(_fish,>,5,"Too few fish!"); - (end) - -Author: - Killswitch, PabstMirror -------------------------------------------- */ -#define TEST_DEFINED_AND_OP(A,OPERATOR,B,MESSAGE) \ - if (isNil #A) then { \ - TEST_FAIL('(A is not defined) ' + (MESSAGE)); \ - } else { \ - if (isNil #B) then { \ - TEST_FAIL('(B is not defined) ' + (MESSAGE)); \ - } else { \ - if ((A) OPERATOR (B)) then { \ - TEST_SUCCESS('(A OPERATOR B) ' + (MESSAGE)) \ - } else { \ - TEST_FAIL('(A OPERATOR B) ' + (MESSAGE)) \ - }; }; }; - - -/* ------------------------------------------- -Macro: TEST_DEFINED() - Tests that a VARIABLE is defined. - -Parameters: - VARIABLE - Variable to test if defined [String or Function]. - MESSAGE - Message to display if variable is undefined [String]. - -Examples: - (begin example) - TEST_DEFINED("_anUndefinedVar","Too few fish!"); - TEST_DEFINED({ obj getVariable "anUndefinedVar" },"Too many fish!"); - (end) - -Author: - Killswitch -------------------------------------------- */ -#define TEST_DEFINED(VARIABLE,MESSAGE) \ - if (not isNil VARIABLE) then \ - { \ - TEST_SUCCESS('(' + VARIABLE + ' is defined)'); \ - } \ - else \ - { \ - TEST_FAIL('(' + VARIABLE + ' is not defined)' + (MESSAGE)); \ - } - -/* ------------------------------------------- -Group: Managing Deprecation -------------------------------------------- */ - -/* ------------------------------------------- -Macro: DEPRECATE_SYS() - Allow deprecation of a function that has been renamed. - - Replaces an old OLD_FUNCTION (which will have PREFIX_ prepended) with a NEW_FUNCTION - (PREFIX_ prepended) with the intention that the old function will be disabled in the future. - - Shows a warning in RPT each time the deprecated function is used, but runs the new function. - -Parameters: - OLD_FUNCTION - Full name of old function [Identifier for function that does not exist any more] - NEW_FUNCTION - Full name of new function [Function] - -Example: - (begin example) - // After renaming CBA_fnc_frog as CBA_fnc_fish - DEPRECATE_SYS(CBA_fnc_frog,CBA_fnc_fish); - (end) - -Author: - Sickboy -------------------------------------------- */ -#define DEPRECATE_SYS(OLD_FUNCTION,NEW_FUNCTION) \ - OLD_FUNCTION = { \ - WARNING('Deprecated function used: OLD_FUNCTION (new: NEW_FUNCTION) in ADDON'); \ - if (isNil "_this") then { call NEW_FUNCTION } else { _this call NEW_FUNCTION }; \ - } - -/* ------------------------------------------- -Macro: DEPRECATE() - Allow deprecation of a function, in the current component, that has been renamed. - - Replaces an OLD_FUNCTION (which will have PREFIX_ prepended) with a NEW_FUNCTION - (PREFIX_ prepended) with the intention that the old function will be disabled in the future. - - Shows a warning in RPT each time the deprecated function is used, but runs the new function. - -Parameters: - OLD_FUNCTION - Name of old function, assuming PREFIX [Identifier for function that does not exist any more] - NEW_FUNCTION - Name of new function, assuming PREFIX [Function] - -Example: - (begin example) - // After renaming CBA_fnc_frog as CBA_fnc_fish - DEPRECATE(fnc_frog,fnc_fish); - (end) - -Author: - Sickboy -------------------------------------------- */ -#define DEPRECATE(OLD_FUNCTION,NEW_FUNCTION) \ - DEPRECATE_SYS(DOUBLES(PREFIX,OLD_FUNCTION),DOUBLES(PREFIX,NEW_FUNCTION)) - -/* ------------------------------------------- -Macro: OBSOLETE_SYS() - Replace a function that has become obsolete. - - Replace an obsolete OLD_FUNCTION with a simple COMMAND_FUNCTION, with the intention that anyone - using the function should replace it with the simple command, since the function will be disabled in the future. - - Shows a warning in RPT each time the deprecated function is used, and runs the command function. - -Parameters: - OLD_FUNCTION - Full name of old function [Identifier for function that does not exist any more] - COMMAND_CODE - Code to replace the old function [Function] - -Example: - (begin example) - // In Arma2, currentWeapon command made the CBA_fMyWeapon function obsolete: - OBSOLETE_SYS(CBA_fMyWeapon,{ currentWeapon player }); - (end) - -Author: - Spooner -------------------------------------------- */ -#define OBSOLETE_SYS(OLD_FUNCTION,COMMAND_CODE) \ - OLD_FUNCTION = { \ - WARNING('Obsolete function used: (use: OLD_FUNCTION) in ADDON'); \ - if (isNil "_this") then { call COMMAND_CODE } else { _this call COMMAND_CODE }; \ - } - -/* ------------------------------------------- -Macro: OBSOLETE() - Replace a function, in the current component, that has become obsolete. - - Replace an obsolete OLD_FUNCTION (which will have PREFIX_ prepended) with a simple - COMMAND_CODE, with the intention that anyone using the function should replace it with the simple - command. - - Shows a warning in RPT each time the deprecated function is used. - -Parameters: - OLD_FUNCTION - Name of old function, assuming PREFIX [Identifier for function that does not exist any more] - COMMAND_CODE - Code to replace the old function [Function] - -Example: - (begin example) - // In Arma2, currentWeapon command made the CBA_fMyWeapon function obsolete: - OBSOLETE(fMyWeapon,{ currentWeapon player }); - (end) - -Author: - Spooner -------------------------------------------- */ -#define OBSOLETE(OLD_FUNCTION,COMMAND_CODE) \ - OBSOLETE_SYS(DOUBLES(PREFIX,OLD_FUNCTION),COMMAND_CODE) - -#define BWC_CONFIG(NAME) class NAME { \ - units[] = {}; \ - weapons[] = {}; \ - requiredVersion = REQUIRED_VERSION; \ - requiredAddons[] = {}; \ - version = VERSION; \ -} - -// XEH Specific -#define XEH_CLASS CBA_Extended_EventHandlers -#define XEH_CLASS_BASE DOUBLES(XEH_CLASS,base) -#define XEH_DISABLED class EventHandlers { class XEH_CLASS {}; }; SLX_XEH_DISABLED = 1 -#define XEH_ENABLED class EventHandlers { class XEH_CLASS { EXTENDED_EVENTHANDLERS }; }; SLX_XEH_DISABLED = 0 - -// TODO: These are actually outdated; _Once ? -#define XEH_PRE_INIT QUOTE(call COMPILE_FILE(XEH_PreInit_Once)) -#define XEH_PRE_CINIT QUOTE(call COMPILE_FILE(XEH_PreClientInit_Once)) -#define XEH_PRE_SINIT QUOTE(call COMPILE_FILE(XEH_PreServerInit_Once)) - -#define XEH_POST_INIT QUOTE(call COMPILE_FILE(XEH_PostInit_Once)) -#define XEH_POST_CINIT QUOTE(call COMPILE_FILE(XEH_PostClientInit_Once)) -#define XEH_POST_SINIT QUOTE(call COMPILE_FILE(XEH_PostServerInit_Once)) - -/* ------------------------------------------- -Macro: IS_ADMIN - Check if the local machine is an admin in the multiplayer environment. - - Reports 'true' for logged and voted in admins. - -Parameters: - None - -Example: - (begin example) - // print "true" if player is admin - systemChat str IS_ADMIN; - (end) - -Author: - commy2 -------------------------------------------- */ -#define IS_ADMIN_SYS(x) x##kick -#define IS_ADMIN serverCommandAvailable 'IS_ADMIN_SYS(#)' - -/* ------------------------------------------- -Macro: IS_ADMIN_LOGGED - Check if the local machine is a logged in admin in the multiplayer environment. - - Reports 'false' if the player was voted to be the admin. - -Parameters: - None - -Example: - (begin example) - // print "true" if player is admin and entered in the server password - systemChat str IS_ADMIN_LOGGED; - (end) - -Author: - commy2 -------------------------------------------- */ -#define IS_ADMIN_LOGGED_SYS(x) x##shutdown -#define IS_ADMIN_LOGGED serverCommandAvailable 'IS_ADMIN_LOGGED_SYS(#)' - -/* ------------------------------------------- -Macro: FILE_EXISTS - Check if a file exists - - Reports "false" if the file does not exist. - -Parameters: - FILE - Path to the file - -Example: - (begin example) - // print "true" if file exists - systemChat str FILE_EXISTS("\A3\ui_f\data\igui\cfg\cursors\weapon_ca.paa"); - (end) - -Author: - commy2 -------------------------------------------- */ -#define FILE_EXISTS(FILE) (fileExists (FILE)) diff --git a/libs/sqf/tests/preprocessor/script_mod.hpp b/libs/sqf/tests/preprocessor/script_mod.hpp deleted file mode 100644 index fdb044d6..00000000 --- a/libs/sqf/tests/preprocessor/script_mod.hpp +++ /dev/null @@ -1,14 +0,0 @@ -// COMPONENT should be defined in the script_component.hpp and included BEFORE this hpp - -#define MAINPREFIX z -#define PREFIX abe - -// MINIMAL required version for the Mod. Components can specify others.. -#define REQUIRED_VERSION 2.10 -#define REQUIRED_CBA_VERSION {3,15,7} - -// #ifdef COMPONENT_BEAUTIFIED -// #define COMPONENT_NAME QUOTE(ACE3 - COMPONENT_BEAUTIFIED) -// #else - #define COMPONENT_NAME QUOTE(ACE3 - COMPONENT) -// #endif diff --git a/libs/sqf/tests/simple.rs b/libs/sqf/tests/simple.rs index c2559b9b..3f1e1ea7 100644 --- a/libs/sqf/tests/simple.rs +++ b/libs/sqf/tests/simple.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use hemtt_preprocessor::Processor; -use hemtt_sqf::parser::database::Database; +use hemtt_sqf::{parser::database::Database, Statement}; use hemtt_workspace::{reporting::WorkspaceFiles, LayerType}; const ROOT: &str = "tests/simple/"; @@ -13,13 +13,26 @@ macro_rules! simple { paste::paste! { #[test] fn []() { - simple(stringify!($dir)); + let (sqfc, ast) = simple(stringify!($dir)); + insta::assert_debug_snapshot!(sqfc); + insta::assert_debug_snapshot!(ast); } } }; } -fn simple(file: &str) { +simple!(dev); +simple!(eventhandler); +simple!(foreach); +simple!(format_font); +simple!(get_visibility); +simple!(hash_select); +simple!(hello); +simple!(include); +simple!(oneline); +simple!(semicolons); + +fn simple(file: &str) -> (Vec, Vec) { let workspace = hemtt_workspace::Workspace::builder() .physical(&PathBuf::from(ROOT), LayerType::Source) .finish(None, false, &hemtt_common::config::PDriveOption::Disallow) @@ -46,21 +59,11 @@ fn simple(file: &str) { assert_ne!(parsed.content().len(), 0); let mut buffer = Vec::new(); parsed.compile_to_writer(&processed, &mut buffer).unwrap(); - std::fs::write(format!("tests/simple/{file}.sqfc"), buffer).unwrap(); + std::fs::write(format!("tests/simple/{file}.sqfc"), &buffer).unwrap(); std::fs::write( format!("tests/simple/{file}.sqfast"), format!("{:#?}", parsed.content()), ) .unwrap(); + (buffer, parsed.content().to_vec()) } - -simple!(dev); -simple!(eventhandler); -simple!(foreach); -simple!(format_font); -simple!(get_visibility); -simple!(hash_select); -simple!(hello); -simple!(include); -simple!(oneline); -simple!(semicolons); diff --git a/libs/sqf/tests/errors/spe1_invalid_token/stderr.ansi b/libs/sqf/tests/snapshots/errors__errors_spe1_invalid_token.snap similarity index 59% rename from libs/sqf/tests/errors/spe1_invalid_token/stderr.ansi rename to libs/sqf/tests/snapshots/errors__errors_spe1_invalid_token.snap index 76b8b2c4..af1e30ca 100644 --- a/libs/sqf/tests/errors/spe1_invalid_token/stderr.ansi +++ b/libs/sqf/tests/snapshots/errors__errors_spe1_invalid_token.snap @@ -1,6 +1,9 @@ +--- +source: libs/sqf/tests/errors.rs +expression: errors(stringify! (spe1_invalid_token)) +--- error[SPE1]: invalid token - ┌─ source.sqf:1:9 + ┌─ spe1_invalid_token.sqf:1:9 │ 1 │ private ð = 0; │ ^ invalid token - diff --git a/libs/sqf/tests/errors/spe2_unparseable/stderr.ansi b/libs/sqf/tests/snapshots/errors__errors_spe2_unparseable.snap similarity index 60% rename from libs/sqf/tests/errors/spe2_unparseable/stderr.ansi rename to libs/sqf/tests/snapshots/errors__errors_spe2_unparseable.snap index 20de35a0..0002a183 100644 --- a/libs/sqf/tests/errors/spe2_unparseable/stderr.ansi +++ b/libs/sqf/tests/snapshots/errors__errors_spe2_unparseable.snap @@ -1,6 +1,9 @@ +--- +source: libs/sqf/tests/errors.rs +expression: errors(stringify! (spe2_unparseable)) +--- error[SPE2]: unparseable syntax - ┌─ source.sqf:1:1 + ┌─ spe2_unparseable.sqf:1:1 │ 1 │ getVariable │ ^^^^^^^^^^^ unparseable syntax - diff --git a/libs/sqf/tests/lints/s02_event_handler_case/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s02_event_handler_case.snap similarity index 73% rename from libs/sqf/tests/lints/s02_event_handler_case/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s02_event_handler_case.snap index 206787b2..afc12028 100644 --- a/libs/sqf/tests/lints/s02_event_handler_case/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s02_event_handler_case.snap @@ -1,8 +1,11 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s02_event_handler_case)) +--- warning[L-S02UE]: Using `ctrlAddEventHandler` with unknown event `lbdblclick` - ┌─ source.sqf:1:28 + ┌─ s02_event_handler_case.sqf:1:28 │ 1 │ _this ctrlAddEventHandler ["lbdblclick", { │ ^^^^^^^^^^^^ unknown event `lbdblclick` │ = help: Did you mean: `LBDblClick`? - diff --git a/libs/sqf/tests/lints/s03_static_typename/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s03_static_typename.snap similarity index 82% rename from libs/sqf/tests/lints/s03_static_typename/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s03_static_typename.snap index 97478a85..f0ddd4a9 100644 --- a/libs/sqf/tests/lints/s03_static_typename/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s03_static_typename.snap @@ -1,5 +1,9 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s03_static_typename)) +--- help[L-S03]: using `typeName` on a constant is slower than using the type directly - ┌─ source.sqf:1:6 + ┌─ s03_static_typename.sqf:1:6 │ 1 │ hint typeName []; │ ^^^^^^^^^^^ `typeName` on a constant @@ -8,7 +12,7 @@ help[L-S03]: using `typeName` on a constant is slower than using the type directly - ┌─ source.sqf:3:5 + ┌─ s03_static_typename.sqf:3:5 │ 3 │ if (typeName 0 == typeName _thing) then { │ ^^^^^^^^^^ `typeName` on a constant @@ -17,10 +21,9 @@ help[L-S03]: using `typeName` on a constant is slower than using the type directly - ┌─ source.sqf:9:24 + ┌─ s03_static_typename.sqf:9:24 │ 9 │ private _aliveIsBool = typeName true == typeName alive player; │ ^^^^^^^^^^^^^ `typeName` on a constant │ = try: "BOOL" - diff --git a/libs/sqf/tests/lints/s04_command_case/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s04_command_case.snap similarity index 80% rename from libs/sqf/tests/lints/s04_command_case/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s04_command_case.snap index c30f1e43..597c9b41 100644 --- a/libs/sqf/tests/lints/s04_command_case/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s04_command_case.snap @@ -1,5 +1,9 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s04_command_case)) +--- help[L-S04]: `surfaceiswater` does not match the wiki's case - ┌─ source.sqf:1:18 + ┌─ s04_command_case.sqf:1:18 │ 1 │ private _water = surfaceiswater getPos Player; │ ^^^^^^^^^^^^^^ non-standard command case @@ -8,10 +12,9 @@ help[L-S04]: `Player` does not match the wiki's case - ┌─ source.sqf:1:40 + ┌─ s04_command_case.sqf:1:40 │ 1 │ private _water = surfaceiswater getPos Player; │ ^^^^^^ non-standard command case │ = try: "player" - diff --git a/libs/sqf/tests/lints/s05_if_assign/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s05_if_assign.snap similarity index 89% rename from libs/sqf/tests/lints/s05_if_assign/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s05_if_assign.snap index b2babdd8..86a10b90 100644 --- a/libs/sqf/tests/lints/s05_if_assign/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s05_if_assign.snap @@ -1,5 +1,9 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s05_if_assign)) +--- help[L-S05]: assignment to if can be replaced with select - ┌─ source.sqf:1:24 + ┌─ s05_if_assign.sqf:1:24 │ 1 │ private _workingArms = if (alive player) then { 2 } else { 0 }; │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use select @@ -10,7 +14,7 @@ help[L-S05]: assignment to if can be replaced with select - ┌─ source.sqf:4:22 + ┌─ s05_if_assign.sqf:4:22 │ 4 │ private _thing = if (alive player) then { 2 } else { 0 }; │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use select @@ -21,7 +25,7 @@ help[L-S05]: assignment to if can be replaced with select - ┌─ source.sqf:7:5 + ┌─ s05_if_assign.sqf:7:5 │ 7 │ if (alive player) then { "torso" } else { "legs" }, │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use select @@ -32,7 +36,7 @@ help[L-S05]: assignment to if can be replaced with select - ┌─ source.sqf:8:5 + ┌─ s05_if_assign.sqf:8:5 │ 8 │ if (alive player) then { "torso" } else { "legs" } │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use select @@ -40,4 +44,3 @@ = note: the if and else blocks only return constant values select is faster in this case = try: ["legs", "torso"] select (alive player) - diff --git a/libs/sqf/tests/lints/s06_find_in_str/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s06_find_in_str.snap similarity index 79% rename from libs/sqf/tests/lints/s06_find_in_str/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s06_find_in_str.snap index a9457ac6..42e1733c 100644 --- a/libs/sqf/tests/lints/s06_find_in_str/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s06_find_in_str.snap @@ -1,5 +1,9 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s06_find_in_str)) +--- help[L-S06]: string search using `in` is faster than `find` - ┌─ source.sqf:1:1 + ┌─ s06_find_in_str.sqf:1:1 │ 1 │ "foobar" find "bar" > -1; │ ^^^^^^^^^^^^^^^^^^^^^^^^ using `find` with -1 @@ -8,10 +12,9 @@ help[L-S06]: string search using `in` is faster than `find` - ┌─ source.sqf:2:19 + ┌─ s06_find_in_str.sqf:2:19 │ 2 │ private _hasBar = _things find "bar" > -1; │ ^^^^^^^^^^^^^^^^^^^^^^^ using `find` with -1 │ = try: "bar" in _things - diff --git a/libs/sqf/tests/lints/s07_select_parse_number/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s07_select_parse_number.snap similarity index 84% rename from libs/sqf/tests/lints/s07_select_parse_number/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s07_select_parse_number.snap index d7c8517f..24e9e94c 100644 --- a/libs/sqf/tests/lints/s07_select_parse_number/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s07_select_parse_number.snap @@ -1,5 +1,9 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s07_select_parse_number)) +--- help[L-S07]: using `select` where `parseNumber` is more appropriate - ┌─ source.sqf:1:20 + ┌─ s07_select_parse_number.sqf:1:20 │ 1 │ private _isWater = [0, 1] select (surfaceIsWater getPos player); │ ^^^^^^ using `select` where `parseNumber` is more appropriate @@ -8,7 +12,7 @@ help[L-S07]: using `select` where `parseNumber` is more appropriate - ┌─ source.sqf:2:19 + ┌─ s07_select_parse_number.sqf:2:19 │ 2 │ private _isLand = [1, 0] select (surfaceIsWater getPos player); │ ^^^^^^ using `select` where `parseNumber` is more appropriate @@ -18,11 +22,10 @@ help[L-S07]: using `select` where `parseNumber` is more appropriate - ┌─ source.sqf:3:20 + ┌─ s07_select_parse_number.sqf:3:20 │ 3 │ private _isHEMTT = [1, 0] select (name player != "HEMTT"); │ ^^^^^^ using `select` where `parseNumber` is more appropriate │ = note: != is now == = try: parseNumber (name player == "HEMTT") - diff --git a/libs/sqf/tests/lints/s08_format_args/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s08_format_args.snap similarity index 89% rename from libs/sqf/tests/lints/s08_format_args/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s08_format_args.snap index 4f7c9fdb..2e621dbc 100644 --- a/libs/sqf/tests/lints/s08_format_args/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s08_format_args.snap @@ -1,5 +1,9 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s08_format_args)) +--- error[L-S08]: format string: empty array - ┌─ source.sqf:4:21 + ┌─ s08_format_args.sqf:4:21 │ 4 │ format [" • %1", 1]; │ ╭─────────────────────^ @@ -8,7 +12,7 @@ error[L-S08]: format string: unused args [used "%1", passed 3] - ┌─ source.sqf:5:11 + ┌─ s08_format_args.sqf:5:11 │ 5 │ format []; // empty array │ ╭───────────^ @@ -17,7 +21,7 @@ error[L-S08]: format string: undefined tokens [used "%2", passed 1] - ┌─ source.sqf:6:24 + ┌─ s08_format_args.sqf:6:24 │ 6 │ format ["%1", 1, 2, 3]; // unused args │ ╭────────────────────────^ @@ -26,7 +30,7 @@ error[L-S08]: format string: skipped tokens [used "%5", but only 1 tokens] - ┌─ source.sqf:7:20 + ┌─ s08_format_args.sqf:7:20 │ 7 │ format ["%1%2", 1]; // undefined tokens │ ╭────────────────────^ @@ -35,10 +39,9 @@ error[L-S08]: format string: undefined tokens [used "%1", passed 0] - ┌─ source.sqf:8:30 + ┌─ s08_format_args.sqf:8:30 │ 8 │ format ["%5", 1, 2 ,3 ,4, 5]; // skipped tokens │ ╭──────────────────────────────^ 9 │ │ formatText ["me too %1"]; │ ╰─────────────────────^ format string: undefined tokens [used "%1", passed 0] - diff --git a/libs/sqf/tests/lints/s09_banned_command/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s09_banned_command.snap similarity index 63% rename from libs/sqf/tests/lints/s09_banned_command/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s09_banned_command.snap index 49036f38..1baa26bc 100644 --- a/libs/sqf/tests/lints/s09_banned_command/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s09_banned_command.snap @@ -1,6 +1,9 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s09_banned_command)) +--- error[L-S09]: `echo` is marked as a broken command on the wiki - ┌─ source.sqf:1:1 + ┌─ s09_banned_command.sqf:1:1 │ 1 │ echo "Hello World!"; │ ^^^^ broken command - diff --git a/libs/sqf/tests/lints/s11_if_not_else/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s11_if_not_else.snap similarity index 65% rename from libs/sqf/tests/lints/s11_if_not_else/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s11_if_not_else.snap index 829ba57d..63ff3cc8 100644 --- a/libs/sqf/tests/lints/s11_if_not_else/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s11_if_not_else.snap @@ -1,6 +1,9 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s11_if_not_else)) +--- help[L-S11]: Unneeded not in if - ┌─ source.sqf:2:5 + ┌─ s11_if_not_else.sqf:2:5 │ 2 │ if (!alive player) then { player } else { objNull }; │ ^ unnecessary `!` operation - diff --git a/libs/sqf/tests/lints/s17_var_all_caps/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s17_var_all_caps.snap similarity index 85% rename from libs/sqf/tests/lints/s17_var_all_caps/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s17_var_all_caps.snap index 1751eeb5..a64987dd 100644 --- a/libs/sqf/tests/lints/s17_var_all_caps/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s17_var_all_caps.snap @@ -1,5 +1,9 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s17_var_all_caps)) +--- help[L-S17]: Variable should not be all caps: DO_NOT_EXIST - ┌─ source.sqf:7:19 + ┌─ s17_var_all_caps.sqf:7:19 │ 7 │ private _z = _y + DO_NOT_EXIST; │ ^^^^^^^^^^^^ All caps variable @@ -8,7 +12,7 @@ help[L-S17]: Variable should not be all caps: TPYO - ┌─ source.sqf:8:19 + ┌─ s17_var_all_caps.sqf:8:19 │ 8 │ private _w = _z + TPYO; │ ^^^^ All caps variable @@ -18,7 +22,7 @@ help[L-S17]: Variable should not be all caps: UNDEFINED - ┌─ source.sqf:3:27 + ┌─ s17_var_all_caps.sqf:3:27 │ 3 │ #define NESTED systemChat UNDEFINED │ ^^^^^^^^^ All caps variable @@ -27,4 +31,3 @@ │ ^^^^^^ Used in macro here │ = note: All caps variables are usually reserved for macros - diff --git a/libs/sqf/tests/lints/s18_in_vehicle_check/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s18_in_vehicle_check.snap similarity index 80% rename from libs/sqf/tests/lints/s18_in_vehicle_check/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s18_in_vehicle_check.snap index 0831c979..9255bd2b 100644 --- a/libs/sqf/tests/lints/s18_in_vehicle_check/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s18_in_vehicle_check.snap @@ -1,5 +1,9 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s18_in_vehicle_check)) +--- help[L-S18]: Using `vehicle` to check if a unit is in a vehicle is innefficient - ┌─ source.sqf:1:5 + ┌─ s18_in_vehicle_check.sqf:1:5 │ 1 │ if (vehicle player != player) then { │ ^^^^^^^^^^^^^^^^^^^^^^^^ Innefficient "in vehicle" check @@ -8,10 +12,9 @@ help[L-S18]: Using `vehicle` to check if a unit is in a vehicle is innefficient - ┌─ source.sqf:5:21 + ┌─ s18_in_vehicle_check.sqf:5:21 │ 5 │ if (alive _unit && {_unit == vehicle _unit}) then { │ ^^^^^^^^^^^^^^^^^^^^^^ Innefficient "not in vehicle" check │ = try: isNull objectParent _unit - diff --git a/libs/sqf/tests/lints/s20_bool_static_comparison/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s20_bool_static_comparison.snap similarity index 79% rename from libs/sqf/tests/lints/s20_bool_static_comparison/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s20_bool_static_comparison.snap index b502d84e..a96a704d 100644 --- a/libs/sqf/tests/lints/s20_bool_static_comparison/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s20_bool_static_comparison.snap @@ -1,5 +1,9 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s20_bool_static_comparison)) +--- help[L-S20]: Variable compared to static boolean - ┌─ source.sqf:3:5 + ┌─ s20_bool_static_comparison.sqf:3:5 │ 3 │ if (_true == true) then {}; │ ^^^^^^^^^^^^^ compared to static boolean @@ -8,7 +12,7 @@ help[L-S20]: Variable compared to static boolean - ┌─ source.sqf:4:5 + ┌─ s20_bool_static_comparison.sqf:4:5 │ 4 │ if (_true == false) then {}; │ ^^^^^^^^^^^^^^ compared to static boolean @@ -17,7 +21,7 @@ help[L-S20]: Variable compared to static boolean - ┌─ source.sqf:5:5 + ┌─ s20_bool_static_comparison.sqf:5:5 │ 5 │ if (_true != true) then {}; │ ^^^^^^^^^^^^^ compared to static boolean @@ -26,10 +30,9 @@ help[L-S20]: Variable compared to static boolean - ┌─ source.sqf:6:5 + ┌─ s20_bool_static_comparison.sqf:6:5 │ 6 │ if (_true != false) then {}; │ ^^^^^^^^^^^^^^ compared to static boolean │ = try: _true - diff --git a/libs/sqf/tests/lints/s21_invalid_comparisons/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s21_invalid_comparisons.snap similarity index 75% rename from libs/sqf/tests/lints/s21_invalid_comparisons/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s21_invalid_comparisons.snap index b3894a74..4168c26c 100644 --- a/libs/sqf/tests/lints/s21_invalid_comparisons/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s21_invalid_comparisons.snap @@ -1,20 +1,23 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s21_invalid_comparisons)) +--- help[L-S21]: Impossible comparison - ┌─ source.sqf:9:31 + ┌─ s21_invalid_comparisons.sqf:9:31 │ 9 │ if ({_y && _x < 10} || {_z && _x > 30 && {_x < 10}}) then {}; │ ^^^^^^^ ^^^^^^^ help[L-S21]: Impossible comparison - ┌─ source.sqf:11:5 + ┌─ s21_invalid_comparisons.sqf:11:5 │ 11 │ if (_x < 20 && {_x > 30 && {_y || _z}}) then { │ ^^^^^^^ ^^^^^^^ help[L-S21]: Overlapping comparison - ┌─ source.sqf:15:5 + ┌─ s21_invalid_comparisons.sqf:15:5 │ 15 │ if (_x < 20 && _x < 10) then { │ ^^^^^^^ ^^^^^^^ - diff --git a/libs/sqf/tests/lints/s22_this_call/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s22_this_call.snap similarity index 73% rename from libs/sqf/tests/lints/s22_this_call/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s22_this_call.snap index ce5ecc69..1b24070f 100644 --- a/libs/sqf/tests/lints/s22_this_call/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s22_this_call.snap @@ -1,9 +1,12 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s22_this_call)) +--- help[L-S22]: Unnecessary `_this` in `call` - ┌─ source.sqf:5:1 + ┌─ s22_this_call.sqf:5:1 │ 5 │ _this call _my_fnc; │ ^^^^^ │ = note: `call` inherits `_this` from the calling scope = help: Remove `_this` from the call - diff --git a/libs/sqf/tests/lints/s23_reassign_reserved_variable/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s23_reassign_reserved_variable.snap similarity index 82% rename from libs/sqf/tests/lints/s23_reassign_reserved_variable/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s23_reassign_reserved_variable.snap index d176340d..35dfe81b 100644 --- a/libs/sqf/tests/lints/s23_reassign_reserved_variable/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s23_reassign_reserved_variable.snap @@ -1,19 +1,23 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s23_reassign_reserved_variable)) +--- error[L-S23]: Reassigning reserved variable `_this` - ┌─ source.sqf:3:5 + ┌─ s23_reassign_reserved_variable.sqf:3:5 │ 3 │ _this = 123; │ ^^^^^^^^^^^ `_this` is reserved error[L-S23]: Reassigning reserved variable `_this` - ┌─ source.sqf:8:13 + ┌─ s23_reassign_reserved_variable.sqf:8:13 │ 8 │ params ["_this"]; │ ^^^^^^^ `_this` is reserved error[L-S23]: Reserved variable `_this` was never restored after being saved to `_savedThis` - ┌─ source.sqf:13:26 + ┌─ s23_reassign_reserved_variable.sqf:13:26 │ 13 │ private _savedThis = _this; │ ^^^^^ `_savedThis` is never restored to `_this` @@ -22,7 +26,7 @@ error[L-S23]: Holder variable `_savedThis` is overwritten before restoring `_this` - ┌─ source.sqf:22:5 + ┌─ s23_reassign_reserved_variable.sqf:22:5 │ 20 │ private _savedThis = _this; │ ----- `_savedThis` saves the state of _this @@ -30,4 +34,3 @@ │ ----------- `_this` is changed 22 │ private _savedThis = 1234; │ ^^^^^^^^^^^^^^^^^^^^^^^^^ `_savedThis` is overwritten before restoring `_this` - diff --git a/libs/sqf/tests/lints/s24_marker_spam/stdout.ansi b/libs/sqf/tests/snapshots/lints__simple_s24_marker_spam.snap similarity index 92% rename from libs/sqf/tests/lints/s24_marker_spam/stdout.ansi rename to libs/sqf/tests/snapshots/lints__simple_s24_marker_spam.snap index 81ca6115..a6bd272d 100644 --- a/libs/sqf/tests/lints/s24_marker_spam/stdout.ansi +++ b/libs/sqf/tests/snapshots/lints__simple_s24_marker_spam.snap @@ -1,5 +1,9 @@ +--- +source: libs/sqf/tests/lints.rs +expression: lint(stringify! (s24_marker_spam)) +--- help[L-S24]: Repeated calls to global marker updates - ┌─ source.sqf:4:13 + ┌─ s24_marker_spam.sqf:4:13 │ 4 │ _marker setMarkerShape "ICON"; │ ^^^^^^^^^^^^^^ Use setMarkerShapeLocal @@ -15,7 +19,7 @@ help[L-S24]: Repeated calls to global marker updates - ┌─ source.sqf:12:10 + ┌─ s24_marker_spam.sqf:12:10 │ 12 │ "m1" setMarkerShape "ICON"; │ ^^^^^^^^^^^^^^ Use setMarkerShapeLocal @@ -29,7 +33,7 @@ help[L-S24]: Repeated calls to global marker updates - ┌─ source.sqf:20:13 + ┌─ s24_marker_spam.sqf:20:13 │ 20 │ _marker setMarkerShape "ICON"; │ ^^^^^^^^^^^^^^ Use setMarkerShapeLocal @@ -41,7 +45,7 @@ help[L-S24]: Repeated calls to global marker updates - ┌─ source.sqf:23:13 + ┌─ s24_marker_spam.sqf:23:13 │ 23 │ _marker setMarkerColor "ColorRed"; │ ^^^^^^^^^^^^^^ Use setMarkerColorLocal @@ -50,4 +54,3 @@ │ = note: Global marker commands update the entire state of the marker = help: Using `setMarker*Local` on all except the last call reduces network updates - diff --git a/libs/sqf/tests/snapshots/optimizer__simple_consume_array.snap b/libs/sqf/tests/snapshots/optimizer__simple_consume_array.snap new file mode 100644 index 00000000..3ea53afb --- /dev/null +++ b/libs/sqf/tests/snapshots/optimizer__simple_consume_array.snap @@ -0,0 +1,383 @@ +--- +source: libs/sqf/tests/optimizer.rs +expression: optimize(stringify! (consume_array)) +--- +Statements { + content: [ + Expression( + UnaryCommand( + Named( + "params", + ), + ConsumeableArray( + [ + String( + "_a", + 8..12, + DoubleQuote, + ), + String( + "_b", + 14..18, + DoubleQuote, + ), + ], + 8..18, + ), + 0..6, + ), + 0..19, + ), + Expression( + UnaryCommand( + Named( + "params", + ), + UnaryCommand( + Plus, + ConsumeableArray( + [ + String( + "_a", + 30..34, + DoubleQuote, + ), + String( + "_b", + 36..40, + DoubleQuote, + ), + Array( + [ + String( + "_c", + 43..47, + DoubleQuote, + ), + Array( + [], + 50..51, + ), + ], + 43..51, + ), + ], + 30..52, + ), + 30..52, + ), + 22..28, + ), + 22..53, + ), + Expression( + BinaryCommand( + Named( + "getVariable", + ), + NularCommand( + NularCommand { + name: "missionNamespace", + }, + 56..72, + ), + ConsumeableArray( + [ + String( + "a", + 86..89, + DoubleQuote, + ), + Number( + FloatOrd( + -1.0, + ), + 91..92, + ), + ], + 86..93, + ), + 73..84, + ), + 56..94, + ), + Expression( + BinaryCommand( + Named( + "setVariable", + ), + Variable( + "z", + 97..98, + ), + UnaryCommand( + Plus, + ConsumeableArray( + [ + String( + "b", + 112..115, + DoubleQuote, + ), + Array( + [], + 118..119, + ), + Boolean( + true, + 121..125, + ), + ], + 112..125, + ), + 112..125, + ), + 99..110, + ), + 97..126, + ), + Expression( + BinaryCommand( + Named( + "vectorAdd", + ), + ConsumeableArray( + [ + Number( + FloatOrd( + 1.0, + ), + 130..131, + ), + Number( + FloatOrd( + 0.0, + ), + 132..133, + ), + ], + 130..133, + ), + Variable( + "p", + 145..146, + ), + 135..144, + ), + 129..146, + ), + Expression( + UnaryCommand( + Named( + "positionCameraToWorld", + ), + ConsumeableArray( + [ + Number( + FloatOrd( + 10000.0, + ), + 172..177, + ), + Number( + FloatOrd( + 0.0, + ), + 179..180, + ), + Number( + FloatOrd( + 10000.0, + ), + 182..187, + ), + ], + 172..187, + ), + 149..170, + ), + 149..188, + ), + Expression( + UnaryCommand( + Named( + "random", + ), + Array( + [ + Number( + FloatOrd( + 0.0, + ), + 200..201, + ), + Variable( + "_x", + 203..205, + ), + Number( + FloatOrd( + 1.0, + ), + 207..208, + ), + ], + 200..208, + ), + 192..198, + ), + 192..209, + ), + AssignLocal( + "_z", + BinaryCommand( + Named( + "then", + ), + UnaryCommand( + Named( + "if", + ), + BinaryCommand( + Greater, + NularCommand( + NularCommand { + name: "time", + }, + 229..233, + ), + Number( + FloatOrd( + 10.0, + ), + 236..238, + ), + 234..235, + ), + 225..227, + ), + ConsumeableArray( + [ + Code( + Statements { + content: [ + Expression( + Number( + FloatOrd( + 1.0, + ), + 247..248, + ), + 247..248, + ), + Expression( + Number( + FloatOrd( + 2.0, + ), + 249..250, + ), + 249..250, + ), + Expression( + Number( + FloatOrd( + 3.0, + ), + 251..252, + ), + 251..252, + ), + Expression( + Number( + FloatOrd( + 4.0, + ), + 253..254, + ), + 253..254, + ), + ], + source: "1;2;3;4;", + span: 247..255, + }, + ), + Code( + Statements { + content: [ + Expression( + Number( + FloatOrd( + -1.0, + ), + 265..266, + ), + 265..267, + ), + Expression( + Number( + FloatOrd( + -2.0, + ), + 268..269, + ), + 268..270, + ), + ], + source: "-1;-2;", + span: 265..271, + }, + ), + ], + 258..262, + ), + 240..244, + ), + 212..273, + ), + Expression( + UnaryCommand( + Named( + "param", + ), + ConsumeableArray( + [ + String( + "_d", + 283..287, + DoubleQuote, + ), + ], + 283..287, + ), + 276..281, + ), + 276..288, + ), + Expression( + BinaryCommand( + Named( + "param", + ), + Array( + [], + 292..293, + ), + ConsumeableArray( + [ + String( + "_e", + 301..305, + DoubleQuote, + ), + ], + 301..305, + ), + 294..299, + ), + 291..306, + ), + ], + source: "params [\"_a\", \"_b\"];\n\nparams [\"_a\", \"_b\", [\"_c\", []]];\n\nmissionNamespace getVariable [\"a\", -1];\n\nz setVariable [\"b\", [], true];\n\n[1,0] vectorAdd p;\n\npositionCameraToWorld [10000, 0, 10000];\n\n\nrandom [0, _x, 1];\n\nprivate _z = if (time > 10) then { 1;2;3;4; } else { -1;-2; };\n\nparam [\"_d\"];\n\n[] param [\"_e\"];\n", + span: 0..307, +} diff --git a/libs/sqf/tests/snapshots/optimizer__simple_scalar.snap b/libs/sqf/tests/snapshots/optimizer__simple_scalar.snap new file mode 100644 index 00000000..a1551d85 --- /dev/null +++ b/libs/sqf/tests/snapshots/optimizer__simple_scalar.snap @@ -0,0 +1,19 @@ +--- +source: libs/sqf/tests/optimizer.rs +expression: optimize(stringify! (scalar)) +--- +Statements { + content: [ + Expression( + Number( + FloatOrd( + -5.0, + ), + 0..1, + ), + 0..2, + ), + ], + source: "-5;\n", + span: 0..3, +} diff --git a/libs/sqf/tests/snapshots/optimizer__simple_static_math.snap b/libs/sqf/tests/snapshots/optimizer__simple_static_math.snap new file mode 100644 index 00000000..0110c807 --- /dev/null +++ b/libs/sqf/tests/snapshots/optimizer__simple_static_math.snap @@ -0,0 +1,49 @@ +--- +source: libs/sqf/tests/optimizer.rs +expression: optimize(stringify! (static_math)) +--- +Statements { + content: [ + Expression( + Number( + FloatOrd( + 23.0, + ), + 48..49, + ), + 0..51, + ), + Expression( + UnaryCommand( + Named( + "sqrt", + ), + Number( + FloatOrd( + -100.0, + ), + 59..60, + ), + 54..58, + ), + 54..63, + ), + Expression( + BinaryCommand( + Add, + Variable( + "z", + 67..68, + ), + Variable( + "z", + 71..72, + ), + 69..70, + ), + 67..72, + ), + ], + source: "1 + (2 * 2) + (36 % 31) + (36 / 6) + (sqrt 100) - 3;\n\nsqrt -100;\n\n\nz + z;\n", + span: 0..73, +} diff --git a/libs/sqf/tests/snapshots/optimizer__simple_string_case.snap b/libs/sqf/tests/snapshots/optimizer__simple_string_case.snap new file mode 100644 index 00000000..e81e8564 --- /dev/null +++ b/libs/sqf/tests/snapshots/optimizer__simple_string_case.snap @@ -0,0 +1,18 @@ +--- +source: libs/sqf/tests/optimizer.rs +expression: optimize(stringify! (string_case)) +--- +Statements { + content: [ + Expression( + String( + "aBCd", + 44..45, + DoubleQuote, + ), + 0..61, + ), + ], + source: "toLower \"A\" + toUpper \"b\" + toUpperAnsi \"C\" + toLowerAnsi \"d\";\n", + span: 0..62, +} diff --git a/libs/sqf/tests/snapshots/simple__simple_dev-2.snap b/libs/sqf/tests/snapshots/simple__simple_dev-2.snap new file mode 100644 index 00000000..e40d8f32 --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_dev-2.snap @@ -0,0 +1,16 @@ +--- +source: libs/sqf/tests/simple.rs +expression: ast +--- +[ + AssignLocal( + "_target", + NularCommand( + NularCommand { + name: "playerTargetLock", + }, + 18..34, + ), + 0..34, + ), +] diff --git a/libs/sqf/tests/snapshots/simple__simple_dev.snap b/libs/sqf/tests/snapshots/simple__simple_dev.snap new file mode 100644 index 00000000..31e2e194 --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_dev.snap @@ -0,0 +1,153 @@ +--- +source: libs/sqf/tests/simple.rs +expression: sqfc +--- +[ + 1, + 0, + 0, + 0, + 5, + 31, + 0, + 0, + 0, + 2, + 48, + 2, + 0, + 16, + 0, + 0, + 112, + 108, + 97, + 121, + 101, + 114, + 116, + 97, + 114, + 103, + 101, + 116, + 108, + 111, + 99, + 107, + 7, + 0, + 0, + 95, + 116, + 97, + 114, + 103, + 101, + 116, + 17, + 0, + 0, + 1, + 76, + 0, + 0, + 0, + 2, + 0, + 13, + 2, + 0, + 1, + 36, + 0, + 0, + 112, + 114, + 105, + 118, + 97, + 116, + 101, + 32, + 95, + 116, + 97, + 114, + 103, + 101, + 116, + 32, + 61, + 32, + 112, + 108, + 97, + 121, + 101, + 114, + 84, + 152, + 1, + 4, + 76, + 111, + 99, + 107, + 59, + 10, + 0, + 225, + 0, + 3, + 96, + 1, + 0, + 2, + 4, + 18, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 6, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 1, + 0, + 17, + 0, + 0, + 2, + 1, + 0, + 8, + 0, + 0, + 47, + 100, + 101, + 118, + 46, + 115, + 113, + 102, + 3, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +] diff --git a/libs/sqf/tests/snapshots/simple__simple_eventhandler-2.snap b/libs/sqf/tests/snapshots/simple__simple_eventhandler-2.snap new file mode 100644 index 00000000..e09ece6f --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_eventhandler-2.snap @@ -0,0 +1,282 @@ +--- +source: libs/sqf/tests/simple.rs +expression: ast +--- +[ + Expression( + BinaryCommand( + Named( + "count", + ), + Code( + Statements { + content: [ + Expression( + UnaryCommand( + Named( + "deleteVehicle", + ), + Variable( + "_x", + 17..19, + ), + 3..16, + ), + 3..19, + ), + ], + source: "deleteVehicle _x", + span: 3..19, + }, + ), + NularCommand( + NularCommand { + name: "allPlayers", + }, + 28..38, + ), + 22..27, + ), + 1..38, + ), + Expression( + BinaryCommand( + Named( + "call", + ), + Array( + [ + String( + "something", + 43..54, + DoubleQuote, + ), + Code( + Statements { + content: [ + Expression( + BinaryCommand( + Named( + "then", + ), + UnaryCommand( + Named( + "if", + ), + UnaryCommand( + Named( + "alive", + ), + NularCommand( + NularCommand { + name: "player", + }, + 72..78, + ), + 66..71, + ), + 62..64, + ), + Code( + Statements { + content: [ + Expression( + BinaryCommand( + Named( + "findIf", + ), + NularCommand( + NularCommand { + name: "allPlayers", + }, + 95..105, + ), + Code( + Statements { + content: [ + Expression( + UnaryCommand( + Named( + "alive", + ), + Variable( + "_x", + 121..123, + ), + 115..120, + ), + 115..123, + ), + ], + source: "alive _x", + span: 115..123, + }, + ), + 106..112, + ), + 95..125, + ), + Expression( + BinaryCommand( + Named( + "forEach", + ), + Code( + Statements { + content: [ + Expression( + UnaryCommand( + Named( + "deleteVehicle", + ), + Variable( + "_x", + 163..165, + ), + 149..162, + ), + 149..165, + ), + ], + source: "deleteVehicle _x;", + span: 149..166, + }, + ), + NularCommand( + NularCommand { + name: "allPlayers", + }, + 185..195, + ), + 177..184, + ), + 135..195, + ), + ], + source: "allPlayers findIf { alive _x };\n {\n deleteVehicle _x;\n } forEach allPlayers;", + span: 95..196, + }, + ), + 80..84, + ), + 62..202, + ), + ], + source: "if (alive player) then {\n allPlayers findIf { alive _x };\n {\n deleteVehicle _x;\n } forEach allPlayers;\n };", + span: 62..203, + }, + ), + ], + 43..205, + ), + Variable( + "CBA_fnc_addEventHandler", + 212..235, + ), + 207..211, + ), + 42..235, + ), + Expression( + BinaryCommand( + Named( + "call", + ), + Array( + [ + String( + "something", + 240..251, + DoubleQuote, + ), + Code( + Statements { + content: [ + Expression( + BinaryCommand( + Named( + "then", + ), + UnaryCommand( + Named( + "if", + ), + UnaryCommand( + Named( + "alive", + ), + NularCommand( + NularCommand { + name: "player", + }, + 269..275, + ), + 263..268, + ), + 259..261, + ), + Code( + Statements { + content: [ + Expression( + BinaryCommand( + Named( + "count", + ), + Code( + Statements { + content: [ + Expression( + UnaryCommand( + Named( + "deleteVehicle", + ), + Variable( + "_x", + 308..310, + ), + 294..307, + ), + 294..310, + ), + ], + source: "deleteVehicle _x", + span: 294..310, + }, + ), + NularCommand( + NularCommand { + name: "allPlayers", + }, + 319..329, + ), + 313..318, + ), + 292..329, + ), + ], + source: "{ deleteVehicle _x } count allPlayers;", + span: 292..330, + }, + ), + 277..281, + ), + 259..336, + ), + ], + source: "if (alive player) then {\n { deleteVehicle _x } count allPlayers;\n };", + span: 259..337, + }, + ), + ], + 240..339, + ), + Variable( + "CBA_fnc_addEventHandler", + 346..369, + ), + 341..345, + ), + 239..369, + ), +] diff --git a/libs/sqf/tests/snapshots/simple__simple_eventhandler.snap b/libs/sqf/tests/snapshots/simple__simple_eventhandler.snap new file mode 100644 index 00000000..e5d7935c --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_eventhandler.snap @@ -0,0 +1,728 @@ +--- +source: libs/sqf/tests/simple.rs +expression: sqfc +--- +[ + 1, + 0, + 0, + 0, + 5, + 125, + 0, + 0, + 0, + 2, + 0, + 30, + 12, + 0, + 2, + 0, + 0, + 95, + 120, + 13, + 0, + 0, + 100, + 101, + 108, + 101, + 116, + 101, + 118, + 101, + 104, + 105, + 99, + 108, + 101, + 10, + 0, + 0, + 97, + 108, + 108, + 112, + 108, + 97, + 121, + 101, + 114, + 115, + 5, + 0, + 0, + 99, + 111, + 117, + 110, + 116, + 6, + 0, + 0, + 112, + 133, + 2, + 5, + 116, + 3, + 0, + 49, + 105, + 118, + 101, + 2, + 0, + 0, + 105, + 102, + 6, + 0, + 0, + 102, + 105, + 110, + 100, + 105, + 102, + 7, + 0, + 0, + 102, + 111, + 114, + 101, + 97, + 99, + 104, + 4, + 0, + 0, + 116, + 104, + 101, + 110, + 23, + 0, + 0, + 99, + 98, + 97, + 95, + 102, + 110, + 99, + 95, + 97, + 100, + 100, + 101, + 118, + 101, + 110, + 116, + 104, + 97, + 110, + 100, + 108, + 101, + 114, + 4, + 0, + 0, + 99, + 97, + 108, + 108, + 17, + 0, + 0, + 1, + 81, + 3, + 0, + 0, + 2, + 15, + 11, + 0, + 0, + 3, + 0, + 0, + 0, + 16, + 0, + 0, + 128, + 3, + 0, + 0, + 0, + 0, + 7, + 17, + 116, + 0, + 2, + 2, + 0, + 0, + 0, + 2, + 156, + 1, + 7, + 2, + 0, + 1, + 0, + 0, + 115, + 0, + 0, + 0, + 8, + 39, + 133, + 0, + 121, + 101, + 4, + 7, + 100, + 4, + 124, + 2, + 8, + 0, + 7, + 0, + 5, + 0, + 0, + 149, + 0, + 0, + 0, + 17, + 39, + 133, + 0, + 163, + 101, + 4, + 9, + 100, + 4, + 126, + 2, + 0, + 9, + 108, + 8, + 6, + 95, + 0, + 0, + 0, + 101, + 0, + 0, + 128, + 8, + 109, + 3, + 4, + 116, + 1, + 7, + 0, + 7, + 0, + 2, + 0, + 1, + 1, + 0, + 3, + 106, + 104, + 2, + 7, + 7, + 0, + 7, + 0, + 0, + 1, + 2, + 0, + 4, + 185, + 116, + 1, + 3, + 10, + 0, + 2, + 0, + 3, + 177, + 164, + 1, + 0, + 7, + 8, + 0, + 1, + 9, + 0, + 0, + 115, + 111, + 109, + 101, + 116, + 104, + 105, + 110, + 103, + 0, + 62, + 0, + 0, + 0, + 141, + 0, + 0, + 128, + 6, + 122, + 3, + 4, + 72, + 116, + 0, + 3, + 6, + 0, + 4, + 0, + 2, + 66, + 167, + 1, + 5, + 0, + 2, + 100, + 4, + 7, + 0, + 6, + 0, + 6, + 0, + 1, + 3, + 0, + 3, + 80, + 184, + 2, + 2, + 9, + 0, + 0, + 38, + 1, + 42, + 162, + 3, + 52, + 1, + 174, + 22, + 0, + 2, + 126, + 2, + 0, + 17, + 112, + 20, + 6, + 36, + 1, + 0, + 0, + 38, + 0, + 0, + 128, + 4, + 108, + 6, + 2, + 1, + 6, + 0, + 4, + 63, + 176, + 4, + 1, + 2, + 0, + 3, + 57, + 164, + 1, + 5, + 3, + 0, + 0, + 3, + 1, + 0, + 0, + 78, + 39, + 253, + 1, + 13, + 125, + 2, + 16, + 125, + 15, + 7, + 167, + 1, + 5, + 0, + 2, + 102, + 4, + 0, + 16, + 124, + 15, + 1, + 7, + 0, + 3, + 21, + 184, + 2, + 0, + 32, + 9, + 0, + 1, + 115, + 1, + 0, + 10, + 123, + 32, + 100, + 101, + 108, + 101, + 116, + 101, + 86, + 101, + 104, + 105, + 99, + 108, + 101, + 32, + 95, + 120, + 32, + 125, + 32, + 99, + 111, + 117, + 110, + 116, + 32, + 97, + 108, + 108, + 80, + 108, + 97, + 121, + 101, + 114, + 115, + 59, + 10, + 10, + 10, + 91, + 34, + 39, + 196, + 3, + 0, + 2, + 34, + 44, + 32, + 123, + 10, + 32, + 32, + 32, + 32, + 105, + 102, + 32, + 40, + 97, + 108, + 105, + 118, + 101, + 32, + 112, + 128, + 5, + 3, + 41, + 32, + 116, + 104, + 101, + 110, + 208, + 3, + 96, + 4, + 40, + 8, + 1, + 7, + 32, + 102, + 105, + 110, + 100, + 73, + 102, + 32, + 123, + 32, + 160, + 6, + 125, + 12, + 59, + 144, + 8, + 124, + 4, + 184, + 9, + 100, + 1, + 108, + 0, + 46, + 68, + 2, + 40, + 156, + 0, + 7, + 125, + 32, + 102, + 111, + 114, + 69, + 97, + 99, + 104, + 32, + 40, + 100, + 1, + 180, + 3, + 0, + 16, + 125, + 59, + 10, + 125, + 93, + 32, + 99, + 97, + 108, + 108, + 32, + 67, + 66, + 65, + 95, + 102, + 110, + 99, + 95, + 97, + 100, + 100, + 69, + 118, + 101, + 110, + 116, + 72, + 97, + 110, + 100, + 108, + 101, + 114, + 32, + 24, + 16, + 3, + 32, + 6, + 136, + 4, + 100, + 23, + 32, + 3, + 21, + 2, + 0, + 96, + 81, + 125, + 57, + 16, + 112, + 0, + 2, + 1, + 0, + 0, + 4, + 28, + 97, + 1, + 2, + 101, + 76, + 22, + 164, + 1, + 5, + 3, + 0, + 0, + 1, + 4, + 0, + 1, + 5, + 112, + 92, + 100, + 2, + 2, + 0, + 2, + 0, + 7, + 212, + 96, + 1, + 3, + 12, + 0, + 10, + 0, + 3, + 207, + 165, + 1, + 11, + 177, + 4, + 8, + 42, + 144, + 0, + 0, + 1, + 90, + 1, + 0, + 0, + 0, + 19, + 0, + 10, + 0, + 3, + 85, + 1, + 0, + 0, + 0, + 19, + 0, + 11, + 0, + 17, + 0, + 0, + 2, + 1, + 0, + 17, + 0, + 0, + 47, + 101, + 118, + 101, + 110, + 116, + 104, + 97, + 110, + 100, + 108, + 101, + 114, + 46, + 115, + 113, + 102, + 3, + 10, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +] diff --git a/libs/sqf/tests/snapshots/simple__simple_foreach-2.snap b/libs/sqf/tests/snapshots/simple__simple_foreach-2.snap new file mode 100644 index 00000000..24bc3e96 --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_foreach-2.snap @@ -0,0 +1,140 @@ +--- +source: libs/sqf/tests/simple.rs +expression: ast +--- +[ + Expression( + BinaryCommand( + Named( + "forEach", + ), + Code( + Statements { + content: [ + Expression( + UnaryCommand( + Named( + "deleteVehicle", + ), + Variable( + "_x", + 21..23, + ), + 7..20, + ), + 7..23, + ), + ], + source: "deleteVehicle _x;", + span: 7..24, + }, + ), + NularCommand( + NularCommand { + name: "allUnits", + }, + 35..43, + ), + 27..34, + ), + 1..43, + ), + Expression( + BinaryCommand( + Named( + "forEach", + ), + Code( + Statements { + content: [ + Expression( + UnaryCommand( + Named( + "systemChat", + ), + UnaryCommand( + Named( + "format", + ), + Array( + [ + String( + "%1", + 72..76, + DoubleQuote, + ), + Variable( + "_x", + 78..80, + ), + ], + 72..80, + ), + 64..70, + ), + 53..63, + ), + 53..81, + ), + Expression( + BinaryCommand( + Named( + "forEach", + ), + Code( + Statements { + content: [ + Expression( + BinaryCommand( + Named( + "setDamage", + ), + Variable( + "_x", + 97..99, + ), + Number( + FloatOrd( + 1.0, + ), + 110..111, + ), + 100..109, + ), + 97..111, + ), + ], + source: "_x setDamage 1;", + span: 97..112, + }, + ), + UnaryCommand( + Named( + "crew", + ), + Variable( + "_x", + 132..134, + ), + 127..131, + ), + 119..126, + ), + 87..134, + ), + ], + source: "systemChat format [\"%1\", _x];\n {\n _x setDamage 1;\n } forEach crew _x;", + span: 53..135, + }, + ), + NularCommand( + NularCommand { + name: "allUnits", + }, + 146..154, + ), + 138..145, + ), + 47..154, + ), +] diff --git a/libs/sqf/tests/snapshots/simple__simple_foreach.snap b/libs/sqf/tests/snapshots/simple__simple_foreach.snap new file mode 100644 index 00000000..bf49f96b --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_foreach.snap @@ -0,0 +1,455 @@ +--- +source: libs/sqf/tests/simple.rs +expression: sqfc +--- +[ + 1, + 0, + 0, + 0, + 5, + 85, + 0, + 0, + 0, + 2, + 0, + 28, + 8, + 0, + 2, + 0, + 0, + 95, + 120, + 13, + 0, + 0, + 100, + 101, + 108, + 101, + 116, + 101, + 118, + 101, + 104, + 105, + 99, + 108, + 101, + 8, + 0, + 0, + 97, + 108, + 108, + 117, + 110, + 105, + 116, + 115, + 7, + 0, + 0, + 102, + 111, + 114, + 101, + 97, + 99, + 104, + 6, + 0, + 100, + 1, + 0, + 17, + 109, + 97, + 116, + 10, + 0, + 0, + 115, + 121, + 115, + 116, + 101, + 109, + 99, + 104, + 97, + 116, + 9, + 0, + 0, + 115, + 101, + 116, + 100, + 97, + 109, + 97, + 103, + 101, + 4, + 0, + 0, + 99, + 114, + 101, + 119, + 17, + 0, + 0, + 1, + 140, + 1, + 0, + 0, + 2, + 15, + 7, + 0, + 0, + 7, + 0, + 0, + 0, + 17, + 0, + 0, + 128, + 3, + 0, + 0, + 0, + 0, + 7, + 21, + 116, + 0, + 106, + 1, + 2, + 7, + 164, + 1, + 0, + 5, + 1, + 0, + 1, + 2, + 0, + 0, + 37, + 49, + 2, + 0, + 0, + 128, + 63, + 0, + 97, + 0, + 0, + 0, + 15, + 0, + 0, + 128, + 4, + 113, + 3, + 7, + 116, + 1, + 1, + 0, + 10, + 0, + 0, + 106, + 4, + 3, + 100, + 104, + 2, + 11, + 10, + 0, + 6, + 0, + 0, + 53, + 0, + 0, + 0, + 82, + 0, + 0, + 128, + 11, + 100, + 2, + 2, + 1, + 1, + 0, + 7, + 78, + 96, + 1, + 3, + 8, + 0, + 0, + 0, + 8, + 72, + 164, + 1, + 1, + 2, + 0, + 2, + 64, + 167, + 1, + 4, + 0, + 2, + 120, + 5, + 8, + 0, + 8, + 0, + 5, + 0, + 0, + 1, + 3, + 0, + 7, + 132, + 124, + 2, + 102, + 7, + 2, + 127, + 164, + 1, + 1, + 7, + 0, + 3, + 119, + 164, + 1, + 0, + 34, + 3, + 0, + 1, + 156, + 0, + 0, + 10, + 123, + 10, + 32, + 32, + 32, + 32, + 100, + 101, + 108, + 101, + 116, + 101, + 86, + 101, + 104, + 105, + 99, + 108, + 101, + 32, + 95, + 120, + 59, + 10, + 125, + 32, + 102, + 111, + 114, + 69, + 97, + 99, + 104, + 32, + 97, + 108, + 108, + 85, + 110, + 105, + 116, + 115, + 59, + 10, + 10, + 212, + 5, + 7, + 115, + 121, + 115, + 116, + 101, + 109, + 67, + 104, + 97, + 116, + 112, + 4, + 12, + 109, + 97, + 116, + 32, + 91, + 34, + 37, + 49, + 34, + 44, + 32, + 95, + 120, + 93, + 59, + 156, + 9, + 180, + 10, + 100, + 11, + 11, + 95, + 120, + 32, + 115, + 101, + 116, + 68, + 97, + 109, + 97, + 103, + 101, + 32, + 49, + 180, + 3, + 40, + 108, + 1, + 1, + 99, + 114, + 101, + 119, + 55, + 184, + 1, + 112, + 24, + 109, + 21, + 0, + 112, + 29, + 3, + 0, + 1, + 0, + 0, + 4, + 35, + 120, + 1, + 3, + 4, + 0, + 2, + 0, + 3, + 27, + 164, + 1, + 0, + 8, + 3, + 0, + 0, + 1, + 4, + 0, + 4, + 146, + 0, + 0, + 0, + 0, + 12, + 0, + 2, + 0, + 3, + 138, + 0, + 0, + 0, + 0, + 12, + 0, + 3, + 0, + 17, + 0, + 0, + 2, + 1, + 0, + 12, + 0, + 0, + 47, + 102, + 111, + 114, + 101, + 97, + 99, + 104, + 46, + 115, + 113, + 102, + 3, + 6, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +] diff --git a/libs/sqf/tests/snapshots/simple__simple_format_font-2.snap b/libs/sqf/tests/snapshots/simple__simple_format_font-2.snap new file mode 100644 index 00000000..7d6fe38b --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_format_font-2.snap @@ -0,0 +1,56 @@ +--- +source: libs/sqf/tests/simple.rs +expression: ast +--- +[ + AssignLocal( + "_redTextDisabled", + UnaryCommand( + Named( + "format", + ), + Array( + [ + String( + "%1", + 37..70, + DoubleQuote, + ), + String( + "thing", + 73..80, + DoubleQuote, + ), + ], + 36..80, + ), + 29..35, + ), + 2..81, + ), + AssignLocal( + "_greenTextEnabled", + UnaryCommand( + Named( + "format", + ), + Array( + [ + String( + "%1", + 119..152, + DoubleQuote, + ), + String( + "thing", + 155..162, + DoubleQuote, + ), + ], + 118..162, + ), + 111..117, + ), + 83..163, + ), +] diff --git a/libs/sqf/tests/snapshots/simple__simple_format_font.snap b/libs/sqf/tests/snapshots/simple__simple_format_font.snap new file mode 100644 index 00000000..2230520c --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_format_font.snap @@ -0,0 +1,316 @@ +--- +source: libs/sqf/tests/simple.rs +expression: sqfc +--- +[ + 1, + 0, + 0, + 0, + 5, + 50, + 0, + 0, + 0, + 2, + 67, + 3, + 0, + 6, + 0, + 0, + 102, + 111, + 114, + 109, + 97, + 116, + 16, + 0, + 0, + 95, + 114, + 101, + 100, + 116, + 101, + 120, + 116, + 100, + 105, + 115, + 97, + 98, + 108, + 101, + 100, + 17, + 0, + 0, + 95, + 103, + 114, + 101, + 101, + 110, + 116, + 101, + 120, + 116, + 101, + 110, + 97, + 98, + 108, + 101, + 100, + 17, + 0, + 0, + 1, + 81, + 1, + 0, + 0, + 2, + 0, + 14, + 5, + 0, + 1, + 31, + 0, + 0, + 60, + 102, + 111, + 110, + 116, + 32, + 99, + 111, + 108, + 111, + 114, + 61, + 39, + 35, + 70, + 70, + 48, + 48, + 48, + 48, + 39, + 62, + 37, + 49, + 60, + 47, + 96, + 3, + 10, + 62, + 1, + 5, + 0, + 0, + 116, + 104, + 105, + 110, + 103, + 1, + 31, + 0, + 45, + 174, + 0, + 48, + 48, + 116, + 5, + 42, + 172, + 0, + 0, + 24, + 165, + 0, + 0, + 10, + 10, + 112, + 114, + 105, + 118, + 97, + 116, + 101, + 32, + 95, + 114, + 101, + 100, + 84, + 101, + 120, + 116, + 68, + 105, + 115, + 97, + 98, + 108, + 101, + 100, + 32, + 61, + 32, + 102, + 111, + 114, + 109, + 97, + 116, + 91, + 40, + 34, + 60, + 108, + 11, + 56, + 208, + 1, + 2, + 34, + 41, + 44, + 32, + 34, + 151, + 14, + 34, + 93, + 59, + 40, + 64, + 1, + 2, + 103, + 114, + 101, + 101, + 110, + 106, + 10, + 69, + 110, + 61, + 68, + 1, + 47, + 104, + 2, + 44, + 71, + 1, + 0, + 3, + 0, + 161, + 0, + 12, + 120, + 0, + 4, + 1, + 0, + 0, + 1, + 1, + 0, + 8, + 104, + 1, + 4, + 0, + 0, + 0, + 2, + 0, + 2, + 29, + 104, + 1, + 3, + 6, + 0, + 0, + 0, + 6, + 2, + 164, + 1, + 101, + 4, + 2, + 45, + 144, + 0, + 0, + 1, + 111, + 0, + 0, + 0, + 0, + 7, + 0, + 0, + 0, + 6, + 83, + 0, + 0, + 0, + 0, + 7, + 0, + 2, + 0, + 17, + 0, + 0, + 2, + 1, + 0, + 16, + 0, + 0, + 47, + 102, + 111, + 114, + 109, + 97, + 116, + 95, + 102, + 111, + 110, + 116, + 46, + 115, + 113, + 102, + 3, + 4, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +] diff --git a/libs/sqf/tests/snapshots/simple__simple_get_visibility-2.snap b/libs/sqf/tests/snapshots/simple__simple_get_visibility-2.snap new file mode 100644 index 00000000..0e168ddf --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_get_visibility-2.snap @@ -0,0 +1,334 @@ +--- +source: libs/sqf/tests/simple.rs +expression: ast +--- +[ + Expression( + UnaryCommand( + Named( + "params", + ), + Array( + [ + String( + "_arg1", + 8..15, + DoubleQuote, + ), + String( + "_arg2", + 17..24, + DoubleQuote, + ), + ], + 8..24, + ), + 0..6, + ), + 0..25, + ), + Expression( + BinaryCommand( + Named( + "then", + ), + UnaryCommand( + Named( + "if", + ), + BinaryCommand( + Eq, + UnaryCommand( + Named( + "typeName", + ), + Variable( + "_arg1", + 40..45, + ), + 31..39, + ), + String( + "OBJECT", + 49..57, + DoubleQuote, + ), + 46..48, + ), + 27..29, + ), + Code( + Statements { + content: [ + AssignGlobal( + "_arg1", + Array( + [ + UnaryCommand( + Named( + "eyePos", + ), + Variable( + "_arg1", + 82..87, + ), + 75..81, + ), + Variable( + "_arg1", + 89..94, + ), + ], + 75..94, + ), + 66..95, + ), + ], + source: "_arg1 = [eyePos _arg1, _arg1]", + span: 66..95, + }, + ), + 59..63, + ), + 27..97, + ), + Expression( + BinaryCommand( + Named( + "then", + ), + UnaryCommand( + Named( + "if", + ), + BinaryCommand( + Eq, + UnaryCommand( + Named( + "typeName", + ), + Variable( + "_arg2", + 112..117, + ), + 103..111, + ), + String( + "OBJECT", + 121..129, + DoubleQuote, + ), + 118..120, + ), + 99..101, + ), + Code( + Statements { + content: [ + AssignGlobal( + "_arg2", + Array( + [ + UnaryCommand( + Named( + "eyePos", + ), + Variable( + "_arg2", + 154..159, + ), + 147..153, + ), + Variable( + "_arg2", + 161..166, + ), + ], + 147..166, + ), + 138..167, + ), + ], + source: "_arg2 = [eyePos _arg2, _arg2]", + span: 138..167, + }, + ), + 131..135, + ), + 99..169, + ), + Expression( + BinaryCommand( + Named( + "params", + ), + Variable( + "_arg1", + 171..176, + ), + Array( + [ + String( + "_position1", + 185..197, + DoubleQuote, + ), + Array( + [ + String( + "_ignore1", + 200..210, + DoubleQuote, + ), + NularCommand( + NularCommand { + name: "objNull", + }, + 212..219, + ), + ], + 200..219, + ), + ], + 185..220, + ), + 177..183, + ), + 171..221, + ), + Expression( + BinaryCommand( + Named( + "params", + ), + Variable( + "_arg2", + 223..228, + ), + Array( + [ + String( + "_position2", + 237..249, + DoubleQuote, + ), + Array( + [ + String( + "_ignore2", + 252..262, + DoubleQuote, + ), + NularCommand( + NularCommand { + name: "objNull", + }, + 264..271, + ), + ], + 252..271, + ), + ], + 237..272, + ), + 229..235, + ), + 223..273, + ), + AssignLocal( + "_multiplier", + BinaryCommand( + Div, + Number( + FloatOrd( + 1.0, + ), + 298..299, + ), + BinaryCommand( + Exp, + Number( + FloatOrd( + 2.0, + ), + 303..304, + ), + BinaryCommand( + Div, + BinaryCommand( + Named( + "distance", + ), + Variable( + "_position1", + 309..319, + ), + Variable( + "_position2", + 329..339, + ), + 320..328, + ), + Number( + FloatOrd( + 100.0, + ), + 343..346, + ), + 341..342, + ), + 305..306, + ), + 300..301, + ), + 276..348, + ), + Expression( + BinaryCommand( + Mul, + BinaryCommand( + Named( + "checkVisibility", + ), + Array( + [ + Variable( + "_ignore1", + 352..360, + ), + String( + "VIEW", + 362..368, + DoubleQuote, + ), + Variable( + "_ignore2", + 370..378, + ), + ], + 352..378, + ), + Array( + [ + Variable( + "_position1", + 397..407, + ), + Variable( + "_position2", + 409..419, + ), + ], + 397..419, + ), + 380..395, + ), + Variable( + "_multiplier", + 424..435, + ), + 422..423, + ), + 350..435, + ), +] diff --git a/libs/sqf/tests/snapshots/simple__simple_get_visibility.snap b/libs/sqf/tests/snapshots/simple__simple_get_visibility.snap new file mode 100644 index 00000000..d482fee2 --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_get_visibility.snap @@ -0,0 +1,955 @@ +--- +source: libs/sqf/tests/simple.rs +expression: sqfc +--- +[ + 1, + 0, + 0, + 0, + 5, + 167, + 0, + 0, + 0, + 2, + 0, + 38, + 18, + 0, + 6, + 0, + 0, + 112, + 97, + 114, + 97, + 109, + 115, + 5, + 0, + 0, + 95, + 97, + 114, + 103, + 49, + 8, + 0, + 0, + 116, + 121, + 112, + 101, + 110, + 97, + 109, + 101, + 2, + 0, + 0, + 61, + 61, + 2, + 0, + 0, + 105, + 102, + 6, + 0, + 0, + 101, + 121, + 101, + 112, + 111, + 115, + 4, + 0, + 0, + 116, + 104, + 101, + 110, + 208, + 5, + 11, + 50, + 10, + 0, + 0, + 95, + 112, + 111, + 115, + 105, + 116, + 105, + 111, + 110, + 49, + 42, + 48, + 0, + 0, + 26, + 50, + 8, + 0, + 0, + 100, + 105, + 115, + 116, + 97, + 110, + 99, + 101, + 1, + 0, + 0, + 47, + 1, + 0, + 0, + 94, + 11, + 0, + 0, + 95, + 109, + 117, + 108, + 116, + 105, + 112, + 108, + 105, + 101, + 114, + 8, + 0, + 0, + 95, + 105, + 103, + 110, + 111, + 114, + 101, + 105, + 14, + 95, + 168, + 1, + 0, + 5, + 50, + 15, + 0, + 0, + 99, + 104, + 101, + 99, + 107, + 118, + 105, + 115, + 105, + 98, + 105, + 108, + 105, + 116, + 121, + 1, + 0, + 0, + 42, + 17, + 0, + 0, + 1, + 88, + 4, + 0, + 0, + 2, + 11, + 16, + 0, + 1, + 5, + 0, + 0, + 95, + 97, + 114, + 103, + 49, + 1, + 5, + 0, + 128, + 1, + 0, + 9, + 50, + 1, + 6, + 0, + 0, + 79, + 66, + 74, + 69, + 67, + 84, + 0, + 66, + 0, + 0, + 0, + 29, + 0, + 0, + 128, + 6, + 0, + 0, + 0, + 0, + 7, + 82, + 116, + 0, + 3, + 2, + 0, + 1, + 0, + 2, + 75, + 164, + 1, + 1, + 5, + 0, + 7, + 89, + 167, + 1, + 1, + 0, + 8, + 207, + 2, + 2, + 0, + 5, + 117, + 6, + 0, + 126, + 4, + 0, + 138, + 43, + 253, + 0, + 154, + 108, + 5, + 3, + 3, + 0, + 7, + 0, + 2, + 147, + 164, + 1, + 1, + 5, + 0, + 7, + 161, + 167, + 1, + 7, + 0, + 8, + 207, + 2, + 2, + 0, + 5, + 117, + 6, + 0, + 124, + 4, + 0, + 20, + 1, + 10, + 0, + 0, + 95, + 112, + 111, + 115, + 105, + 116, + 105, + 111, + 110, + 49, + 1, + 8, + 0, + 0, + 95, + 105, + 103, + 110, + 111, + 114, + 101, + 49, + 5, + 7, + 0, + 0, + 111, + 98, + 106, + 110, + 117, + 108, + 108, + 1, + 42, + 145, + 0, + 50, + 41, + 144, + 0, + 0, + 20, + 50, + 2, + 0, + 0, + 128, + 63, + 2, + 0, + 0, + 0, + 64, + 2, + 0, + 0, + 200, + 66, + 1, + 4, + 0, + 0, + 86, + 73, + 69, + 87, + 1, + 180, + 1, + 0, + 112, + 97, + 114, + 97, + 109, + 115, + 32, + 91, + 34, + 95, + 107, + 31, + 34, + 44, + 32, + 128, + 1, + 15, + 50, + 34, + 93, + 59, + 10, + 105, + 102, + 32, + 40, + 116, + 121, + 112, + 101, + 78, + 97, + 109, + 101, + 32, + 132, + 35, + 2, + 32, + 61, + 61, + 32, + 34, + 164, + 34, + 6, + 34, + 41, + 32, + 116, + 104, + 101, + 110, + 32, + 123, + 228, + 3, + 5, + 32, + 91, + 101, + 121, + 101, + 80, + 111, + 115, + 189, + 1, + 44, + 187, + 0, + 93, + 32, + 125, + 49, + 29, + 1, + 50, + 55, + 31, + 1, + 50, + 32, + 61, + 43, + 29, + 1, + 50, + 189, + 8, + 50, + 156, + 8, + 168, + 16, + 40, + 192, + 2, + 39, + 62, + 4, + 34, + 44, + 124, + 23, + 192, + 34, + 11, + 34, + 44, + 32, + 111, + 98, + 106, + 78, + 117, + 108, + 108, + 93, + 93, + 59, + 10, + 110, + 6, + 50, + 32, + 48, + 205, + 0, + 50, + 42, + 204, + 0, + 112, + 1, + 41, + 204, + 0, + 0, + 16, + 10, + 112, + 114, + 105, + 118, + 97, + 116, + 101, + 32, + 95, + 109, + 117, + 108, + 116, + 105, + 112, + 108, + 105, + 101, + 114, + 32, + 61, + 32, + 49, + 32, + 47, + 32, + 40, + 50, + 32, + 94, + 32, + 40, + 40, + 40, + 40, + 6, + 7, + 32, + 100, + 105, + 115, + 116, + 97, + 110, + 99, + 101, + 32, + 39, + 76, + 0, + 11, + 50, + 41, + 32, + 47, + 32, + 49, + 48, + 48, + 41, + 41, + 59, + 10, + 40, + 91, + 255, + 52, + 44, + 32, + 34, + 107, + 46, + 34, + 44, + 32, + 196, + 2, + 0, + 2, + 50, + 93, + 32, + 99, + 104, + 101, + 99, + 107, + 86, + 105, + 115, + 105, + 98, + 105, + 108, + 105, + 116, + 121, + 32, + 91, + 39, + 14, + 1, + 49, + 44, + 41, + 60, + 1, + 1, + 93, + 41, + 32, + 42, + 42, + 47, + 2, + 10, + 0, + 14, + 108, + 69, + 1, + 0, + 0, + 0, + 59, + 124, + 0, + 4, + 1, + 0, + 0, + 1, + 1, + 0, + 8, + 104, + 1, + 2, + 0, + 0, + 0, + 2, + 0, + 127, + 60, + 0, + 0, + 1, + 126, + 1, + 7, + 40, + 116, + 0, + 98, + 80, + 2, + 31, + 164, + 1, + 4, + 2, + 0, + 1, + 2, + 0, + 3, + 46, + 176, + 1, + 1, + 3, + 0, + 2, + 27, + 164, + 1, + 3, + 4, + 0, + 1, + 3, + 0, + 3, + 152, + 9, + 4, + 2, + 0, + 6, + 0, + 0, + 7, + 112, + 124, + 2, + 102, + 79, + 2, + 103, + 164, + 1, + 161, + 7, + 118, + 176, + 1, + 1, + 3, + 0, + 2, + 99, + 164, + 1, + 4, + 4, + 0, + 1, + 4, + 0, + 3, + 131, + 176, + 1, + 97, + 7, + 171, + 104, + 1, + 9, + 4, + 0, + 1, + 0, + 1, + 5, + 0, + 1, + 6, + 0, + 1, + 7, + 41, + 100, + 2, + 40, + 142, + 2, + 3, + 177, + 184, + 4, + 113, + 105, + 223, + 104, + 1, + 6, + 5, + 0, + 7, + 0, + 1, + 8, + 0, + 1, + 9, + 55, + 197, + 0, + 229, + 184, + 4, + 8, + 0, + 0, + 0, + 1, + 10, + 0, + 1, + 11, + 0, + 7, + 53, + 104, + 28, + 122, + 11, + 7, + 73, + 164, + 1, + 1, + 9, + 0, + 3, + 64, + 164, + 1, + 4, + 10, + 0, + 1, + 12, + 0, + 3, + 85, + 176, + 1, + 1, + 11, + 0, + 3, + 49, + 164, + 1, + 1, + 12, + 0, + 3, + 44, + 164, + 1, + 1, + 11, + 0, + 6, + 20, + 164, + 1, + 2, + 13, + 0, + 0, + 7, + 96, + 104, + 1, + 6, + 8, + 0, + 14, + 0, + 1, + 13, + 0, + 7, + 114, + 179, + 1, + 15, + 0, + 8, + 216, + 2, + 1, + 3, + 0, + 7, + 141, + 172, + 2, + 1, + 8, + 0, + 7, + 153, + 167, + 1, + 9, + 0, + 8, + 204, + 2, + 1, + 2, + 0, + 3, + 124, + 172, + 2, + 0, + 4, + 16, + 0, + 7, + 168, + 1, + 0, + 0, + 0, + 8, + 0, + 13, + 0, + 3, + 166, + 1, + 0, + 0, + 0, + 8, + 0, + 17, + 0, + 17, + 0, + 0, + 2, + 1, + 0, + 19, + 0, + 0, + 47, + 103, + 101, + 116, + 95, + 118, + 105, + 115, + 105, + 98, + 105, + 108, + 105, + 116, + 121, + 46, + 115, + 113, + 102, + 3, + 15, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +] diff --git a/libs/sqf/tests/snapshots/simple__simple_hash_select-2.snap b/libs/sqf/tests/snapshots/simple__simple_hash_select-2.snap new file mode 100644 index 00000000..a5e96973 --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_hash_select-2.snap @@ -0,0 +1,23 @@ +--- +source: libs/sqf/tests/simple.rs +expression: ast +--- +[ + Expression( + BinaryCommand( + Select, + Variable( + "_explosive", + 0..10, + ), + Number( + FloatOrd( + 0.0, + ), + 13..14, + ), + 11..12, + ), + 0..14, + ), +] diff --git a/libs/sqf/tests/snapshots/simple__simple_hash_select.snap b/libs/sqf/tests/snapshots/simple__simple_hash_select.snap new file mode 100644 index 00000000..9dba1cfe --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_hash_select.snap @@ -0,0 +1,137 @@ +--- +source: libs/sqf/tests/simple.rs +expression: sqfc +--- +[ + 1, + 0, + 0, + 0, + 5, + 19, + 0, + 0, + 0, + 2, + 36, + 2, + 0, + 10, + 0, + 0, + 95, + 101, + 120, + 112, + 108, + 111, + 115, + 105, + 118, + 101, + 1, + 0, + 0, + 35, + 17, + 0, + 0, + 1, + 63, + 0, + 0, + 0, + 2, + 0, + 11, + 3, + 0, + 2, + 0, + 0, + 0, + 0, + 1, + 15, + 0, + 0, + 95, + 101, + 120, + 112, + 108, + 111, + 115, + 105, + 118, + 101, + 32, + 35, + 32, + 48, + 10, + 0, + 1, + 0, + 161, + 0, + 4, + 121, + 0, + 7, + 112, + 0, + 15, + 0, + 1, + 0, + 0, + 0, + 1, + 0, + 0, + 3, + 11, + 0, + 0, + 0, + 0, + 1, + 0, + 1, + 0, + 17, + 0, + 0, + 2, + 1, + 0, + 16, + 0, + 0, + 47, + 104, + 97, + 115, + 104, + 95, + 115, + 101, + 108, + 101, + 99, + 116, + 46, + 115, + 113, + 102, + 3, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +] diff --git a/libs/sqf/tests/snapshots/simple__simple_hello-2.snap b/libs/sqf/tests/snapshots/simple__simple_hello-2.snap new file mode 100644 index 00000000..17309f3b --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_hello-2.snap @@ -0,0 +1,44 @@ +--- +source: libs/sqf/tests/simple.rs +expression: ast +--- +[ + AssignLocal( + "_name", + String( + "HEMTT", + 16..23, + DoubleQuote, + ), + 0..23, + ), + Expression( + UnaryCommand( + Named( + "systemChat", + ), + UnaryCommand( + Named( + "format", + ), + Array( + [ + String( + "Hello, %1!", + 44..56, + DoubleQuote, + ), + Variable( + "_name", + 58..63, + ), + ], + 44..63, + ), + 36..42, + ), + 25..35, + ), + 25..64, + ), +] diff --git a/libs/sqf/tests/snapshots/simple__simple_hello.snap b/libs/sqf/tests/snapshots/simple__simple_hello.snap new file mode 100644 index 00000000..93d6ec0a --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_hello.snap @@ -0,0 +1,229 @@ +--- +source: libs/sqf/tests/simple.rs +expression: sqfc +--- +[ + 1, + 0, + 0, + 0, + 5, + 32, + 0, + 0, + 0, + 2, + 49, + 3, + 0, + 5, + 0, + 0, + 95, + 110, + 97, + 109, + 101, + 6, + 0, + 0, + 102, + 111, + 114, + 109, + 97, + 116, + 10, + 0, + 0, + 115, + 121, + 115, + 116, + 101, + 109, + 99, + 104, + 97, + 116, + 17, + 0, + 0, + 1, + 166, + 0, + 0, + 0, + 2, + 0, + 28, + 4, + 0, + 1, + 5, + 0, + 0, + 72, + 69, + 77, + 84, + 84, + 1, + 10, + 0, + 0, + 72, + 101, + 108, + 108, + 111, + 44, + 32, + 37, + 49, + 33, + 1, + 66, + 0, + 0, + 112, + 114, + 105, + 118, + 97, + 116, + 101, + 32, + 95, + 110, + 97, + 109, + 101, + 32, + 61, + 32, + 34, + 156, + 4, + 0, + 5, + 34, + 59, + 10, + 115, + 121, + 115, + 116, + 101, + 109, + 67, + 104, + 97, + 116, + 32, + 102, + 111, + 114, + 109, + 97, + 116, + 32, + 91, + 34, + 40, + 234, + 0, + 34, + 44, + 164, + 6, + 3, + 93, + 59, + 10, + 0, + 2, + 0, + 161, + 0, + 9, + 120, + 0, + 1, + 1, + 0, + 0, + 6, + 126, + 0, + 0, + 1, + 116, + 0, + 2, + 1, + 1, + 0, + 7, + 58, + 96, + 1, + 110, + 4, + 8, + 44, + 164, + 1, + 0, + 4, + 2, + 0, + 2, + 36, + 0, + 0, + 0, + 0, + 2, + 0, + 1, + 0, + 2, + 25, + 0, + 0, + 0, + 0, + 2, + 0, + 2, + 0, + 17, + 0, + 0, + 2, + 1, + 0, + 10, + 0, + 0, + 47, + 104, + 101, + 108, + 108, + 111, + 46, + 115, + 113, + 102, + 3, + 3, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +] diff --git a/libs/sqf/tests/snapshots/simple__simple_include-2.snap b/libs/sqf/tests/snapshots/simple__simple_include-2.snap new file mode 100644 index 00000000..726ce909 --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_include-2.snap @@ -0,0 +1,187 @@ +--- +source: libs/sqf/tests/simple.rs +expression: ast +--- +[ + AssignLocal( + "_things", + Array( + [ + Number( + FloatOrd( + 1.0, + ), + 19..20, + ), + Number( + FloatOrd( + 2.0, + ), + 21..22, + ), + Number( + FloatOrd( + 3.0, + ), + 23..24, + ), + Number( + FloatOrd( + 4.0, + ), + 25..26, + ), + ], + 19..26, + ), + 0..27, + ), + AssignLocal( + "_things", + Array( + [ + Number( + FloatOrd( + 1.0, + ), + 49..50, + ), + Number( + FloatOrd( + 2.0, + ), + 51..52, + ), + Number( + FloatOrd( + 3.0, + ), + 53..54, + ), + Number( + FloatOrd( + 4.0, + ), + 55..56, + ), + ], + 49..56, + ), + 30..57, + ), + AssignLocal( + "_things", + Array( + [ + Number( + FloatOrd( + 1.0, + ), + 79..80, + ), + Number( + FloatOrd( + 2.0, + ), + 81..82, + ), + Number( + FloatOrd( + 3.0, + ), + 83..84, + ), + Number( + FloatOrd( + 4.0, + ), + 85..86, + ), + ], + 79..86, + ), + 60..87, + ), + Expression( + BinaryCommand( + Named( + "forEach", + ), + Code( + Statements { + content: [ + AssignLocal( + "thinghi", + BinaryCommand( + Add, + Variable( + "_x", + 112..114, + ), + String( + "test", + 117..123, + DoubleQuote, + ), + 115..116, + ), + 94..123, + ), + ], + source: "private thinghi = _x + \"test\";", + span: 94..124, + }, + ), + Array( + [ + Number( + FloatOrd( + 0.0, + ), + 136..137, + ), + Number( + FloatOrd( + 1.0, + ), + 138..139, + ), + Number( + FloatOrd( + 2.0, + ), + 140..141, + ), + Number( + FloatOrd( + 3.0, + ), + 142..143, + ), + ], + 136..143, + ), + 127..134, + ), + 91..144, + ), + Expression( + UnaryCommand( + Named( + "systemChat", + ), + UnaryCommand( + Named( + "str", + ), + Variable( + "_things", + 161..168, + ), + 157..160, + ), + 146..156, + ), + 146..168, + ), +] diff --git a/libs/sqf/tests/snapshots/simple__simple_include.snap b/libs/sqf/tests/snapshots/simple__simple_include.snap new file mode 100644 index 00000000..3cd69217 --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_include.snap @@ -0,0 +1,419 @@ +--- +source: libs/sqf/tests/simple.rs +expression: sqfc +--- +[ + 1, + 0, + 0, + 0, + 5, + 60, + 0, + 0, + 0, + 2, + 0, + 6, + 7, + 0, + 7, + 0, + 0, + 95, + 116, + 104, + 105, + 110, + 103, + 115, + 2, + 0, + 0, + 95, + 120, + 1, + 0, + 0, + 43, + 7, + 0, + 0, + 132, + 2, + 0, + 13, + 104, + 105, + 7, + 0, + 0, + 102, + 111, + 114, + 101, + 97, + 99, + 104, + 3, + 0, + 0, + 115, + 116, + 114, + 10, + 0, + 0, + 115, + 121, + 115, + 116, + 101, + 109, + 99, + 104, + 97, + 116, + 17, + 0, + 0, + 1, + 179, + 1, + 0, + 0, + 2, + 13, + 9, + 0, + 2, + 0, + 0, + 128, + 63, + 2, + 0, + 0, + 0, + 64, + 2, + 0, + 0, + 64, + 112, + 0, + 0, + 22, + 128, + 64, + 1, + 4, + 0, + 0, + 116, + 101, + 115, + 116, + 0, + 94, + 0, + 0, + 0, + 30, + 0, + 0, + 128, + 5, + 0, + 0, + 0, + 0, + 7, + 112, + 0, + 0, + 0, + 1, + 6, + 0, + 1, + 0, + 1, + 4, + 0, + 3, + 115, + 0, + 147, + 1, + 2, + 0, + 6, + 112, + 4, + 2, + 1, + 6, + 0, + 3, + 0, + 116, + 8, + 0, + 18, + 0, + 1, + 170, + 0, + 0, + 112, + 114, + 105, + 118, + 97, + 116, + 101, + 32, + 95, + 116, + 104, + 105, + 110, + 103, + 115, + 32, + 61, + 32, + 91, + 49, + 44, + 50, + 44, + 51, + 44, + 52, + 93, + 59, + 10, + 10, + 112, + 32, + 26, + 116, + 0, + 1, + 10, + 123, + 10, + 9, + 244, + 11, + 144, + 11, + 8, + 104, + 105, + 32, + 61, + 32, + 95, + 120, + 32, + 43, + 32, + 34, + 100, + 22, + 13, + 34, + 59, + 10, + 125, + 32, + 102, + 111, + 114, + 69, + 97, + 99, + 104, + 32, + 91, + 48, + 44, + 152, + 14, + 14, + 93, + 59, + 10, + 115, + 121, + 115, + 116, + 101, + 109, + 67, + 104, + 97, + 116, + 32, + 115, + 116, + 114, + 224, + 19, + 1, + 59, + 10, + 0, + 7, + 100, + 27, + 1, + 0, + 0, + 0, + 33, + 124, + 0, + 10, + 1, + 0, + 0, + 1, + 1, + 0, + 1, + 2, + 0, + 1, + 3, + 0, + 8, + 96, + 2, + 3, + 0, + 0, + 0, + 4, + 0, + 6, + 133, + 1, + 1, + 116, + 0, + 53, + 129, + 0, + 30, + 109, + 3, + 3, + 112, + 0, + 53, + 129, + 0, + 60, + 108, + 3, + 146, + 40, + 1, + 5, + 168, + 40, + 192, + 13, + 40, + 150, + 1, + 3, + 127, + 116, + 43, + 4, + 7, + 0, + 4, + 0, + 0, + 7, + 161, + 104, + 1, + 104, + 3, + 0, + 2, + 2, + 157, + 0, + 0, + 0, + 1, + 8, + 0, + 5, + 0, + 2, + 146, + 0, + 0, + 0, + 1, + 8, + 0, + 6, + 0, + 17, + 0, + 0, + 2, + 2, + 0, + 14, + 0, + 0, + 47, + 115, + 111, + 109, + 101, + 116, + 104, + 105, + 110, + 103, + 46, + 104, + 112, + 112, + 12, + 0, + 0, + 47, + 105, + 110, + 99, + 108, + 117, + 100, + 101, + 46, + 115, + 113, + 102, + 3, + 8, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +] diff --git a/libs/sqf/tests/snapshots/simple__simple_oneline-2.snap b/libs/sqf/tests/snapshots/simple__simple_oneline-2.snap new file mode 100644 index 00000000..4b9f6568 --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_oneline-2.snap @@ -0,0 +1,23 @@ +--- +source: libs/sqf/tests/simple.rs +expression: ast +--- +[ + AssignLocal( + "value", + BinaryCommand( + Add, + Variable( + "a", + 16..17, + ), + String( + "1", + 20..23, + DoubleQuote, + ), + 18..19, + ), + 0..23, + ), +] diff --git a/libs/sqf/tests/snapshots/simple__simple_oneline.snap b/libs/sqf/tests/snapshots/simple__simple_oneline.snap new file mode 100644 index 00000000..92fd82e5 --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_oneline.snap @@ -0,0 +1,152 @@ +--- +source: libs/sqf/tests/simple.rs +expression: sqfc +--- +[ + 1, + 0, + 0, + 0, + 5, + 18, + 0, + 0, + 0, + 2, + 35, + 3, + 0, + 1, + 0, + 0, + 97, + 1, + 0, + 0, + 43, + 5, + 0, + 0, + 118, + 97, + 108, + 117, + 101, + 17, + 0, + 0, + 1, + 83, + 0, + 0, + 0, + 2, + 0, + 22, + 3, + 0, + 1, + 1, + 0, + 0, + 49, + 1, + 25, + 0, + 0, + 112, + 114, + 105, + 118, + 97, + 116, + 101, + 32, + 118, + 97, + 108, + 117, + 101, + 32, + 61, + 32, + 97, + 32, + 43, + 32, + 34, + 49, + 34, + 59, + 10, + 0, + 1, + 0, + 0, + 133, + 0, + 5, + 118, + 0, + 7, + 16, + 119, + 0, + 1, + 0, + 0, + 120, + 2, + 0, + 2, + 3, + 18, + 0, + 0, + 0, + 0, + 1, + 0, + 1, + 0, + 6, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 2, + 0, + 17, + 0, + 0, + 2, + 1, + 0, + 12, + 0, + 0, + 47, + 111, + 110, + 101, + 108, + 105, + 110, + 101, + 46, + 115, + 113, + 102, + 3, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +] diff --git a/libs/sqf/tests/snapshots/simple__simple_semicolons-2.snap b/libs/sqf/tests/snapshots/simple__simple_semicolons-2.snap new file mode 100644 index 00000000..ede82283 --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_semicolons-2.snap @@ -0,0 +1,101 @@ +--- +source: libs/sqf/tests/simple.rs +expression: ast +--- +[ + AssignLocal( + "_test", + Boolean( + true, + 20..24, + ), + 4..24, + ), + Expression( + UnaryCommand( + Named( + "systemChat", + ), + String( + "this is a test", + 41..57, + DoubleQuote, + ), + 30..40, + ), + 30..57, + ), + AssignLocal( + "_variable", + String( + "this is a test", + 83..99, + DoubleQuote, + ), + 63..99, + ), + Expression( + BinaryCommand( + Named( + "then", + ), + UnaryCommand( + Named( + "if", + ), + BinaryCommand( + Eq, + Variable( + "_variable", + 105..114, + ), + String( + "this is a test", + 118..134, + DoubleQuote, + ), + 115..117, + ), + 101..103, + ), + Code( + Statements { + content: [ + Expression( + UnaryCommand( + Named( + "systemChat", + ), + String( + "this is a test", + 164..180, + DoubleQuote, + ), + 153..163, + ), + 153..180, + ), + ], + source: "systemChat \"this is a test\";", + span: 153..181, + }, + ), + 136..140, + ), + 101..189, + ), + Expression( + UnaryCommand( + Named( + "systemChat", + ), + String( + "this is a test", + 202..218, + DoubleQuote, + ), + 191..201, + ), + 191..218, + ), +] diff --git a/libs/sqf/tests/snapshots/simple__simple_semicolons.snap b/libs/sqf/tests/snapshots/simple__simple_semicolons.snap new file mode 100644 index 00000000..46d0ba6e --- /dev/null +++ b/libs/sqf/tests/snapshots/simple__simple_semicolons.snap @@ -0,0 +1,359 @@ +--- +source: libs/sqf/tests/simple.rs +expression: sqfc +--- +[ + 1, + 0, + 0, + 0, + 5, + 52, + 0, + 0, + 0, + 2, + 69, + 6, + 0, + 5, + 0, + 0, + 95, + 116, + 101, + 115, + 116, + 10, + 0, + 0, + 115, + 121, + 115, + 116, + 101, + 109, + 99, + 104, + 97, + 116, + 9, + 0, + 0, + 95, + 118, + 97, + 114, + 105, + 97, + 98, + 108, + 101, + 2, + 0, + 0, + 61, + 61, + 2, + 0, + 0, + 105, + 102, + 4, + 0, + 0, + 116, + 104, + 101, + 110, + 17, + 0, + 0, + 1, + 133, + 1, + 0, + 0, + 2, + 0, + 22, + 5, + 0, + 3, + 1, + 1, + 14, + 0, + 0, + 116, + 104, + 105, + 115, + 32, + 105, + 115, + 32, + 97, + 32, + 116, + 101, + 115, + 116, + 0, + 153, + 0, + 0, + 0, + 28, + 0, + 0, + 128, + 3, + 0, + 0, + 0, + 0, + 1, + 1, + 0, + 2, + 96, + 2, + 0, + 4, + 0, + 9, + 0, + 1, + 0, + 1, + 220, + 0, + 0, + 59, + 32, + 59, + 10, + 112, + 114, + 105, + 118, + 97, + 116, + 101, + 32, + 95, + 124, + 5, + 6, + 32, + 61, + 32, + 116, + 114, + 117, + 101, + 59, + 10, + 100, + 3, + 9, + 115, + 121, + 115, + 116, + 101, + 109, + 67, + 104, + 97, + 116, + 32, + 34, + 44, + 89, + 1, + 34, + 160, + 4, + 39, + 232, + 0, + 7, + 118, + 97, + 114, + 105, + 97, + 98, + 108, + 101, + 32, + 61, + 49, + 164, + 0, + 2, + 105, + 102, + 32, + 40, + 95, + 40, + 132, + 0, + 48, + 136, + 0, + 11, + 41, + 32, + 116, + 104, + 101, + 110, + 32, + 123, + 10, + 32, + 32, + 32, + 32, + 59, + 148, + 0, + 59, + 232, + 1, + 187, + 4, + 125, + 59, + 10, + 59, + 149, + 0, + 0, + 136, + 30, + 1, + 0, + 0, + 0, + 19, + 136, + 31, + 1, + 0, + 0, + 6, + 4, + 97, + 1, + 2, + 112, + 0, + 97, + 33, + 30, + 99, + 1, + 4, + 0, + 1, + 154, + 34, + 6, + 63, + 116, + 1, + 4, + 6, + 0, + 2, + 0, + 0, + 7, + 105, + 104, + 1, + 6, + 7, + 0, + 2, + 0, + 1, + 1, + 0, + 3, + 115, + 176, + 1, + 1, + 3, + 0, + 2, + 101, + 164, + 1, + 4, + 4, + 0, + 1, + 2, + 0, + 3, + 136, + 176, + 1, + 13, + 5, + 0, + 0, + 1, + 1, + 0, + 2, + 191, + 0, + 0, + 0, + 0, + 12, + 0, + 1, + 0, + 17, + 0, + 0, + 2, + 1, + 0, + 15, + 0, + 0, + 47, + 115, + 101, + 109, + 105, + 99, + 111, + 108, + 111, + 110, + 115, + 46, + 115, + 113, + 102, + 3, + 4, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +]