Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Apr 15, 2024
1 parent 17a5ff4 commit d40712e
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions src/generator/graphql_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ struct Package {
}

impl Package {
fn parse(input: &str, separator: &str) -> Option<Self> {
fn parse(input: &str) -> Option<Self> {
let separator = PACKAGE_SEPARATOR;
let path = input.split(separator).map(String::from).collect::<Vec<_>>();
if path.is_empty() | input.is_empty() {
None
Expand Down Expand Up @@ -60,33 +61,28 @@ impl GraphQLType<Unparsed> {
Self(Unparsed { package: None, name: input.to_string() })
}

// TODO: separator should be taken as an input
fn parse(&self, convertor: Entity) -> Option<GraphQLType<Parsed>> {
fn parse(&self, entity: Entity) -> Option<GraphQLType<Parsed>> {
let unparsed = &self.0;
let name = &unparsed.name;
let package = &unparsed.package;
if name.contains(PACKAGE_SEPARATOR) {
if let Some((package, name)) = name.rsplit_once(PACKAGE_SEPARATOR) {
let package = Package::parse(package, PACKAGE_SEPARATOR);
let parsed_package = unparsed.package.as_deref().and_then(Package::parse);

// Name contains package
if unparsed.name.contains(PACKAGE_SEPARATOR) {
if let Some((package, name)) = unparsed.name.rsplit_once(PACKAGE_SEPARATOR) {
Some(GraphQLType(Parsed {
package,
name: name.to_string(),
entity: convertor,
package: parsed_package.or(Package::parse(package)),
entity,
}))
} else {
None

Check warning on line 77 in src/generator/graphql_type.rs

View check run for this annotation

Codecov / codecov/patch

src/generator/graphql_type.rs#L77

Added line #L77 was not covered by tests
}
} else if let Some(package) = package {
Some(GraphQLType(Parsed {
package: Package::parse(package, PACKAGE_SEPARATOR),
name: name.to_string(),
entity: convertor,
}))
} else {
}
// Name doesn't contain package
else {
Some(GraphQLType(Parsed {
package: None,
name: name.to_string(),
entity: convertor,
package: parsed_package,
name: unparsed.name.to_string(),
entity,
}))
}
}
Expand Down Expand Up @@ -254,7 +250,7 @@ mod tests {
for ((entity, package, name), expected) in input {
let mut g = GraphQLType::new(name);
if let Some(package) = package {
g = g.clone().package(package);
g = g.package(package);
}

let actual = g.parse(entity).unwrap().to_string();
Expand Down

0 comments on commit d40712e

Please sign in to comment.