From 94ff0d5764834b60100c0259a7feca5c78ca6b7e Mon Sep 17 00:00:00 2001 From: Calvo Date: Thu, 8 May 2025 13:25:56 -0600 Subject: [PATCH] Refactor lint spacing tests Use robust check for spacing tests --- src/lint/mod.rs | 48 ------ src/lint/rules/tests/common.rs | 9 +- .../rules/tests/indentation/closing_brace.rs | 2 +- .../rules/tests/indentation/code_block.rs | 2 +- .../rules/tests/indentation/empty_loop.rs | 2 +- src/lint/rules/tests/indentation/mod.rs | 15 +- src/lint/rules/tests/indentation/no_tabs.rs | 2 +- .../rules/tests/indentation/paren_expr.rs | 2 +- .../rules/tests/indentation/switch_case.rs | 2 +- src/lint/rules/tests/spacing/mod.rs | 155 +----------------- src/lint/rules/tests/spacing/nsp_funpar.rs | 36 ++++ src/lint/rules/tests/spacing/nsp_inparen.rs | 40 +++++ src/lint/rules/tests/spacing/nsp_trailing.rs | 28 ++++ src/lint/rules/tests/spacing/nsp_unary.rs | 46 ++++++ src/lint/rules/tests/spacing/sp_braces.rs | 94 +++++++++++ src/lint/rules/tests/spacing/sp_punct.rs | 46 ++++++ 16 files changed, 315 insertions(+), 214 deletions(-) create mode 100644 src/lint/rules/tests/spacing/nsp_funpar.rs create mode 100644 src/lint/rules/tests/spacing/nsp_inparen.rs create mode 100644 src/lint/rules/tests/spacing/nsp_trailing.rs create mode 100644 src/lint/rules/tests/spacing/nsp_unary.rs create mode 100644 src/lint/rules/tests/spacing/sp_braces.rs create mode 100644 src/lint/rules/tests/spacing/sp_punct.rs diff --git a/src/lint/mod.rs b/src/lint/mod.rs index c72c168f..6036cf22 100644 --- a/src/lint/mod.rs +++ b/src/lint/mod.rs @@ -189,41 +189,6 @@ pub mod tests { use std::str::FromStr; use crate::{analysis::{parsing::{parser::FileInfo, structure::{self, TopAst}}, FileSpec}, vfs::TextFile}; - pub static SOURCE: &str = " - dml 1.4; - - bank sb_cr { - group monitor { - - register MKTME_KEYID_MASK { - method get() -> (uint64) { - local uint64 physical_address_mask = mse.srv10nm_mse_mktme.get_key_addr_mask(); - this.Mask.set(physical_address_mask); - this.function_with_args('some_string', - integer, - floater); - return this.val; - } - } - - register TDX_KEYID_MASK { - method get() -> (uint64) { - local uint64 tdx_keyid_mask = mse.srv10nm_mse_tdx.get_key_addr_mask(); - local uint64 some_uint = (is_this_real) ? then_you_might_like_this_value : or_this_one; - this.Mask.set(tdx_keyid_mask); - return this.val; - } - } - } - } - - /* - This is ONEEEE VEEEEEERY LLOOOOOOONG COOOMMMEENTT ON A SINGLEEEE LINEEEEEEEEEEEEEE - and ANOTHEEEER VEEEEEERY LLOOOOOOONG COOOMMMEENTT ON A SINGLEEEE LINEEEEEEEEEEEEEE - */ - - "; - pub fn create_ast_from_snippet(source: &str) -> TopAst { use logos::Logos; use crate::analysis::parsing::lexer::TokenKind; @@ -251,17 +216,4 @@ pub mod tests { let example_cfg = parse_lint_cfg(example_path.into()).unwrap(); assert_eq!(example_cfg, LintCfg::default()); } - - #[test] - #[ignore] - fn test_main() { - use crate::lint::{begin_style_check, LintCfg}; - use crate::lint::rules:: instantiate_rules; - let ast = create_ast_from_snippet(SOURCE); - let cfg = LintCfg::default(); - let rules = instantiate_rules(&cfg); - let _lint_errors = begin_style_check(ast, SOURCE.to_string(), &rules); - assert!(_lint_errors.is_ok()); - assert!(!_lint_errors.unwrap().is_empty()); - } } diff --git a/src/lint/rules/tests/common.rs b/src/lint/rules/tests/common.rs index 8111fb6b..9704de0a 100644 --- a/src/lint/rules/tests/common.rs +++ b/src/lint/rules/tests/common.rs @@ -36,14 +36,7 @@ pub fn run_linter(source_code: &str, rules: &CurrentRules) begin_style_check(ast, source_code.to_string(), rules) } -pub fn assert_snippet(source_code: &str, expected_errors: usize, rules: &CurrentRules) { - let lint_errors = run_linter(source_code, rules); - assert!(lint_errors.is_ok()); - assert_eq!(lint_errors.clone().unwrap().len(), expected_errors, - "{:#?}", lint_errors); -} - -pub fn robust_assert_snippet(source_code: &str, expected_errors: Vec, rules: &CurrentRules) { +pub fn assert_snippet(source_code: &str, expected_errors: Vec, rules: &CurrentRules) { let lint_errors = run_linter(source_code, rules); assert!(lint_errors.is_ok()); let lint_errors = lint_errors.unwrap(); diff --git a/src/lint/rules/tests/indentation/closing_brace.rs b/src/lint/rules/tests/indentation/closing_brace.rs index bd318d46..d68e2fc4 100644 --- a/src/lint/rules/tests/indentation/closing_brace.rs +++ b/src/lint/rules/tests/indentation/closing_brace.rs @@ -1,4 +1,4 @@ -use crate::lint::rules::tests::common::{set_up, robust_assert_snippet as assert_snippet}; +use crate::lint::rules::tests::common::{set_up, assert_snippet}; use crate::lint::rules::RuleType; static BASIC_COMPOUND_CORRECT: &str = " diff --git a/src/lint/rules/tests/indentation/code_block.rs b/src/lint/rules/tests/indentation/code_block.rs index b298c908..fd30d24c 100644 --- a/src/lint/rules/tests/indentation/code_block.rs +++ b/src/lint/rules/tests/indentation/code_block.rs @@ -1,4 +1,4 @@ -use crate::lint::rules::tests::common::{set_up, robust_assert_snippet as assert_snippet}; +use crate::lint::rules::tests::common::{set_up, assert_snippet}; use crate::lint::rules::RuleType; static FUNCTION_CONTENTS_INDENT_CORRECT: &str = " diff --git a/src/lint/rules/tests/indentation/empty_loop.rs b/src/lint/rules/tests/indentation/empty_loop.rs index a2df0add..3665abd2 100644 --- a/src/lint/rules/tests/indentation/empty_loop.rs +++ b/src/lint/rules/tests/indentation/empty_loop.rs @@ -1,4 +1,4 @@ -use crate::lint::rules::tests::common::{set_up, robust_assert_snippet as assert_snippet}; +use crate::lint::rules::tests::common::{set_up, assert_snippet}; use crate::lint::rules::RuleType; static EMPTY_LOOP_INCORRECT: &str = " diff --git a/src/lint/rules/tests/indentation/mod.rs b/src/lint/rules/tests/indentation/mod.rs index ab00ce85..4eb63c9f 100644 --- a/src/lint/rules/tests/indentation/mod.rs +++ b/src/lint/rules/tests/indentation/mod.rs @@ -6,6 +6,7 @@ mod switch_case; mod empty_loop; use crate::lint::rules::tests::common::assert_snippet; +use crate::lint::rules::RuleType; use crate::lint::LintCfg; use crate::lint::LongLineOptions; use crate::lint::rules::instantiate_rules; @@ -20,15 +21,23 @@ param some_parameter_name_in_this_device = some_long_name_bank.some_long_name_gr fn line_length_incorrect() { let mut cfg = LintCfg::default(); let mut rules = instantiate_rules(&cfg); - assert_snippet(LINE_LENGTH_INCORRECT, 1, &rules); + let expected_errors = define_expected_errors!( + RuleType::LL1, + (1, 1, 80, 103), + ); + assert_snippet(LINE_LENGTH_INCORRECT, expected_errors, &rules); // Test rule disable cfg.long_lines = None; rules = instantiate_rules(&cfg); - assert_snippet(LINE_LENGTH_INCORRECT, 0, &rules); + assert_snippet(LINE_LENGTH_INCORRECT, vec![], &rules); // Test lower max_length cfg.long_lines = Some(LongLineOptions{ max_length: (LINE_LENGTH_INCORRECT.len()-3).try_into().unwrap() }); rules = instantiate_rules(&cfg); - assert_snippet(LINE_LENGTH_INCORRECT, 1, &rules); + let expected_errors = define_expected_errors!( + RuleType::LL1, + (1, 1, 102, 103), + ); + assert_snippet(LINE_LENGTH_INCORRECT, expected_errors, &rules); } diff --git a/src/lint/rules/tests/indentation/no_tabs.rs b/src/lint/rules/tests/indentation/no_tabs.rs index d75255ad..8e010347 100644 --- a/src/lint/rules/tests/indentation/no_tabs.rs +++ b/src/lint/rules/tests/indentation/no_tabs.rs @@ -1,4 +1,4 @@ -use crate::lint::rules::tests::common::{set_up, robust_assert_snippet as assert_snippet}; +use crate::lint::rules::tests::common::{set_up, assert_snippet}; use crate::lint::rules::RuleType; static USING_TAB_INDENT_INCORRECT: &str = " diff --git a/src/lint/rules/tests/indentation/paren_expr.rs b/src/lint/rules/tests/indentation/paren_expr.rs index 85440a89..f4460939 100644 --- a/src/lint/rules/tests/indentation/paren_expr.rs +++ b/src/lint/rules/tests/indentation/paren_expr.rs @@ -1,4 +1,4 @@ -use crate::lint::rules::tests::common::{set_up, robust_assert_snippet as assert_snippet}; +use crate::lint::rules::tests::common::{set_up, assert_snippet}; use crate::lint::rules::RuleType; // A continuation line that is broken inside a parenthesized expression diff --git a/src/lint/rules/tests/indentation/switch_case.rs b/src/lint/rules/tests/indentation/switch_case.rs index 43450453..f0959231 100644 --- a/src/lint/rules/tests/indentation/switch_case.rs +++ b/src/lint/rules/tests/indentation/switch_case.rs @@ -1,4 +1,4 @@ -use crate::lint::rules::tests::common::{set_up, robust_assert_snippet as assert_snippet}; +use crate::lint::rules::tests::common::{set_up, assert_snippet}; use crate::lint::rules::RuleType; static SWITCH_CASE_INDENT_CORRECT: &str = " diff --git a/src/lint/rules/tests/spacing/mod.rs b/src/lint/rules/tests/spacing/mod.rs index 302e0a82..543f1758 100644 --- a/src/lint/rules/tests/spacing/mod.rs +++ b/src/lint/rules/tests/spacing/mod.rs @@ -1,6 +1,9 @@ -use crate::lint::rules::tests::common::assert_snippet; -use crate::lint::rules::instantiate_rules; -use crate::lint::LintCfg; +mod nsp_funpar; +mod nsp_inparen; +mod nsp_trailing; +mod nsp_unary; +mod sp_braces; +mod sp_punct; // Put whitespace (space or newline): // SP.reserved around reserved words, such as if, else, default, @@ -15,51 +18,6 @@ if(this_some_integer == 0x666) } "; -// SP.braces around braces ({ and }) -static SP_BRACES: &str = " -method this_is_some_method() {return 0;} - -method this_is_empty_method() { } - -bank pcie_config {register command {field mem { - method pcie_write(uint64 value) { - if (value != 0) {value = value + 1;} - default(value); - map_memory_alt(); - } -} -} -} -"; -#[test] -fn style_check_sp_braces() { - let mut cfg = LintCfg::default(); - let mut rules = instantiate_rules(&cfg); - assert_snippet(SP_BRACES, 6, &rules); - // Test rule disable - cfg.sp_brace = None; - rules = instantiate_rules(&cfg); - assert_snippet(SP_BRACES, 0, &rules); - -} - -static SP_BRACES_02: &str = " -typedef struct {uint16 idx;} hqm_cq_list_release_ctx_t; - -typedef layout \"little-endian\" {bitfields 1 {uint1 cq @ [0:0];} byte;} q_t; -"; -#[test] -fn style_check_sp_braces_02() { - let mut cfg = LintCfg::default(); - let mut rules = instantiate_rules(&cfg); - assert_snippet(SP_BRACES_02, 6, &rules); - // Test rule disable - cfg.sp_brace = None; - rules = instantiate_rules(&cfg); - assert_snippet(SP_BRACES_02, 0, &rules); - -} - // SP.binop around binary operators except the dereferencing operators dot // (a.b) and arrow (a->b) #[allow(dead_code)] @@ -79,27 +37,6 @@ local int this_some_integer = (flag?5:7)); } "; -// SP.punct after but not before colon, semicolon and comma -#[allow(dead_code)] -static SP_PUNCT: &str = " -method this_is_some_method(bool flag ,int8 var) { - local int this_some_integer = 0x666 ; - if(this_some_integer == 0x666) - return; - some_func(arg1 ,arg2 ,arg3 ,arg4); -} -"; -#[test] -fn style_check_sp_punct_rule() { - let mut cfg = LintCfg::default(); - let mut rules = instantiate_rules(&cfg); - assert_snippet(SP_PUNCT, 9, &rules); - // Test rule disable - cfg.sp_punct = None; - rules = instantiate_rules(&cfg); - assert_snippet(SP_PUNCT, 0, &rules); -} - // SP.ptrdecl between a type and the * marking a pointer #[allow(dead_code)] static SP_PTRDECL: &str = " @@ -120,65 +57,6 @@ if(!dummy_obj)//Not null } "; -// There should be no space: -// NSP.funpar between a function/method name and its opening parenthesis -static NSP_FUNPAR: &str = " -method this_is_some_method (conf_object_t *dummy_obj) { - if(!dummy_obj) - other_method_called (); -} -"; -#[test] -fn style_check_nsp_funpar() { - let mut cfg = LintCfg::default(); - let mut rules = instantiate_rules(&cfg); - assert_snippet(NSP_FUNPAR, 2, &rules); - // Test rule disable - cfg.nsp_funpar = None; - rules = instantiate_rules(&cfg); - assert_snippet(NSP_FUNPAR, 0, &rules); -} - -// NSP.inparen immediately inside parentheses or brackets -static NSP_INPAREN: &str = " -method this_is_some_method( conf_object_t *dummy_obj ) { - if( !dummy_obj[ 0 ] ) - return; -} -"; -#[test] -fn style_check_nsp_inparen() { - let mut cfg = LintCfg::default(); - let mut rules = instantiate_rules(&cfg); - assert_snippet(NSP_INPAREN, 6, &rules); - // Test rule disable - cfg.nsp_inparen = None; - rules = instantiate_rules(&cfg); - assert_snippet(NSP_INPAREN, 0, &rules); -} - -// NSP.unary between a unary operator and its operand -static NSP_UNARY: &str = " -method this_is_some_method(conf_object_t *dummy_obj) { - if(! dummy_obj) - return; - local uint64 p = & dummy_obj; - p ++; - -- p; - local int64 neg = - 1; -} -"; -#[test] -fn style_check_nsp_unary() { - let mut cfg = LintCfg::default(); - let mut rules = instantiate_rules(&cfg); - assert_snippet(NSP_UNARY, 5, &rules); - // Test rule disable - cfg.nsp_unary = None; - rules = instantiate_rules(&cfg); - assert_snippet(NSP_UNARY, 0, &rules); -} - // NSP.ptrdecl after the * marking a pointer in a declaration #[allow(dead_code)] static NSP_PTRDECL: &str = " @@ -187,24 +65,3 @@ if(!dummy_obj) return; } "; - -// Adding trailing whitespace removal to spacing rules: -// no whitespaces should be left at the end of a line between the last token -// and the newline \n -static NSP_TRAILING: &str = " -method this_is_some_method(int64 num) { - local int this_some_integer = 0x666; - if (this_some_integer == 0x666) - return; -} -"; -#[test] -fn style_check_nsp_trailing() { - let mut cfg = LintCfg::default(); - let mut rules = instantiate_rules(&cfg); - assert_snippet(NSP_TRAILING, 4, &rules); - // Test rule disable - cfg.nsp_trailing = None; - rules = instantiate_rules(&cfg); - assert_snippet(NSP_TRAILING, 0, &rules); -} diff --git a/src/lint/rules/tests/spacing/nsp_funpar.rs b/src/lint/rules/tests/spacing/nsp_funpar.rs new file mode 100644 index 00000000..b1979601 --- /dev/null +++ b/src/lint/rules/tests/spacing/nsp_funpar.rs @@ -0,0 +1,36 @@ +use crate::lint::rules::tests::common::{set_up, assert_snippet}; +use crate::lint::rules::RuleType; + +// There should be no space: +// NSP.funpar between a function/method name and its opening parenthesis +static NO_SPACE_METHOD_FUNC_INCORRECT: &str = " +method this_is_some_method (conf_object_t *dummy_obj) { + if(!dummy_obj) + other_method_called (); +} +"; +#[test] +fn no_space_method_func_incorrect() { + let mut rules = set_up(); + let expected_errors = define_expected_errors!( + RuleType::NspFunpar, + (1, 1, 26, 27), + (3, 3, 27, 28), + ); + assert_snippet(NO_SPACE_METHOD_FUNC_INCORRECT, expected_errors, &rules); + // Test rule disable + rules.nsp_funpar.enabled = false; + assert_snippet(NO_SPACE_METHOD_FUNC_INCORRECT, vec![], &rules); +} + +static NO_SPACE_METHOD_FUNC_CORRECT: &str = " +method this_is_some_method(conf_object_t *dummy_obj) { + if(!dummy_obj) + other_method_called(); +} +"; +#[test] +fn no_space_method_func_correct() { + let rules = set_up(); + assert_snippet(NO_SPACE_METHOD_FUNC_CORRECT, vec![], &rules); +} \ No newline at end of file diff --git a/src/lint/rules/tests/spacing/nsp_inparen.rs b/src/lint/rules/tests/spacing/nsp_inparen.rs new file mode 100644 index 00000000..944a0c3c --- /dev/null +++ b/src/lint/rules/tests/spacing/nsp_inparen.rs @@ -0,0 +1,40 @@ +use crate::lint::rules::tests::common::{set_up, assert_snippet}; +use crate::lint::rules::RuleType; + +// NSP.inparen immediately inside parentheses or brackets +static NO_SPACE_INPAREN_METHOD_FUNC_INDEX_INCORRECT: &str = " +method this_is_some_method( conf_object_t *dummy_obj ) { + if( !dummy_obj[ 0 ] ) + return; +} +"; +#[test] +fn no_space_inparen_method_func_index_incorrect() { + let mut rules = set_up(); + let expected_errors = define_expected_errors!( + RuleType::NspInparen, + (1, 1, 27, 28), + (1, 1, 52, 53), + (2, 2, 7, 8), + (2, 2, 23, 24), + (2, 2, 19, 20), + (2, 2, 21, 22), + ); + assert_snippet(NO_SPACE_INPAREN_METHOD_FUNC_INDEX_INCORRECT, expected_errors, &rules); + // Test rule disable + rules.nsp_inparen.enabled = false; + assert_snippet(NO_SPACE_INPAREN_METHOD_FUNC_INDEX_INCORRECT, vec![], &rules); +} + +// NSP.inparen immediately inside parentheses or brackets +static NO_SPACE_INPAREN_METHOD_FUNC_INDEX_CORRECT: &str = " +method this_is_some_method(conf_object_t *dummy_obj) { + if(!dummy_obj[0]) + return; +} +"; +#[test] +fn no_space_inparen_method_func_index_correct() { + let rules = set_up(); + assert_snippet(NO_SPACE_INPAREN_METHOD_FUNC_INDEX_CORRECT, vec![], &rules); +} \ No newline at end of file diff --git a/src/lint/rules/tests/spacing/nsp_trailing.rs b/src/lint/rules/tests/spacing/nsp_trailing.rs new file mode 100644 index 00000000..83981fef --- /dev/null +++ b/src/lint/rules/tests/spacing/nsp_trailing.rs @@ -0,0 +1,28 @@ +use crate::lint::rules::tests::common::{set_up, assert_snippet}; +use crate::lint::rules::RuleType; + +// Adding trailing whitespace removal to spacing rules: +// no whitespaces should be left at the end of a line between the last token +// and the newline \n +static TRAILING_WHITESPACE_INCORRECT: &str = " +method this_is_some_method(int64 num) { + local int this_some_integer = 0x666; + if (this_some_integer == 0x666) + return; +} +"; +#[test] +fn trailing_whitespace_incorrect() { + let mut rules = set_up(); + let expected_errors = define_expected_errors!( + RuleType::NspTrailing, + (2, 2, 40, 51), + (3, 3, 35, 42), + (4, 4, 15, 17), + (5, 5, 1, 4), + ); + assert_snippet(TRAILING_WHITESPACE_INCORRECT, expected_errors, &rules); + // Test rule disable + rules.nsp_trailing.enabled = false; + assert_snippet(TRAILING_WHITESPACE_INCORRECT, vec![], &rules); +} \ No newline at end of file diff --git a/src/lint/rules/tests/spacing/nsp_unary.rs b/src/lint/rules/tests/spacing/nsp_unary.rs new file mode 100644 index 00000000..4b059cc2 --- /dev/null +++ b/src/lint/rules/tests/spacing/nsp_unary.rs @@ -0,0 +1,46 @@ +use crate::lint::rules::tests::common::{set_up, assert_snippet}; +use crate::lint::rules::RuleType; + +// NSP.unary between a unary operator and its operand +static NO_SPACE_UNARY_INCORRECT: &str = " +method this_is_some_method(conf_object_t *dummy_obj) { + if(! dummy_obj) + return; + local uint64 p = & dummy_obj; + p ++; + -- p; + local int64 neg = - 1; +} +"; +#[test] +fn no_space_unary_incorrect() { + let mut rules = set_up(); + let expected_errors = define_expected_errors!( + RuleType::NspUnary, + (2, 2, 8, 9), + (4, 4, 22, 23), + (5, 5, 5, 6), + (6, 6, 6, 7), + (7, 7, 23, 24), + ); + assert_snippet(NO_SPACE_UNARY_INCORRECT, expected_errors, &rules); + // Test rule disable + rules.nsp_unary.enabled = false; + assert_snippet(NO_SPACE_UNARY_INCORRECT, vec![], &rules); +} + +static NO_SPACE_UNARY_CORRECT: &str = " +method this_is_some_method(conf_object_t *dummy_obj) { + if(!dummy_obj) + return; + local uint64 p = &dummy_obj; + p++; + --p; + local int64 neg = -1; +} +"; +#[test] +fn no_space_unary_correct() { + let rules = set_up(); + assert_snippet(NO_SPACE_UNARY_CORRECT, vec![], &rules); +} \ No newline at end of file diff --git a/src/lint/rules/tests/spacing/sp_braces.rs b/src/lint/rules/tests/spacing/sp_braces.rs new file mode 100644 index 00000000..c8424f98 --- /dev/null +++ b/src/lint/rules/tests/spacing/sp_braces.rs @@ -0,0 +1,94 @@ +use crate::lint::rules::tests::common::{set_up, assert_snippet}; +use crate::lint::rules::RuleType; + +// SP.braces around braces ({ and }) +static SPACE_BRACES_METHOD_BANK_REGISTER_FIELD_INCORRECT: &str = " +method this_is_some_method() {return 0;} + +method this_is_empty_method() { } + +bank pcie_config {register command {field mem { + method pcie_write(uint64 value) { + if (value != 0) {value = value + 1;} + default(value); + map_memory_alt(); + } +} +} +} +"; +#[test] +fn space_braces_method_bank_register_field_incorrect() { + let mut rules = set_up(); + let expected_errors = define_expected_errors!( + RuleType::SpBraces, + (1, 1, 29, 30), + (1, 1, 39, 40), + (5, 5, 17, 18), + (5, 5, 35, 36), + (7, 7, 24, 25), + (7, 7, 43, 44), + ); + assert_snippet(SPACE_BRACES_METHOD_BANK_REGISTER_FIELD_INCORRECT, expected_errors, &rules); + // Test rule disable + rules.sp_brace.enabled = false; + assert_snippet(SPACE_BRACES_METHOD_BANK_REGISTER_FIELD_INCORRECT, vec![], &rules); +} + +static SPACE_BRACES_METHOD_BANK_REGISTER_FIELD_CORRECT: &str = " +method this_is_some_method() { return 0; } + +method this_is_empty_method() { } + +bank pcie_config { register command { field mem { + method pcie_write(uint64 value) { + if (value != 0) { value = value + 1; } + default(value); + map_memory_alt(); + } +} +} +} +"; +#[test] +fn space_braces_method_bank_register_field_correct() { + let rules = set_up(); + assert_snippet(SPACE_BRACES_METHOD_BANK_REGISTER_FIELD_CORRECT, vec![], &rules); +} + +static SPACE_BRACES_STRUCT_LAYOUT_BITF_INCORRECT: &str = " +typedef struct {uint16 idx;} hqm_cq_list_release_ctx_t; + +typedef layout \"little-endian\" {bitfields 1 {uint1 cq @ [0:0];} byte;} q_t; +"; +#[test] +fn space_braces_struct_layout_bitf_incorrect() { + let mut rules = set_up(); + let expected_errors = define_expected_errors!( + RuleType::SpBraces, + (1, 1, 15, 16), + (1, 1, 27, 28), + (3, 3, 31, 32), + (3, 3, 69, 70), + (3, 3, 44, 45), + (3, 3, 62, 63), + ); + assert_snippet(SPACE_BRACES_STRUCT_LAYOUT_BITF_INCORRECT, expected_errors, &rules); + // Test rule disable + rules.sp_brace.enabled = false; + assert_snippet(SPACE_BRACES_STRUCT_LAYOUT_BITF_INCORRECT, vec![], &rules); +} + +static SPACE_BRACES_STRUCT_LAYOUT_BITF_CORRECT: &str = " +typedef struct { uint16 idx; } hqm_cq_list_release_ctx_t; + +typedef layout \"little-endian\" { bitfields 1 { uint1 cq @ [0:0]; } byte; } q_t; +"; +#[test] +fn space_braces_struct_layout_bitf_correct() { + let mut rules = set_up(); + assert_snippet(SPACE_BRACES_STRUCT_LAYOUT_BITF_CORRECT, vec![], &rules); + // Test rule disable + rules.sp_brace.enabled = false; + assert_snippet(SPACE_BRACES_STRUCT_LAYOUT_BITF_CORRECT, vec![], &rules); +} diff --git a/src/lint/rules/tests/spacing/sp_punct.rs b/src/lint/rules/tests/spacing/sp_punct.rs new file mode 100644 index 00000000..eb11dd79 --- /dev/null +++ b/src/lint/rules/tests/spacing/sp_punct.rs @@ -0,0 +1,46 @@ +use crate::lint::rules::tests::common::{set_up, assert_snippet}; +use crate::lint::rules::RuleType; + +// SP.punct after but not before colon, semicolon and comma +static SP_PUNCT_INCORRECT: &str = " +method this_is_some_method(bool flag ,int8 var) { + local int this_some_integer = 0x666 ; + if(this_some_integer == 0x666) + return; + some_func(arg1 ,arg2 ,arg3 ,arg4); +} +"; +#[test] +fn sp_punct_incorrect() { + let mut rules = set_up(); + let expected_errors = define_expected_errors!( + RuleType::SpPunct, + (1, 1, 36, 37), + (1, 1, 37, 46), + (2, 2, 39, 40), + (5, 5, 18, 19), + (5, 5, 19, 24), + (5, 5, 24, 25), + (5, 5, 25, 30), + (5, 5, 30, 31), + (5, 5, 31, 36), + ); + assert_snippet(SP_PUNCT_INCORRECT, expected_errors, &rules); + // Test rule disable + rules.sp_punct.enabled = false; + assert_snippet(SP_PUNCT_INCORRECT, vec![], &rules); +} + +static SP_PUNCT_CORRECT: &str = " +method this_is_some_method(bool flag, int8 var) { + local int this_some_integer = 0x666; + if(this_some_integer == 0x666) + return; + some_func(arg1, arg2, arg3, arg4); +} +"; +#[test] +fn sp_punct_correct() { + let rules = set_up(); + assert_snippet(SP_PUNCT_CORRECT, vec![], &rules); +} \ No newline at end of file