-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow subject attributes to be string wrapper numerics; attempt to sa…
…fely coerce (#35) * allow subject attributes to be string wrapper numerics; attempt to safely coerce * add comment
- Loading branch information
1 parent
5f87650
commit bf8c56b
Showing
4 changed files
with
76 additions
and
5 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
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,34 @@ | ||
package eppoclient | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestToFloat64(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input interface{} | ||
expected float64 | ||
expectErr bool | ||
}{ | ||
{"Float64Input", 123.456, 123.456, false}, | ||
{"StringInputValid", "789.012", 789.012, false}, | ||
{"StringInputInvalid", "abc", 0, true}, | ||
{"SemVerInputInvalid", "1.2.3", 0, true}, | ||
{"BoolInput", true, 0, true}, | ||
{"IntInput", 123, 0, true}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result, err := ToFloat64(tt.input) | ||
if (err != nil) != tt.expectErr { | ||
t.Errorf("ToFloat64(%v) error = %v, expectErr %v", tt.input, err, tt.expectErr) | ||
return | ||
} | ||
if !tt.expectErr && result != tt.expected { | ||
t.Errorf("ToFloat64(%v) = %v, want %v", tt.input, result, tt.expected) | ||
} | ||
}) | ||
} | ||
} |