Skip to content

Commit

Permalink
Merge branch 'main' into formatter-error
Browse files Browse the repository at this point in the history
  • Loading branch information
subashcs authored Apr 1, 2024
2 parents eeeae76 + 8a4517b commit 102df7a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions nepalitime/nepalitimeregex.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package nepalitime

import (
"errors"
"fmt"
"regexp"
"strings"
Expand Down Expand Up @@ -80,7 +79,7 @@ func (obj *nepaliTimeRegex) pattern(format string) (string, error) {
processedFormat = fmt.Sprintf("%s%s%s", processedFormat, string(format[:directiveIndex-1]), val)
format = string(format[directiveIndex+indexIncrement:])
} else {
return "", errors.New("no pattern matched")
return "", fmt.Errorf("the format '%%%s' isn't supported", directiveToCheck)
}
}

Expand Down
6 changes: 3 additions & 3 deletions nepalitime/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Parse(datetimeStr string, format string) (*NepaliTime, error) {
nepalitime, err := validate(datetimeStr, format)

if err != nil {
return nil, errors.New("datetime string did not match with given format")
return nil, err
}

return nepalitime, nil
Expand Down Expand Up @@ -87,7 +87,7 @@ func extract(datetimeStr string, format string) (map[string]string, error) {
match := reCompiledFormat.FindStringSubmatch(datetimeStr)

if len(match) < 1 {
return nil, errors.New("no pattern matched")
return nil, errors.New("datetime string did not match with given format")
}

result := make(map[string]string)
Expand Down Expand Up @@ -211,7 +211,7 @@ func transform(data map[string]string) (map[string]int, error) {
fraction, err = strconv.Atoi(s)

if err != nil {
return nil, errors.New("error while getting nanoseconds data")
return nil, errors.New("invalid value in %f")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions nepalitime/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func TestParseWithRandomFormats(t *testing.T) {
got, err := nepalitime.Parse(datetimeStr, format)

assert.Nil(t, got, "NepaliTime object should be nil")
assert.EqualError(t, err, "datetime string did not match with given format", "error message did not match")
assert.EqualError(t, err, "the format '%k' isn't supported", "error message did not match")
}

func TestParseForInvalidYear(t *testing.T) {
Expand All @@ -273,7 +273,7 @@ func TestParseForInvalidYear(t *testing.T) {
got, err := nepalitime.Parse(datetimeStr, format)

assert.Nil(t, got, "NepaliTime object should be nil")
assert.EqualError(t, err, "datetime string did not match with given format", "error message did not match")
assert.EqualError(t, err, "date is out of range", "error message did not match")
}

func TestParseForValidYear(t *testing.T) {
Expand Down

0 comments on commit 102df7a

Please sign in to comment.