Skip to content

test: add property type validation tests#5

Open
Shubh-Raj wants to merge 1 commit intoaccordproject:mainfrom
Shubh-Raj:shubhraj/i4/add-property-type-tests
Open

test: add property type validation tests#5
Shubh-Raj wants to merge 1 commit intoaccordproject:mainfrom
Shubh-Raj:shubhraj/i4/add-property-type-tests

Conversation

@Shubh-Raj
Copy link
Copy Markdown
Contributor

Fixes #4

Description

Adds unit tests for property type validation to improve test coverage.

Tests Added

  1. test_boolean_property_type_mismatch - Verifies validation fails when string passed where boolean expected
  2. test_valid_integer_property_definition - Verifies IntegerProperty definitions are correctly validated
  3. test_array_property_validation - Verifies properties with isArray: true are correctly validated
  4. test_optional_property_validation - Verifies properties with isOptional: true are correctly validated

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds unit tests to improve test coverage for property type validation in the Concerto validator. The tests validate metamodel definitions with different property configurations including boolean type checking, integer properties, array properties, and optional properties.

Changes:

  • Added 4 new unit tests for property type validation scenarios
  • Tests cover boolean type mismatch, integer property definitions, array properties, and optional properties

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib.rs Outdated
Comment on lines +167 to +196
fn test_valid_integer_property_definition() {
// Test that a valid IntegerProperty definition passes validation
let model_with_integer_property = r#"{
"$class": "[email protected]",
"namespace": "[email protected]",
"imports": [],
"declarations": [
{
"$class": "[email protected]",
"name": "TestConcept",
"isAbstract": false,
"properties": [
{
"$class": "[email protected]",
"name": "count",
"isArray": false,
"isOptional": false
}
]
}
]
}"#;

let result = validate_metamodel(model_with_integer_property);
assert!(
result.is_ok(),
"Valid IntegerProperty definition should pass: {:?}",
result
);
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test validates that a valid IntegerProperty definition passes validation, but according to issue #4, the proposed test was test_integer_property_type_mismatch which should fail when a string is passed where an integer is expected. This test doesn't verify the type validation logic of the validate_integer_property function mentioned in the issue (lines 222-228 in model_manager/mod.rs). Consider adding a test that validates type mismatch behavior, for example, by including a property with an IntegerProperty type but providing a string value.

Copilot uses AI. Check for mistakes.
Comment thread src/lib.rs Outdated
Comment on lines +199 to +228
fn test_array_property_validation() {
// Test that isArray: true properties are correctly defined
let model_with_array = r#"{
"$class": "[email protected]",
"namespace": "[email protected]",
"imports": [],
"declarations": [
{
"$class": "[email protected]",
"name": "TestConcept",
"isAbstract": false,
"properties": [
{
"$class": "[email protected]",
"name": "tags",
"isArray": true,
"isOptional": false
}
]
}
]
}"#;

let result = validate_metamodel(model_with_array);
assert!(
result.is_ok(),
"Array property definition should pass validation: {:?}",
result
);
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test validates that a property with isArray: true is correctly defined, but according to issue #4, the proposed test was test_array_property_expects_array which should fail when a non-array is passed for an isArray: true property. This doesn't test the array validation logic in validate_property_structure (lines 122-146 in model_manager/mod.rs). Consider adding a test that provides a non-array value (e.g., a single string) for a property defined with isArray: true to verify that validation properly rejects such input.

Copilot uses AI. Check for mistakes.
Comment thread src/lib.rs Outdated
Comment on lines +231 to +260
fn test_optional_property_validation() {
// Test that isOptional: true properties are correctly defined
let model_with_optional = r#"{
"$class": "[email protected]",
"namespace": "[email protected]",
"imports": [],
"declarations": [
{
"$class": "[email protected]",
"name": "TestConcept",
"isAbstract": false,
"properties": [
{
"$class": "[email protected]",
"name": "nickname",
"isArray": false,
"isOptional": true
}
]
}
]
}"#;

let result = validate_metamodel(model_with_optional);
assert!(
result.is_ok(),
"Optional property definition should pass validation: {:?}",
result
);
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test validates that a property with isOptional: true is correctly defined, but according to issue #4, the proposed test was test_optional_property_can_be_missing which should verify that optional properties do not cause validation failure when absent. This doesn't test the optional property handling logic in validate_required_properties (lines 96-112 in model_manager/mod.rs). Consider adding a test that omits an optional property from the data to verify that the validation correctly allows missing optional properties.

Copilot uses AI. Check for mistakes.
@Shubh-Raj
Copy link
Copy Markdown
Contributor Author

I am working on the copilot suggestions.

@Shubh-Raj Shubh-Raj force-pushed the shubhraj/i4/add-property-type-tests branch 2 times, most recently from 9415772 to 20ebad7 Compare March 2, 2026 14:21
- test_boolean_property_type_mismatch: fails when string passed where boolean expected
- test_integer_property_type_mismatch: fails when string passed for boolean field in IntegerProperty
- test_array_property_expects_array: fails when non-array passed for array property
- test_optional_property_can_be_missing: passes when optional superType is omitted

Fixes accordproject#4

Signed-off-by: Shubh-Raj <[email protected]>
@Shubh-Raj Shubh-Raj force-pushed the shubhraj/i4/add-property-type-tests branch from 20ebad7 to 5479791 Compare March 2, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for property type validation

2 participants