Skip to content

Commit

Permalink
improve asdfparser
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Vaumoron <[email protected]>
  • Loading branch information
dvaumoron committed Dec 22, 2024
1 parent cd5eb15 commit 7e4b7ea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
9 changes: 3 additions & 6 deletions versionmanager/semantic/parser/asdf/asdfparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ func parseVersionFromToolFileReader(filePath string, reader io.Reader, toolName
continue
}

name, remain, found := strings.Cut(trimmedLine, " ")
if found && name == toolName { // no need to trim name (already done (left by TrimSpace, right by Cut)
version, _, _ := strings.Cut(remain, "#")
resolvedVersion = strings.TrimSpace(version)

break
parts := strings.Fields(trimmedLine)
if len(parts) >= 2 && parts[0] == toolName {
resolvedVersion, _, _ = strings.Cut(parts[1], "#") // handle comment no separeted by space

Check failure on line 78 in versionmanager/semantic/parser/asdf/asdfparser.go

View workflow job for this annotation

GitHub Actions / Check for spelling errors

separeted ==> separated
}
}

Expand Down
11 changes: 11 additions & 0 deletions versionmanager/semantic/parser/asdf/asdfparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,15 @@ func TestParseVersionFromToolFileReader(t *testing.T) {
t.Fatal("Unexpected version : ", version)
}
})

t.Run("LineFallback", func(t *testing.T) {

Check failure on line 57 in versionmanager/semantic/parser/asdf/asdfparser_test.go

View workflow job for this annotation

GitHub Actions / lint

Function TestParseVersionFromToolFileReader missing the call to method parallel in the test run (paralleltest)
version, err := parseVersionFromToolFileReader("", bytes.NewReader(toolFileData), "python", loghelper.InertDisplayer)
if err != nil {
t.Fatal("Unexpected parse error : ", err)
}

if version != "3.7.2" {
t.Fatal("Unexpected version : ", version)
}
})
}
3 changes: 2 additions & 1 deletion versionmanager/semantic/parser/asdf/testdata/.tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ruby 2.5.3 # This is a comment
ruby 2.5.3# This is a comment
# This is another comment
nodejs 10.15.0
python 3.7.2 2.7.15

0 comments on commit 7e4b7ea

Please sign in to comment.