-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert FII dividends date to YYYY-MM-DD format
- Loading branch information
Showing
2 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package parsers | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_comma2dot(t *testing.T) { | ||
type args struct { | ||
val string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want float64 | ||
}{ | ||
{ | ||
name: "should work", | ||
args: args{val: "1.230,56"}, | ||
want: 1230.56, | ||
}, | ||
{ | ||
name: "should return 0", | ||
args: args{val: "shouldbeanum"}, | ||
want: 0, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := comma2dot(tt.args.val); got != tt.want { | ||
t.Errorf("comma2dot() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_convertDateStr(t *testing.T) { | ||
type args struct { | ||
date string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
name: "should work", | ||
args: args{date: "01/02/2021"}, | ||
want: "2021-02-01", | ||
}, | ||
{ | ||
name: "should return the input", | ||
args: args{date: "wrong/date"}, | ||
want: "wrong/date", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := fixDate(tt.args.date); got != tt.want { | ||
t.Errorf("fixDate() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |