Skip to content

Commit

Permalink
Routes should have at least one name set
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitfred committed Oct 7, 2024
1 parent 913e64c commit d0f9a53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/validators/check_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn empty_name<T: std::fmt::Display>(o: &T) -> bool {
// a route has a name if it has either a short or a long name
fn empty_route_name(r: &gtfs_structures::Route) -> bool {
r.short_name.as_ref().map(|n| n.is_empty()).unwrap_or(true)
|| r.long_name.as_ref().map(|n| n.is_empty()).unwrap_or(true)
&& r.long_name.as_ref().map(|n| n.is_empty()).unwrap_or(true)
}

fn make_missing_name_issue<T: gtfs_structures::Id + gtfs_structures::Type + std::fmt::Display>(
Expand All @@ -57,6 +57,7 @@ fn make_missing_name_issue<T: gtfs_structures::Id + gtfs_structures::Type + std:
fn test_routes() {
let gtfs = gtfs_structures::Gtfs::new("test_data/check_name").unwrap();
let issues = validate(&gtfs);

let route_name_issues: Vec<_> = issues
.iter()
.filter(|issue| issue.object_id == *"35")
Expand All @@ -66,6 +67,20 @@ fn test_routes() {
assert_eq!("35", route_name_issues[0].object_id);
assert_eq!(IssueType::MissingName, route_name_issues[0].issue_type);
assert_eq!(Severity::Error, route_name_issues[0].severity);

let route_name_issues: Vec<_> = issues
.iter()
.filter(|issue| issue.object_id == *"36")
.collect();

assert_eq!(0, route_name_issues.len());

let route_name_issues: Vec<_> = issues
.iter()
.filter(|issue| issue.object_id == *"37")
.collect();

assert_eq!(0, route_name_issues.len());
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions test_data/check_name/routes.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color
35,848,,,"",3,,000000,FFFFFF
36,848,SHORT_NAME,,"",3,,000000,FFFFFF
37,848,,LONG_NAME,"",3,,000000,FFFFFF

0 comments on commit d0f9a53

Please sign in to comment.