fix(swift): parsing swift version (#1913)

* fix parse swift version for swift-for-tensorflow

* add test for parsing swift version

Co-authored-by: Masashi Aso <maashi.apple.japan@icloud.com>
This commit is contained in:
Masashi Aso 2020-11-21 03:34:27 +09:00 committed by GitHub
parent 87424d2eaf
commit eb4e59d9ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 5 deletions

View File

@ -53,11 +53,12 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
}
fn parse_swift_version(swift_version: &str) -> Option<String> {
let version = swift_version
// split into ["Apple", "Swift", "version", "5.2.2", ...]
.split_whitespace()
// return "5.2.2"
.nth(3)?;
// split into ["Apple", "Swift", "version", "5.2.2", ...] or
// ["Swift", "version", "5.3-dev", ...]
let mut splited = swift_version.split_whitespace();
let _ = splited.position(|t| t == "version")?;
// return "5.2.2" or "5.3-dev"
let version = splited.next()?;
Some(format!("v{}", version))
}
@ -76,6 +77,12 @@ mod tests {
assert_eq!(parse_swift_version(input), Some(String::from("v5.2.2")));
}
#[test]
fn test_parse_swift_version_without_org_name() {
let input = "Swift version 5.3-dev (LLVM ..., Swift ...)";
assert_eq!(parse_swift_version(input), Some(String::from("v5.3-dev")));
}
#[test]
fn folder_without_swift_files() -> io::Result<()> {
let dir = tempfile::tempdir()?;