Skip to content

Commit

Permalink
tb: add Variant Types name collision test cases
Browse files Browse the repository at this point in the history
This commit should have been part of commit 6b8cabc, but was missed
there.
  • Loading branch information
r-bk committed Sep 7, 2024
1 parent 528a9fb commit 0478e92
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
15 changes: 14 additions & 1 deletion crates/tighterror-build/src/parser/toml/test_toml_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,10 +1501,23 @@ fn test_error_variant_type_bad_name() {
("my_err", BAD_IDENTIFIER_CHARACTERS),
("myErr", BAD_IDENTIFIER_CASE),
("myerr", BAD_IDENTIFIER_CASE),
("CustomErr", NAME_COLLISION),
("CustomErrCat", NAME_COLLISION),
("CustomErrKind", NAME_COLLISION),
];

let pfx = r#"
[module]
err_name = "CustomErr"
err_cat_name = "CustomErrCat"
err_kind_name = "CustomErrKind"
"#;

for tc in test_cases {
let s = format!("[[errors]]\nname = \"MY_ERR\"\nvariant_type = \"{}\"", tc.0);
let s = format!(
"{pfx}\n[[errors]]\nname = \"MY_ERR\"\nvariant_type = \"{}\"",
tc.0
);
assert_eq!(TomlParser::parse_str(&s).unwrap_err().kind(), tc.1);
}
}
Expand Down
15 changes: 14 additions & 1 deletion crates/tighterror-build/src/parser/yaml/test_yaml_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1542,10 +1542,23 @@ fn test_error_variant_type_bad_name() {
("my_err", BAD_IDENTIFIER_CHARACTERS),
("myErr", BAD_IDENTIFIER_CASE),
("myerr", BAD_IDENTIFIER_CASE),
("CustomErr", NAME_COLLISION),
("CustomErrCat", NAME_COLLISION),
("CustomErrKind", NAME_COLLISION),
];

let pfx = r#"
---
module:
err_name: CustomErr
err_cat_name: CustomErrCat
err_kind_name: CustomErrKind
errors:
"#;

for tc in test_cases {
let s = format!("---\nerrors:\n - name: MY_ERR\n variant_type: {}", tc.0);
let s = format!("{pfx} - name: MY_ERR\n variant_type: {}", tc.0);
assert_eq!(YamlParser::parse_str(&s).unwrap_err().kind(), tc.1);
}
}
Expand Down

0 comments on commit 0478e92

Please sign in to comment.