mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Add initial test suite for core:strconv
This commit is contained in:
@@ -25,6 +25,7 @@ all_bsd: download_test_assets \
|
|||||||
reflect_test \
|
reflect_test \
|
||||||
runtime_test \
|
runtime_test \
|
||||||
slice_test \
|
slice_test \
|
||||||
|
strconv_test \
|
||||||
strings_test \
|
strings_test \
|
||||||
thread_test \
|
thread_test \
|
||||||
time_test
|
time_test
|
||||||
@@ -98,6 +99,9 @@ runtime_test:
|
|||||||
slice_test:
|
slice_test:
|
||||||
$(ODIN) test slice $(COMMON) -out:test_core_slice
|
$(ODIN) test slice $(COMMON) -out:test_core_slice
|
||||||
|
|
||||||
|
strconv_test:
|
||||||
|
$(ODIN) test strconv $(COMMON) -out:test_core_strconv
|
||||||
|
|
||||||
strings_test:
|
strings_test:
|
||||||
$(ODIN) test strings $(COMMON) -out:test_core_strings
|
$(ODIN) test strings $(COMMON) -out:test_core_strings
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,11 @@ echo Running core:slice tests
|
|||||||
echo ---
|
echo ---
|
||||||
%PATH_TO_ODIN% test slice %COMMON% -out:test_core_slice.exe || exit /b
|
%PATH_TO_ODIN% test slice %COMMON% -out:test_core_slice.exe || exit /b
|
||||||
|
|
||||||
|
echo ---
|
||||||
|
echo Running core:strconv tests
|
||||||
|
echo ---
|
||||||
|
%PATH_TO_ODIN% test strconv %COMMON% -out:test_core_strconv.exe || exit /b
|
||||||
|
|
||||||
echo ---
|
echo ---
|
||||||
echo Running core:strings tests
|
echo Running core:strings tests
|
||||||
echo ---
|
echo ---
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package test_core_strconv
|
||||||
|
|
||||||
|
import "core:math"
|
||||||
|
import "core:strconv"
|
||||||
|
import "core:testing"
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_infinity :: proc(t: ^testing.T) {
|
||||||
|
pos_inf := math.inf_f64(+1)
|
||||||
|
neg_inf := math.inf_f64(-1)
|
||||||
|
|
||||||
|
n: int
|
||||||
|
s := "infinity"
|
||||||
|
|
||||||
|
for i in 1 ..< len(s) + 1 {
|
||||||
|
ss := s[:i]
|
||||||
|
f, ok := strconv.parse_f64(ss, &n)
|
||||||
|
if i == 3 { // "inf"
|
||||||
|
testing.expect_value(t, f, pos_inf)
|
||||||
|
testing.expect_value(t, n, 3)
|
||||||
|
testing.expect_value(t, ok, true)
|
||||||
|
} else if i == 8 { // "infinity"
|
||||||
|
testing.expect_value(t, f, pos_inf)
|
||||||
|
testing.expect_value(t, n, 8)
|
||||||
|
testing.expect_value(t, ok, true)
|
||||||
|
} else { // invalid substring
|
||||||
|
testing.expect_value(t, f, 0)
|
||||||
|
testing.expect_value(t, n, 0)
|
||||||
|
testing.expect_value(t, ok, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s = "+infinity"
|
||||||
|
for i in 1 ..< len(s) + 1 {
|
||||||
|
ss := s[:i]
|
||||||
|
f, ok := strconv.parse_f64(ss, &n)
|
||||||
|
if i == 4 { // "+inf"
|
||||||
|
testing.expect_value(t, f, pos_inf)
|
||||||
|
testing.expect_value(t, n, 4)
|
||||||
|
testing.expect_value(t, ok, true)
|
||||||
|
} else if i == 9 { // "+infinity"
|
||||||
|
testing.expect_value(t, f, pos_inf)
|
||||||
|
testing.expect_value(t, n, 9)
|
||||||
|
testing.expect_value(t, ok, true)
|
||||||
|
} else { // invalid substring
|
||||||
|
testing.expect_value(t, f, 0)
|
||||||
|
testing.expect_value(t, n, 0)
|
||||||
|
testing.expect_value(t, ok, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s = "-infinity"
|
||||||
|
for i in 1 ..< len(s) + 1 {
|
||||||
|
ss := s[:i]
|
||||||
|
f, ok := strconv.parse_f64(ss, &n)
|
||||||
|
if i == 4 { // "-inf"
|
||||||
|
testing.expect_value(t, f, neg_inf)
|
||||||
|
testing.expect_value(t, n, 4)
|
||||||
|
testing.expect_value(t, ok, true)
|
||||||
|
} else if i == 9 { // "-infinity"
|
||||||
|
testing.expect_value(t, f, neg_inf)
|
||||||
|
testing.expect_value(t, n, 9)
|
||||||
|
testing.expect_value(t, ok, true)
|
||||||
|
} else { // invalid substring
|
||||||
|
testing.expect_value(t, f, 0)
|
||||||
|
testing.expect_value(t, n, 0)
|
||||||
|
testing.expect_value(t, ok, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure odd casing works.
|
||||||
|
batch := [?]string {"INFiniTY", "iNfInItY", "InFiNiTy"}
|
||||||
|
for ss in batch {
|
||||||
|
f, ok := strconv.parse_f64(ss, &n)
|
||||||
|
testing.expect_value(t, f, pos_inf)
|
||||||
|
testing.expect_value(t, n, 8)
|
||||||
|
testing.expect_value(t, ok, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user