diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-21 00:57:29 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-21 00:57:29 +0900 |
| commit | 94d3d5332299bf78bc789397323652529c1d9575 (patch) | |
| tree | 988489f095ac41604fe38e45f1a085ccce6627a7 | |
| parent | b2ad46d4341a07f4d60ccc756bf1ddfa0c4e17f2 (diff) | |
| download | php-shirabe-94d3d5332299bf78bc789397323652529c1d9575.tar.gz php-shirabe-94d3d5332299bf78bc789397323652529c1d9575.tar.zst php-shirabe-94d3d5332299bf78bc789397323652529c1d9575.zip | |
test(dependency-resolver): port RequestTest
Both cases pass. AnyConstraint has no PartialEq (foreign crate), so the
assertEquals on the requires map is reproduced via Debug-representation
comparison. The unused ArrayRepository setup from the original is omitted.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| -rw-r--r-- | crates/shirabe/tests/dependency_resolver/main.rs | 1 | ||||
| -rw-r--r-- | crates/shirabe/tests/dependency_resolver/request_test.rs | 54 |
2 files changed, 55 insertions, 0 deletions
diff --git a/crates/shirabe/tests/dependency_resolver/main.rs b/crates/shirabe/tests/dependency_resolver/main.rs new file mode 100644 index 0000000..35fba9a --- /dev/null +++ b/crates/shirabe/tests/dependency_resolver/main.rs @@ -0,0 +1 @@ +mod request_test; diff --git a/crates/shirabe/tests/dependency_resolver/request_test.rs b/crates/shirabe/tests/dependency_resolver/request_test.rs index 9a211a7..969cd4d 100644 --- a/crates/shirabe/tests/dependency_resolver/request_test.rs +++ b/crates/shirabe/tests/dependency_resolver/request_test.rs @@ -1 +1,55 @@ //! ref: composer/tests/Composer/Test/DependencyResolver/RequestTest.php + +use indexmap::IndexMap; +use shirabe::dependency_resolver::request::Request; +use shirabe::package::version::version_parser::VersionParser; +use shirabe_semver::constraint::{AnyConstraint, MatchAllConstraint, SimpleConstraint}; + +// AnyConstraint does not implement PartialEq (it lives in another crate), so +// the original assertEquals() on the requires map is reproduced by comparing +// the Debug representations. +// +// The original tests also build ArrayRepositories and add packages, but those +// are never read by the assertions (the Request does not consult them), so the +// repository setup is omitted here. + +fn get_version_constraint(operator: &str, version: &str) -> AnyConstraint { + let normalized = VersionParser::new().normalize(version, None).unwrap(); + AnyConstraint::Simple(SimpleConstraint::new( + operator.to_string(), + normalized, + Some(format!("{} {}", operator, version)), + )) +} + +#[test] +fn test_request_install() { + let mut request = Request::new(None); + request.require_name("foo", None).unwrap(); + + let mut expected: IndexMap<String, AnyConstraint> = IndexMap::new(); + expected.insert("foo".to_string(), MatchAllConstraint::new(None).into()); + + assert_eq!( + format!("{:?}", expected), + format!("{:?}", request.get_requires()) + ); +} + +#[test] +fn test_request_install_same_package_from_different_repositories() { + let constraint = get_version_constraint("=", "1"); + + let mut request = Request::new(None); + request + .require_name("foo", Some(constraint.clone())) + .unwrap(); + + let mut expected: IndexMap<String, AnyConstraint> = IndexMap::new(); + expected.insert("foo".to_string(), constraint); + + assert_eq!( + format!("{:?}", expected), + format!("{:?}", request.get_requires()) + ); +} |
