Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser): fixed error messages for parsing #21

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
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")

Check warning on line 214 in nepalitime/parser.go

View check run for this annotation

Codecov / codecov/patch

nepalitime/parser.go#L214

Added line #L214 was not covered by tests
}
}
}
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
Loading