mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-21 05:45:19 +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 \
|
||||
runtime_test \
|
||||
slice_test \
|
||||
strconv_test \
|
||||
strings_test \
|
||||
thread_test \
|
||||
time_test
|
||||
@@ -98,6 +99,9 @@ runtime_test:
|
||||
slice_test:
|
||||
$(ODIN) test slice $(COMMON) -out:test_core_slice
|
||||
|
||||
strconv_test:
|
||||
$(ODIN) test strconv $(COMMON) -out:test_core_strconv
|
||||
|
||||
strings_test:
|
||||
$(ODIN) test strings $(COMMON) -out:test_core_strings
|
||||
|
||||
|
||||
@@ -103,6 +103,11 @@ echo Running core:slice tests
|
||||
echo ---
|
||||
%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 Running core:strings tests
|
||||
echo ---
|
||||
|
||||
79
tests/core/strconv/test_core_strconv.odin
Normal file
79
tests/core/strconv/test_core_strconv.odin
Normal file
@@ -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