Skip to content

Commit

Permalink
Moved sources to version folder
Browse files Browse the repository at this point in the history
Merged PR Masterminds#173 of upstream repository
  • Loading branch information
piccobit committed Jul 26, 2022
1 parent d8e6814 commit bc087ca
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions version.go → v4/version.go
Expand Up @@ -458,6 +458,23 @@ func (v *Version) Value() (driver.Value, error) {
return v.String(), nil
}

// UnmarshalText implements the encoding.TextUnmarshaler interface.
func (v *Version) UnmarshalText(text []byte) error {
temp, err := NewVersion(string(text))
if err != nil {
return err
}

*v = *temp

return nil
}

// MarshalText implements the encoding.TextMarshaler interface.
func (v *Version) MarshalText() ([]byte, error) {
return []byte(v.String()), nil
}

func compareSegment(v, o uint64) int {
if v < o {
return -1
Expand Down
36 changes: 36 additions & 0 deletions version_test.go → v4/version_test.go
Expand Up @@ -623,3 +623,39 @@ func TestValidateMetadata(t *testing.T) {
}
}
}

func TestTextMarshal(t *testing.T) {
sVer := "1.1.1"

x, err := StrictNewVersion(sVer)
if err != nil {
t.Errorf("Error creating version: %s", err)
}

out, err2 := x.MarshalText()
if err2 != nil {
t.Errorf("Error marshaling version: %s", err2)
}

got := string(out)
want := sVer
if got != want {
t.Errorf("Error marshaling unexpected marshaled content: got=%q want=%q", got, want)
}
}

func TestTextUnmarshal(t *testing.T) {
sVer := "1.1.1"
ver := &Version{}

err := ver.UnmarshalText([]byte(sVer))
if err != nil {
t.Errorf("Error unmarshaling version: %s", err)
}

got := ver.String()
want := sVer
if got != want {
t.Errorf("Error unmarshaling unexpected object content: got=%q want=%q", got, want)
}
}

0 comments on commit bc087ca

Please sign in to comment.