mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
merge upstream/master
This commit is contained in:
@@ -4,6 +4,7 @@ package common
|
||||
import "core:testing"
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
import "core:strings"
|
||||
|
||||
TEST_count := 0
|
||||
TEST_fail := 0
|
||||
@@ -38,3 +39,37 @@ report :: proc(t: ^testing.T) {
|
||||
fmt.printf("%v/%v tests successful.\n", TEST_count, TEST_count)
|
||||
}
|
||||
}
|
||||
|
||||
// Returns absolute path to `sub_path` where `sub_path` is within the "tests/" sub-directory of the Odin project root
|
||||
// and we're being run from the Odin project root or from a sub-directory of "tests/"
|
||||
// e.g. get_data_path("assets/blah") will return "/Odin_root/tests/assets/blah" if run within "/Odin_root",
|
||||
// "/Odin_root/tests" or "/Odin_root/tests/subdir" etc
|
||||
get_data_path :: proc(t: ^testing.T, sub_path: string) -> (data_path: string) {
|
||||
|
||||
cwd := os.get_current_directory()
|
||||
defer delete(cwd)
|
||||
|
||||
when ODIN_OS == .Windows {
|
||||
norm, was_allocation := strings.replace_all(cwd, "\\", "/")
|
||||
if !was_allocation {
|
||||
norm = strings.clone(norm)
|
||||
}
|
||||
defer delete(norm)
|
||||
} else {
|
||||
norm := cwd
|
||||
}
|
||||
|
||||
last_index := strings.last_index(norm, "/tests/")
|
||||
if last_index == -1 {
|
||||
len := len(norm)
|
||||
if len >= 6 && norm[len-6:] == "/tests" {
|
||||
data_path = fmt.tprintf("%s/%s", norm, sub_path)
|
||||
} else {
|
||||
data_path = fmt.tprintf("%s/tests/%s", norm, sub_path)
|
||||
}
|
||||
} else {
|
||||
data_path = fmt.tprintf("%s/tests/%s", norm[:last_index], sub_path)
|
||||
}
|
||||
|
||||
return data_path
|
||||
}
|
||||
|
||||
+20
-7
@@ -2,39 +2,52 @@ ODIN=../../odin
|
||||
PYTHON=$(shell which python3)
|
||||
|
||||
all: download_test_assets image_test compress_test strings_test hash_test crypto_test noise_test encoding_test \
|
||||
<<<<<<< HEAD
|
||||
math_test linalg_glsl_math_test os2_test
|
||||
=======
|
||||
math_test linalg_glsl_math_test filepath_test reflect_test os_exit_test
|
||||
>>>>>>> upstream/master
|
||||
|
||||
download_test_assets:
|
||||
$(PYTHON) download_assets.py
|
||||
|
||||
image_test:
|
||||
$(ODIN) run image/test_core_image.odin
|
||||
$(ODIN) run image/test_core_image.odin -file
|
||||
|
||||
compress_test:
|
||||
$(ODIN) run compress/test_core_compress.odin
|
||||
$(ODIN) run compress/test_core_compress.odin -file
|
||||
|
||||
strings_test:
|
||||
$(ODIN) run strings/test_core_strings.odin
|
||||
$(ODIN) run strings/test_core_strings.odin -file
|
||||
|
||||
hash_test:
|
||||
$(ODIN) run hash -out=test_hash -o:speed -no-bounds-check
|
||||
|
||||
crypto_test:
|
||||
$(ODIN) run crypto -out=crypto_hash -o:speed -no-bounds-check
|
||||
$(ODIN) run crypto -out=test_crypto_hash -o:speed -no-bounds-check
|
||||
|
||||
noise_test:
|
||||
$(ODIN) run math/noise -out=test_noise
|
||||
|
||||
encoding_test:
|
||||
$(ODIN) run encoding/hxa -out=test_hxa -collection:tests=..
|
||||
$(ODIN) run encoding/json -out=test_json
|
||||
$(ODIN) run encoding/varint -out=test_varint
|
||||
|
||||
math_test:
|
||||
$(ODIN) run math/test_core_math.odin -out=test_core_math -collection:tests=..
|
||||
$(ODIN) run math/test_core_math.odin -out=test_core_math -file -collection:tests=..
|
||||
|
||||
linalg_glsl_math_test:
|
||||
$(ODIN) run math/linalg/glsl/test_linalg_glsl_math.odin -out=test_linalg_glsl_math -collection:tests=..
|
||||
$(ODIN) run math/linalg/glsl/test_linalg_glsl_math.odin -file -out=test_linalg_glsl_math -collection:tests=..
|
||||
|
||||
filepath_test:
|
||||
$(ODIN) run path/filepath/test_core_filepath.odin -file -out=test_core_filepath -collection:tests=..
|
||||
|
||||
reflect_test:
|
||||
$(ODIN) run reflect/test_core_reflect.odin -file -out=test_core_reflect -collection:tests=..
|
||||
|
||||
os_exit_test:
|
||||
$(ODIN) run os/test_core_os_exit.odin -file -out=test_core_os_exit && exit 1 || exit 0
|
||||
|
||||
os2_test:
|
||||
$(ODIN) run os2/test_os2.odin -out=test_os2
|
||||
|
||||
|
||||
Binary file not shown.
+21
-1
@@ -1,5 +1,5 @@
|
||||
@echo off
|
||||
set COMMON=-show-timings -no-bounds-check -vet -strict-style
|
||||
set COMMON=-show-timings -no-bounds-check -vet -strict-style -collection:tests=..
|
||||
set PATH_TO_ODIN==..\..\odin
|
||||
python3 download_assets.py
|
||||
echo ---
|
||||
@@ -35,6 +35,7 @@ echo ---
|
||||
echo ---
|
||||
echo Running core:encoding tests
|
||||
echo ---
|
||||
%PATH_TO_ODIN% run encoding/hxa %COMMON%
|
||||
%PATH_TO_ODIN% run encoding/json %COMMON%
|
||||
%PATH_TO_ODIN% run encoding/varint %COMMON%
|
||||
|
||||
@@ -44,6 +45,25 @@ echo ---
|
||||
%PATH_TO_ODIN% run math/noise %COMMON%
|
||||
|
||||
echo ---
|
||||
echo Running core:math tests
|
||||
echo ---
|
||||
%PATH_TO_ODIN% run math %COMMON%
|
||||
|
||||
echo ---
|
||||
echo Running core:math/linalg/glsl tests
|
||||
echo ---
|
||||
%PATH_TO_ODIN% run math/linalg/glsl %COMMON%
|
||||
|
||||
echo ---
|
||||
echo Running core:path/filepath tests
|
||||
echo ---
|
||||
%PATH_TO_ODIN% run path/filepath %COMMON%
|
||||
|
||||
echo ---
|
||||
echo Running core:reflect tests
|
||||
echo ---
|
||||
%PATH_TO_ODIN% run reflect %COMMON%
|
||||
|
||||
echo Running core:os/os2 tests
|
||||
echo ---
|
||||
Rem Needed Shlwapi.lib for PathFileExistsW
|
||||
|
||||
@@ -0,0 +1,232 @@
|
||||
// Tests "core:encoding:hxa".
|
||||
// Must be run with `-collection:tests=` flag, e.g.
|
||||
// ./odin run tests/core/encoding/hxa/test_core_hxa.odin -out=tests/core/test_core_hxa -collection:tests=./tests
|
||||
package test_core_hxa
|
||||
|
||||
import "core:encoding/hxa"
|
||||
import "core:fmt"
|
||||
import "core:testing"
|
||||
import tc "tests:common"
|
||||
|
||||
TEAPOT_PATH :: "core/assets/HXA/teapot.hxa"
|
||||
|
||||
main :: proc() {
|
||||
t := testing.T{}
|
||||
|
||||
test_read(&t)
|
||||
test_write(&t)
|
||||
|
||||
tc.report(&t)
|
||||
}
|
||||
|
||||
@test
|
||||
test_read :: proc(t: ^testing.T) {
|
||||
|
||||
using hxa
|
||||
|
||||
filename := tc.get_data_path(t, TEAPOT_PATH)
|
||||
defer delete(filename)
|
||||
|
||||
file, err := read_from_file(filename)
|
||||
e :: hxa.Read_Error.None
|
||||
tc.expect(t, err == e, fmt.tprintf("%v: read_from_file(%v) -> %v != %v", #procedure, filename, err, e))
|
||||
defer file_destroy(file)
|
||||
|
||||
/* Header */
|
||||
tc.expect(t, file.magic_number == 0x417848, fmt.tprintf("%v: file.magic_number %v != %v",
|
||||
#procedure, file.magic_number, 0x417848))
|
||||
tc.expect(t, file.version == 1, fmt.tprintf("%v: file.version %v != %v",
|
||||
#procedure, file.version, 1))
|
||||
tc.expect(t, file.internal_node_count == 1, fmt.tprintf("%v: file.internal_node_count %v != %v",
|
||||
#procedure, file.internal_node_count, 1))
|
||||
|
||||
/* Nodes (only one) */
|
||||
tc.expect(t, len(file.nodes) == 1, fmt.tprintf("%v: len(file.nodes) %v != %v", #procedure, len(file.nodes), 1))
|
||||
|
||||
m := &file.nodes[0].meta_data
|
||||
tc.expect(t, len(m^) == 38, fmt.tprintf("%v: len(m^) %v != %v", #procedure, len(m^), 38))
|
||||
{
|
||||
e :: "Texture resolution"
|
||||
tc.expect(t, m[0].name == e, fmt.tprintf("%v: m[0].name %v != %v", #procedure, m[0].name, e))
|
||||
|
||||
m_v, m_v_ok := m[0].value.([]i64le)
|
||||
tc.expect(t, m_v_ok, fmt.tprintf("%v: m_v_ok %v != %v", #procedure, m_v_ok, true))
|
||||
tc.expect(t, len(m_v) == 1, fmt.tprintf("%v: len(m_v) %v != %v", #procedure, len(m_v), 1))
|
||||
tc.expect(t, m_v[0] == 1024, fmt.tprintf("%v: m_v[0] %v != %v", #procedure, len(m_v), 1024))
|
||||
}
|
||||
{
|
||||
e :: "Validate"
|
||||
tc.expect(t, m[37].name == e, fmt.tprintf("%v: m[37].name %v != %v", #procedure, m[37].name, e))
|
||||
|
||||
m_v, m_v_ok := m[37].value.([]i64le)
|
||||
tc.expect(t, m_v_ok, fmt.tprintf("%v: m_v_ok %v != %v", #procedure, m_v_ok, true))
|
||||
tc.expect(t, len(m_v) == 1, fmt.tprintf("%v: len(m_v) %v != %v", #procedure, len(m_v), 1))
|
||||
tc.expect(t, m_v[0] == -2054847231, fmt.tprintf("%v: m_v[0] %v != %v", #procedure, len(m_v), -2054847231))
|
||||
}
|
||||
|
||||
/* Node content */
|
||||
v, v_ok := file.nodes[0].content.(hxa.Node_Geometry)
|
||||
tc.expect(t, v_ok, fmt.tprintf("%v: v_ok %v != %v", #procedure, v_ok, true))
|
||||
|
||||
tc.expect(t, v.vertex_count == 530, fmt.tprintf("%v: v.vertex_count %v != %v", #procedure, v.vertex_count, 530))
|
||||
tc.expect(t, v.edge_corner_count == 2026, fmt.tprintf("%v: v.edge_corner_count %v != %v",
|
||||
#procedure, v.edge_corner_count, 2026))
|
||||
tc.expect(t, v.face_count == 517, fmt.tprintf("%v: v.face_count %v != %v", #procedure, v.face_count, 517))
|
||||
|
||||
/* Vertex stack */
|
||||
tc.expect(t, len(v.vertex_stack) == 1, fmt.tprintf("%v: len(v.vertex_stack) %v != %v",
|
||||
#procedure, len(v.vertex_stack), 1))
|
||||
{
|
||||
e := "vertex"
|
||||
tc.expect(t, v.vertex_stack[0].name == e, fmt.tprintf("%v: v.vertex_stack[0].name %v != %v",
|
||||
#procedure, v.vertex_stack[0].name, e))
|
||||
}
|
||||
tc.expect(t, v.vertex_stack[0].components == 3, fmt.tprintf("%v: v.vertex_stack[0].components %v != %v",
|
||||
#procedure, v.vertex_stack[0].components, 3))
|
||||
|
||||
/* Vertex stack data */
|
||||
vs_d, vs_d_ok := v.vertex_stack[0].data.([]f64le)
|
||||
tc.expect(t, vs_d_ok, fmt.tprintf("%v: vs_d_ok %v != %v", #procedure, vs_d_ok, true))
|
||||
tc.expect(t, len(vs_d) == 1590, fmt.tprintf("%v: len(vs_d) %v != %v", #procedure, len(vs_d), 1590))
|
||||
|
||||
tc.expect(t, vs_d[0] == 4.06266, fmt.tprintf("%v: vs_d[0] %v (%h) != %v (%h)",
|
||||
#procedure, vs_d[0], vs_d[0], 4.06266, 4.06266))
|
||||
tc.expect(t, vs_d[1] == 2.83457, fmt.tprintf("%v: vs_d[1] %v (%h) != %v (%h)",
|
||||
#procedure, vs_d[1], vs_d[1], 2.83457, 2.83457))
|
||||
tc.expect(t, vs_d[2] == 0hbfbc5da6a4441787, fmt.tprintf("%v: vs_d[2] %v (%h) != %v (%h)",
|
||||
#procedure, vs_d[2], vs_d[2],
|
||||
0hbfbc5da6a4441787, 0hbfbc5da6a4441787))
|
||||
tc.expect(t, vs_d[3] == 0h4010074fb549f948, fmt.tprintf("%v: vs_d[3] %v (%h) != %v (%h)",
|
||||
#procedure, vs_d[3], vs_d[3],
|
||||
0h4010074fb549f948, 0h4010074fb549f948))
|
||||
tc.expect(t, vs_d[1587] == 0h400befa82e87d2c7, fmt.tprintf("%v: vs_d[1587] %v (%h) != %v (%h)",
|
||||
#procedure, vs_d[1587], vs_d[1587],
|
||||
0h400befa82e87d2c7, 0h400befa82e87d2c7))
|
||||
tc.expect(t, vs_d[1588] == 2.83457, fmt.tprintf("%v: vs_d[1588] %v (%h) != %v (%h)",
|
||||
#procedure, vs_d[1588], vs_d[1588], 2.83457, 2.83457))
|
||||
tc.expect(t, vs_d[1589] == -1.56121, fmt.tprintf("%v: vs_d[1589] %v (%h) != %v (%h)",
|
||||
#procedure, vs_d[1589], vs_d[1589], -1.56121, -1.56121))
|
||||
|
||||
/* Corner stack */
|
||||
tc.expect(t, len(v.corner_stack) == 1,
|
||||
fmt.tprintf("%v: len(v.corner_stack) %v != %v", #procedure, len(v.corner_stack), 1))
|
||||
{
|
||||
e := "reference"
|
||||
tc.expect(t, v.corner_stack[0].name == e, fmt.tprintf("%v: v.corner_stack[0].name %v != %v",
|
||||
#procedure, v.corner_stack[0].name, e))
|
||||
}
|
||||
tc.expect(t, v.corner_stack[0].components == 1, fmt.tprintf("%v: v.corner_stack[0].components %v != %v",
|
||||
#procedure, v.corner_stack[0].components, 1))
|
||||
|
||||
/* Corner stack data */
|
||||
cs_d, cs_d_ok := v.corner_stack[0].data.([]i32le)
|
||||
tc.expect(t, cs_d_ok, fmt.tprintf("%v: cs_d_ok %v != %v", #procedure, cs_d_ok, true))
|
||||
tc.expect(t, len(cs_d) == 2026, fmt.tprintf("%v: len(cs_d) %v != %v", #procedure, len(cs_d), 2026))
|
||||
tc.expect(t, cs_d[0] == 6, fmt.tprintf("%v: cs_d[0] %v != %v", #procedure, cs_d[0], 6))
|
||||
tc.expect(t, cs_d[2025] == -32, fmt.tprintf("%v: cs_d[2025] %v != %v", #procedure, cs_d[2025], -32))
|
||||
|
||||
/* Edge and face stacks (empty) */
|
||||
tc.expect(t, len(v.edge_stack) == 0, fmt.tprintf("%v: len(v.edge_stack) %v != %v",
|
||||
#procedure, len(v.edge_stack), 0))
|
||||
tc.expect(t, len(v.face_stack) == 0, fmt.tprintf("%v: len(v.face_stack) %v != %v",
|
||||
#procedure, len(v.face_stack), 0))
|
||||
}
|
||||
|
||||
@test
|
||||
test_write :: proc(t: ^testing.T) {
|
||||
|
||||
using hxa
|
||||
|
||||
n1 :Node
|
||||
|
||||
n1_m1_value := []f64le{0.4, -1.23, 2341.6, -333.333}
|
||||
n1_m1 := Meta{"m1", n1_m1_value}
|
||||
|
||||
n1.meta_data = []Meta{n1_m1}
|
||||
|
||||
n1_l1 := Layer{"l1", 2, []f32le{32.1, -41.3}}
|
||||
n1_l2 := Layer{"l2", 3, []f64le{0.64, 1.64, -2.64}}
|
||||
|
||||
n1_content := Node_Image{Image_Type.Image_1D, [3]u32le{1, 1, 2}, Layer_Stack{n1_l1, n1_l2}}
|
||||
|
||||
n1.content = n1_content
|
||||
|
||||
w_file :File
|
||||
w_file.nodes = []Node{n1}
|
||||
|
||||
required_size := required_write_size(w_file)
|
||||
buf := make([]u8, required_size)
|
||||
|
||||
n, write_err := write(buf, w_file)
|
||||
write_e :: hxa.Write_Error.None
|
||||
tc.expect(t, write_err == write_e, fmt.tprintf("%v: write_err %v != %v", #procedure, write_err, write_e))
|
||||
tc.expect(t, n == required_size, fmt.tprintf("%v: n %v != %v", #procedure, n, required_size))
|
||||
|
||||
file, read_err := read(buf)
|
||||
read_e :: hxa.Read_Error.None
|
||||
tc.expect(t, read_err == read_e, fmt.tprintf("%v: read_err %v != %v", #procedure, read_err, read_e))
|
||||
defer file_destroy(file)
|
||||
|
||||
delete(buf)
|
||||
|
||||
tc.expect(t, file.magic_number == 0x417848, fmt.tprintf("%v: file.magic_number %v != %v",
|
||||
#procedure, file.magic_number, 0x417848))
|
||||
tc.expect(t, file.version == 3, fmt.tprintf("%v: file.version %v != %v", #procedure, file.version, 3))
|
||||
tc.expect(t, file.internal_node_count == 1, fmt.tprintf("%v: file.internal_node_count %v != %v",
|
||||
#procedure, file.internal_node_count, 1))
|
||||
|
||||
tc.expect(t, len(file.nodes) == len(w_file.nodes), fmt.tprintf("%v: len(file.nodes) %v != %v",
|
||||
#procedure, len(file.nodes), len(w_file.nodes)))
|
||||
|
||||
m := &file.nodes[0].meta_data
|
||||
w_m := &w_file.nodes[0].meta_data
|
||||
tc.expect(t, len(m^) == len(w_m^), fmt.tprintf("%v: len(m^) %v != %v", #procedure, len(m^), len(w_m^)))
|
||||
tc.expect(t, m[0].name == w_m[0].name, fmt.tprintf("%v: m[0].name %v != %v", #procedure, m[0].name, w_m[0].name))
|
||||
|
||||
m_v, m_v_ok := m[0].value.([]f64le)
|
||||
tc.expect(t, m_v_ok, fmt.tprintf("%v: m_v_ok %v != %v", #procedure, m_v_ok, true))
|
||||
tc.expect(t, len(m_v) == len(n1_m1_value), fmt.tprintf("%v: %v != len(m_v) %v",
|
||||
#procedure, len(m_v), len(n1_m1_value)))
|
||||
for i := 0; i < len(m_v); i += 1 {
|
||||
tc.expect(t, m_v[i] == n1_m1_value[i], fmt.tprintf("%v: m_v[%d] %v != %v",
|
||||
#procedure, i, m_v[i], n1_m1_value[i]))
|
||||
}
|
||||
|
||||
v, v_ok := file.nodes[0].content.(hxa.Node_Image)
|
||||
tc.expect(t, v_ok, fmt.tprintf("%v: v_ok %v != %v", #procedure, v_ok, true))
|
||||
tc.expect(t, v.type == n1_content.type, fmt.tprintf("%v: v.type %v != %v", #procedure, v.type, n1_content.type))
|
||||
tc.expect(t, len(v.resolution) == 3, fmt.tprintf("%v: len(v.resolution) %v != %v",
|
||||
#procedure, len(v.resolution), 3))
|
||||
tc.expect(t, len(v.image_stack) == len(n1_content.image_stack), fmt.tprintf("%v: len(v.image_stack) %v != %v",
|
||||
#procedure, len(v.image_stack), len(n1_content.image_stack)))
|
||||
for i := 0; i < len(v.image_stack); i += 1 {
|
||||
tc.expect(t, v.image_stack[i].name == n1_content.image_stack[i].name,
|
||||
fmt.tprintf("%v: v.image_stack[%d].name %v != %v",
|
||||
#procedure, i, v.image_stack[i].name, n1_content.image_stack[i].name))
|
||||
tc.expect(t, v.image_stack[i].components == n1_content.image_stack[i].components,
|
||||
fmt.tprintf("%v: v.image_stack[%d].components %v != %v",
|
||||
#procedure, i, v.image_stack[i].components, n1_content.image_stack[i].components))
|
||||
|
||||
switch n1_t in n1_content.image_stack[i].data {
|
||||
case []u8:
|
||||
tc.expect(t, false, fmt.tprintf("%v: n1_content.image_stack[i].data []u8", #procedure))
|
||||
case []i32le:
|
||||
tc.expect(t, false, fmt.tprintf("%v: n1_content.image_stack[i].data []i32le", #procedure))
|
||||
case []f32le:
|
||||
l, l_ok := v.image_stack[i].data.([]f32le)
|
||||
tc.expect(t, l_ok, fmt.tprintf("%v: l_ok %v != %v", #procedure, l_ok, true))
|
||||
tc.expect(t, len(l) == len(n1_t), fmt.tprintf("%v: len(l) %v != %v", #procedure, len(l), len(n1_t)))
|
||||
for j := 0; j < len(l); j += 1 {
|
||||
tc.expect(t, l[j] == n1_t[j], fmt.tprintf("%v: l[%d] %v (%h) != %v (%h)",
|
||||
#procedure, j, l[j], l[j], n1_t[j], n1_t[j]))
|
||||
}
|
||||
case []f64le:
|
||||
l, l_ok := v.image_stack[i].data.([]f64le)
|
||||
tc.expect(t, l_ok, fmt.tprintf("%v: l_ok %v != %v", #procedure, l_ok, true))
|
||||
tc.expect(t, len(l) == len(n1_t), fmt.tprintf("%v: len(l) %v != %v", #procedure, len(l), len(n1_t)))
|
||||
for j := 0; j < len(l); j += 1 {
|
||||
tc.expect(t, l[j] == n1_t[j], fmt.tprintf("%v: l[%d] %v != %v", #procedure, j, l[j], n1_t[j]))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,5 +88,5 @@ marshal_json :: proc(t: ^testing.T) {
|
||||
|
||||
_, err := json.marshal(my_struct)
|
||||
|
||||
expect(t, err == .None, "expected json error to be none")
|
||||
expect(t, err == nil, "expected json error to be none")
|
||||
}
|
||||
|
||||
@@ -10,8 +10,5 @@ echo ---
|
||||
echo Running core:math/big tests
|
||||
echo ---
|
||||
|
||||
rem Fails
|
||||
:%PATH_TO_ODIN% build . %COMMON% -o:speed -out:%OUT_NAME%
|
||||
rem Passes
|
||||
%PATH_TO_ODIN% build . %COMMON% -o:size -out:%OUT_NAME%
|
||||
%PATH_TO_ODIN% build . %COMMON% -o:speed -out:%OUT_NAME%
|
||||
python3 test.py %TEST_ARGS%
|
||||
@@ -32,9 +32,9 @@ print_to_buffer :: proc(val: ^big.Int) -> cstring {
|
||||
|
||||
@export test_initialize_constants :: proc "c" () -> (res: u64) {
|
||||
context = runtime.default_context()
|
||||
res = u64(big.initialize_constants())
|
||||
//assert(MUL_KARATSUBA_CUTOFF >= 40);
|
||||
return res
|
||||
_ = big.initialize_constants()
|
||||
|
||||
return u64(big._DIGIT_NAILS)
|
||||
}
|
||||
|
||||
@export test_error_string :: proc "c" (err: big.Error) -> (res: cstring) {
|
||||
|
||||
@@ -17,7 +17,6 @@ import gc
|
||||
from enum import Enum
|
||||
import argparse
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description = "Odin core:math/big test suite",
|
||||
epilog = "By default we run regression and random tests with preset parameters.",
|
||||
@@ -163,6 +162,8 @@ def load(export_name, args, res):
|
||||
export_name.restype = res
|
||||
return export_name
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Result values will be passed in a struct { res: cstring, err: Error }
|
||||
#
|
||||
@@ -170,7 +171,11 @@ class Res(Structure):
|
||||
_fields_ = [("res", c_char_p), ("err", c_uint64)]
|
||||
|
||||
initialize_constants = load(l.test_initialize_constants, [], c_uint64)
|
||||
print("initialize_constants: ", initialize_constants())
|
||||
|
||||
NAILS = initialize_constants()
|
||||
LEG_BITS = 64 - NAILS
|
||||
|
||||
print("LEG BITS: ", LEG_BITS)
|
||||
|
||||
error_string = load(l.test_error_string, [c_byte], c_char_p)
|
||||
|
||||
@@ -407,7 +412,7 @@ def test_shl_leg(a = 0, digits = 0, expected_error = Error.Okay):
|
||||
res = int_shl_leg(*args)
|
||||
expected_result = None
|
||||
if expected_error == Error.Okay:
|
||||
expected_result = a << (digits * 60)
|
||||
expected_result = a << (digits * LEG_BITS)
|
||||
return test("test_shl_leg", res, [a, digits], expected_error, expected_result)
|
||||
|
||||
def test_shr_leg(a = 0, digits = 0, expected_error = Error.Okay):
|
||||
@@ -419,7 +424,7 @@ def test_shr_leg(a = 0, digits = 0, expected_error = Error.Okay):
|
||||
# Don't pass negative numbers. We have a shr_signed.
|
||||
return False
|
||||
else:
|
||||
expected_result = a >> (digits * 60)
|
||||
expected_result = a >> (digits * LEG_BITS)
|
||||
|
||||
return test("test_shr_leg", res, [a, digits], expected_error, expected_result)
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// Tests that Odin run returns exit code of built executable on Unix
|
||||
// Needs exit status to be inverted to return 0 on success, e.g.
|
||||
// $(./odin run tests/core/os/test_core_os_exit.odin && exit 1 || exit 0)
|
||||
package test_core_os_exit
|
||||
|
||||
import "core:os"
|
||||
|
||||
main :: proc() {
|
||||
os.exit(1)
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
// Tests "path.odin" in "core:path/filepath".
|
||||
// Must be run with `-collection:tests=` flag, e.g.
|
||||
// ./odin run tests/core/path/filepath/test_core_filepath.odin -collection:tests=tests
|
||||
package test_core_filepath
|
||||
|
||||
import "core:fmt"
|
||||
import "core:path/filepath"
|
||||
import "core:testing"
|
||||
import tc "tests:common"
|
||||
|
||||
main :: proc() {
|
||||
t := testing.T{}
|
||||
|
||||
when ODIN_OS == .Windows {
|
||||
test_split_list_windows(&t)
|
||||
} else {
|
||||
test_split_list_unix(&t)
|
||||
}
|
||||
|
||||
tc.report(&t)
|
||||
}
|
||||
|
||||
@test
|
||||
test_split_list_windows :: proc(t: ^testing.T) {
|
||||
|
||||
using filepath
|
||||
|
||||
Datum :: struct {
|
||||
i: int,
|
||||
v: string,
|
||||
e: [3]string,
|
||||
}
|
||||
@static data := []Datum{
|
||||
{ 0, "C:\\Odin;C:\\Visual Studio;\"C:\\Some Other\"",
|
||||
[3]string{"C:\\Odin", "C:\\Visual Studio", "C:\\Some Other"} }, // Issue #1537
|
||||
{ 1, "a;;b", [3]string{"a", "", "b"} },
|
||||
{ 2, "a;b;", [3]string{"a", "b", ""} },
|
||||
{ 3, ";a;b", [3]string{"", "a", "b"} },
|
||||
{ 4, ";;", [3]string{"", "", ""} },
|
||||
{ 5, "\"a;b\"c;d;\"f\"", [3]string{"a;bc", "d", "f"} },
|
||||
{ 6, "\"a;b;c\";d\";e\";f", [3]string{"a;b;c", "d;e", "f"} },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i, fmt.tprintf("wrong data index: i %d != d.i %d\n", i, d.i))
|
||||
r := split_list(d.v)
|
||||
defer delete(r)
|
||||
tc.expect(t, len(r) == len(d.e), fmt.tprintf("i:%d %s(%s) len(r) %d != len(d.e) %d",
|
||||
i, #procedure, d.v, len(r), len(d.e)))
|
||||
if len(r) == len(d.e) {
|
||||
for _, j in r {
|
||||
tc.expect(t, r[j] == d.e[j], fmt.tprintf("i:%d %s(%v) -> %v[%d] != %v",
|
||||
i, #procedure, d.v, r[j], j, d.e[j]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
v := ""
|
||||
r := split_list(v)
|
||||
tc.expect(t, r == nil, fmt.tprintf("%s(%s) -> %v != nil", #procedure, v, r))
|
||||
}
|
||||
{
|
||||
v := "a"
|
||||
r := split_list(v)
|
||||
defer delete(r)
|
||||
tc.expect(t, len(r) == 1, fmt.tprintf("%s(%s) len(r) %d != 1", #procedure, v, len(r)))
|
||||
if len(r) == 1 {
|
||||
tc.expect(t, r[0] == "a", fmt.tprintf("%s(%v) -> %v[0] != a", #procedure, v, r[0]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
test_split_list_unix :: proc(t: ^testing.T) {
|
||||
|
||||
using filepath
|
||||
|
||||
Datum :: struct {
|
||||
i: int,
|
||||
v: string,
|
||||
e: [3]string,
|
||||
}
|
||||
@static data := []Datum{
|
||||
{ 0, "/opt/butler:/home/fancykillerpanda/Projects/Odin/Odin:/usr/local/sbin",
|
||||
[3]string{"/opt/butler", "/home/fancykillerpanda/Projects/Odin/Odin", "/usr/local/sbin"} }, // Issue #1537
|
||||
{ 1, "a::b", [3]string{"a", "", "b"} },
|
||||
{ 2, "a:b:", [3]string{"a", "b", ""} },
|
||||
{ 3, ":a:b", [3]string{"", "a", "b"} },
|
||||
{ 4, "::", [3]string{"", "", ""} },
|
||||
{ 5, "\"a:b\"c:d:\"f\"", [3]string{"a:bc", "d", "f"} },
|
||||
{ 6, "\"a:b:c\":d\":e\":f", [3]string{"a:b:c", "d:e", "f"} },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i, fmt.tprintf("wrong data index: i %d != d.i %d\n", i, d.i))
|
||||
r := split_list(d.v)
|
||||
defer delete(r)
|
||||
tc.expect(t, len(r) == len(d.e), fmt.tprintf("i:%d %s(%s) len(r) %d != len(d.e) %d",
|
||||
i, #procedure, d.v, len(r), len(d.e)))
|
||||
if len(r) == len(d.e) {
|
||||
for _, j in r {
|
||||
tc.expect(t, r[j] == d.e[j], fmt.tprintf("i:%d %s(%v) -> %v[%d] != %v",
|
||||
i, #procedure, d.v, r[j], j, d.e[j]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
v := ""
|
||||
r := split_list(v)
|
||||
tc.expect(t, r == nil, fmt.tprintf("%s(%s) -> %v != nil", #procedure, v, r))
|
||||
}
|
||||
{
|
||||
v := "a"
|
||||
r := split_list(v)
|
||||
defer delete(r)
|
||||
tc.expect(t, len(r) == 1, fmt.tprintf("%s(%s) len(r) %d != 1", #procedure, v, len(r)))
|
||||
if len(r) == 1 {
|
||||
tc.expect(t, r[0] == "a", fmt.tprintf("%s(%v) -> %v[0] != a", #procedure, v, r[0]))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
// Tests "core:reflect/reflect".
|
||||
// Must be run with `-collection:tests=` flag, e.g.
|
||||
// ./odin run tests/core/reflect/test_core_reflect.odin -out=tests/core/test_core_reflect -collection:tests=./tests
|
||||
package test_core_reflect
|
||||
|
||||
import "core:fmt"
|
||||
import "core:reflect"
|
||||
import "core:testing"
|
||||
import tc "tests:common"
|
||||
|
||||
main :: proc() {
|
||||
t := testing.T{}
|
||||
|
||||
test_as_u64(&t)
|
||||
test_as_f64(&t)
|
||||
|
||||
tc.report(&t)
|
||||
}
|
||||
|
||||
@test
|
||||
test_as_u64 :: proc(t: ^testing.T) {
|
||||
using reflect
|
||||
|
||||
{
|
||||
/* i8 */
|
||||
Datum :: struct { i: int, v: i8, e: u64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 0x7F, 0x7F },
|
||||
{ 1, -1, 0xFFFF_FFFF_FFFF_FFFF },
|
||||
{ 2, -0x80, 0xFFFF_FFFF_FFFF_FF80 },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_u64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(i8 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(i8 %v) -> %v (0x%X) != %v (0x%X)\n",
|
||||
i, #procedure, d.v, r, r, d.e, d.e))
|
||||
}
|
||||
}
|
||||
{
|
||||
/* i16 */
|
||||
Datum :: struct { i: int, v: i16, e: u64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 0x7FFF, 0x7FFF },
|
||||
{ 1, -1, 0xFFFF_FFFF_FFFF_FFFF },
|
||||
{ 2, -0x8000, 0xFFFF_FFFF_FFFF_8000 },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_u64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(i16 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(i16 %v) -> %v (0x%X) != %v (0x%X)\n",
|
||||
i, #procedure, d.v, r, r, d.e, d.e))
|
||||
}
|
||||
}
|
||||
{
|
||||
/* i32 */
|
||||
Datum :: struct { i: int, v: i32, e: u64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 0x7FFF_FFFF, 0x7FFF_FFFF },
|
||||
{ 1, -1, 0xFFFF_FFFF_FFFF_FFFF },
|
||||
{ 2, -0x8000_0000, 0xFFFF_FFFF_8000_0000 },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_u64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(i32 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(i32 %v) -> %v (0x%X) != %v (0x%X)\n",
|
||||
i, #procedure, d.v, r, r, d.e, d.e))
|
||||
}
|
||||
}
|
||||
{
|
||||
/* i64 */
|
||||
Datum :: struct { i: int, v: i64, e: u64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 0x7FFF_FFFF_FFFF_FFFF, 0x7FFF_FFFF_FFFF_FFFF },
|
||||
{ 1, -1, 0xFFFF_FFFF_FFFF_FFFF },
|
||||
{ 2, -0x8000_0000_0000_0000, 0x8000_0000_0000_0000 },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_u64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(i64 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(i64 %v) -> %v (0x%X) != %v (0x%X)\n",
|
||||
i, #procedure, d.v, r, r, d.e, d.e))
|
||||
}
|
||||
}
|
||||
{
|
||||
/* i128 */
|
||||
Datum :: struct { i: int, v: i128, e: u64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 0x7FFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF },
|
||||
{ 1, -1, 0xFFFF_FFFF_FFFF_FFFF },
|
||||
{ 2, 0x8000_0000_0000_0000, 0x8000_0000_0000_0000 },
|
||||
{ 3, -0x8000_0000_0000_0000, 0x8000_0000_0000_0000 },
|
||||
{ 4, 0x0001_0000_0000_0000_0000, 0 },
|
||||
{ 5, -0x8000_0000_0000_0000_0000_0000_0000_0000, 0 },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_u64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(i128 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(i128 %v) -> %v (0x%X) != %v (0x%X)\n",
|
||||
i, #procedure, d.v, r, r, d.e, d.e))
|
||||
}
|
||||
}
|
||||
{
|
||||
/* f16 */
|
||||
Datum :: struct { i: int, v: f16, e: u64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 1.2, 1 },
|
||||
{ 1, 123.12, 123 },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_u64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(f16 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(f16 %v) -> %v != %v\n", i, #procedure, d.v, r, d.e))
|
||||
}
|
||||
}
|
||||
{
|
||||
/* f32 */
|
||||
Datum :: struct { i: int, v: f32, e: u64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 123.3415, 123 },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_u64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(f32 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(f32 %v) -> %v != %v\n", i, #procedure, d.v, r, d.e))
|
||||
}
|
||||
}
|
||||
{
|
||||
/* f64 */
|
||||
Datum :: struct { i: int, v: f64, e: u64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 12345345345.3415234234, 12345345345 },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_u64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(f64 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(f64 %v) -> %v != %v\n", i, #procedure, d.v, r, d.e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
test_as_f64 :: proc(t: ^testing.T) {
|
||||
using reflect
|
||||
|
||||
{
|
||||
/* i8 */
|
||||
Datum :: struct { i: int, v: i8, e: f64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 0x7F, 0x7F },
|
||||
{ 1, -1, -1 },
|
||||
{ 2, -0x80, -0x80 },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_f64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(i8 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(i8 %v) -> %v != %v\n", i, #procedure, d.v, r, d.e))
|
||||
}
|
||||
}
|
||||
{
|
||||
/* i16 */
|
||||
Datum :: struct { i: int, v: i16, e: f64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 0x7FFF, 0x7FFF },
|
||||
{ 1, -1, -1 },
|
||||
{ 2, -0x8000, -0x8000 },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_f64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(i16 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(i16 %v) -> %v != %v\n", i, #procedure, d.v, r, d.e))
|
||||
}
|
||||
}
|
||||
{
|
||||
/* i32 */
|
||||
Datum :: struct { i: int, v: i32, e: f64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 0x7FFF_FFFF, 0x7FFF_FFFF },
|
||||
{ 1, -1, -1 },
|
||||
{ 2, -0x8000_0000, -0x8000_0000 },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_f64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(i32 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(i32 %v) -> %v != %v\n", i, #procedure, d.v, r, d.e))
|
||||
}
|
||||
}
|
||||
{
|
||||
/* i64 */
|
||||
Datum :: struct { i: int, v: i64, e: f64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 0x7FFF_FFFF_FFFF_FFFF, 0x7FFF_FFFF_FFFF_FFFF },
|
||||
{ 1, -1, -1 },
|
||||
{ 2, -0x8000_0000_0000_0000, -0x8000_0000_0000_0000 },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_f64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(i64 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(i64 %v) -> %v != %v\n", i, #procedure, d.v, r, d.e))
|
||||
}
|
||||
}
|
||||
{
|
||||
/* i128 */
|
||||
Datum :: struct { i: int, v: i128, e: f64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 0x7FFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF, 0x7FFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF },
|
||||
{ 1, -1, -1 },
|
||||
{ 2, 0x8000_0000_0000_0000_0000_0000_0000, 0x8000_0000_0000_0000_0000_0000_0000 },
|
||||
{ 3, -0x8000_0000_0000_0000_0000_0000_0000_0000, -0x8000_0000_0000_0000_0000_0000_0000_0000 },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_f64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(i128 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(i128 %v) -> %v (%H) != %v (%H)\n",
|
||||
i, #procedure, d.v, r, r, d.e, d.e))
|
||||
}
|
||||
}
|
||||
{
|
||||
/* f16 */
|
||||
Datum :: struct { i: int, v: f16, e: f64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 1.2, 0h3FF3_3400_0000_0000 }, // Precision difference TODO: check
|
||||
{ 1, 123.12, 0h405E_C800_0000_0000 }, // Precision difference TODO: check
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_f64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(f16 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(f16 %v (%H)) -> %v (%H) != %v (%H)\n",
|
||||
i, #procedure, d.v, d.v, r, r, d.e, d.e))
|
||||
}
|
||||
}
|
||||
{
|
||||
/* f32 */
|
||||
Datum :: struct { i: int, v: f32, e: f64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 123.3415, 0h405E_D5DB_2000_0000 }, // Precision difference TODO: check
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_f64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(f32 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(f32 %v (%H)) -> %v (%H) != %v (%H)\n",
|
||||
i, #procedure, d.v, d.v, r, r, d.e, d.e))
|
||||
}
|
||||
}
|
||||
{
|
||||
/* f64 */
|
||||
Datum :: struct { i: int, v: f64, e: f64 }
|
||||
@static data := []Datum{
|
||||
{ 0, 12345345345.3415234234, 12345345345.3415234234 },
|
||||
}
|
||||
|
||||
for d, i in data {
|
||||
assert(i == d.i)
|
||||
r, valid := as_f64(d.v)
|
||||
tc.expect(t, valid, fmt.tprintf("i:%d %s(f64 %v) !valid\n", i, #procedure, d.v))
|
||||
tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(f64 %v) -> %v != %v\n", i, #procedure, d.v, r, d.e))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package test_core_image
|
||||
package test_core_strings
|
||||
|
||||
import "core:strings"
|
||||
import "core:testing"
|
||||
@@ -32,6 +32,7 @@ main :: proc() {
|
||||
test_index_any_larger_string_not_found(&t)
|
||||
test_index_any_small_string_found(&t)
|
||||
test_index_any_larger_string_found(&t)
|
||||
test_cut(&t)
|
||||
|
||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
||||
if TEST_fail > 0 {
|
||||
@@ -42,7 +43,6 @@ main :: proc() {
|
||||
@test
|
||||
test_index_any_small_string_not_found :: proc(t: ^testing.T) {
|
||||
index := strings.index_any(".", "/:\"")
|
||||
log(t, index)
|
||||
expect(t, index == -1, "index_any should be negative")
|
||||
}
|
||||
|
||||
@@ -63,3 +63,30 @@ test_index_any_larger_string_found :: proc(t: ^testing.T) {
|
||||
index := strings.index_any("aaaaaaaa:aaaaaaaa", "/:\"")
|
||||
expect(t, index == 8, "index_any should be 8")
|
||||
}
|
||||
|
||||
Cut_Test :: struct {
|
||||
input: string,
|
||||
offset: int,
|
||||
length: int,
|
||||
output: string,
|
||||
}
|
||||
|
||||
cut_tests :: []Cut_Test{
|
||||
{"some example text", 0, 4, "some" },
|
||||
{"some example text", 2, 2, "me" },
|
||||
{"some example text", 5, 7, "example" },
|
||||
{"some example text", 5, 0, "example text"},
|
||||
{"恥ずべきフクロウ", 4, 0, "フクロウ" },
|
||||
}
|
||||
|
||||
@test
|
||||
test_cut :: proc(t: ^testing.T) {
|
||||
for test in cut_tests {
|
||||
res := strings.cut(test.input, test.offset, test.length)
|
||||
defer delete(res)
|
||||
|
||||
msg := fmt.tprintf("cut(\"%v\", %v, %v) expected to return \"%v\", got \"%v\"",
|
||||
test.input, test.offset, test.length, test.output, res)
|
||||
expect(t, res == test.output, msg)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
@echo off
|
||||
|
||||
if not exist "tests\issues\build\" mkdir tests\issues\build
|
||||
|
||||
set COMMON=-collection:tests=tests -out:tests\issues\build\test_issue
|
||||
|
||||
@echo on
|
||||
|
||||
.\odin build tests\issues\test_issue_829.odin %COMMON% -file
|
||||
tests\issues\build\test_issue
|
||||
|
||||
.\odin build tests\issues\test_issue_1592.odin %COMMON% -file
|
||||
tests\issues\build\test_issue
|
||||
|
||||
@echo off
|
||||
|
||||
rmdir /S /Q tests\issues\build
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
set -eu
|
||||
|
||||
mkdir -p tests/issues/build
|
||||
|
||||
COMMON="-collection:tests=tests -out:tests/issues/build/test_issue"
|
||||
|
||||
set -x
|
||||
|
||||
./odin build tests/issues/test_issue_829.odin $COMMON -file
|
||||
tests/issues/build/test_issue
|
||||
|
||||
./odin build tests/issues/test_issue_1592.odin $COMMON -file
|
||||
tests/issues/build/test_issue
|
||||
|
||||
set +x
|
||||
|
||||
rm -rf tests/issues/build
|
||||
@@ -0,0 +1,489 @@
|
||||
// Tests issue #1592 https://github.com/odin-lang/Odin/issues/1592
|
||||
package test_issues
|
||||
|
||||
import "core:fmt"
|
||||
import "core:testing"
|
||||
import tc "tests:common"
|
||||
|
||||
main :: proc() {
|
||||
t := testing.T{}
|
||||
|
||||
/* This won't short-circuit */
|
||||
test_orig()
|
||||
|
||||
/* These will short-circuit */
|
||||
test_simple_const_false(&t)
|
||||
test_simple_const_true(&t)
|
||||
|
||||
/* These won't short-circuit */
|
||||
test_simple_proc_false(&t)
|
||||
test_simple_proc_true(&t)
|
||||
|
||||
/* These won't short-circuit */
|
||||
test_const_false_const_false(&t)
|
||||
test_const_false_const_true(&t)
|
||||
test_const_true_const_false(&t)
|
||||
test_const_true_const_true(&t)
|
||||
|
||||
/* These won't short-circuit */
|
||||
test_proc_false_const_false(&t)
|
||||
test_proc_false_const_true(&t)
|
||||
test_proc_true_const_false(&t)
|
||||
test_proc_true_const_true(&t)
|
||||
|
||||
tc.report(&t)
|
||||
}
|
||||
|
||||
/* Original issue #1592 example */
|
||||
|
||||
// I get a LLVM code gen error when this constant is false, but it works when it is true
|
||||
CONSTANT_BOOL :: false
|
||||
|
||||
bool_result :: proc() -> bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@test
|
||||
test_orig :: proc() {
|
||||
if bool_result() || CONSTANT_BOOL {
|
||||
}
|
||||
}
|
||||
|
||||
CONSTANT_FALSE :: false
|
||||
CONSTANT_TRUE :: true
|
||||
|
||||
false_result :: proc() -> bool {
|
||||
return false
|
||||
}
|
||||
true_result :: proc() -> bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@test
|
||||
test_simple_const_false :: proc(t: ^testing.T) {
|
||||
if CONSTANT_FALSE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if (CONSTANT_FALSE) {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if !CONSTANT_FALSE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if (!CONSTANT_FALSE) {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if !(CONSTANT_FALSE) {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if !!CONSTANT_FALSE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if CONSTANT_FALSE == true {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if CONSTANT_FALSE == false {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if !(CONSTANT_FALSE == true) {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if !(CONSTANT_FALSE == false) {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
test_simple_const_true :: proc(t: ^testing.T) {
|
||||
if CONSTANT_TRUE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if (CONSTANT_TRUE) {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if !CONSTANT_TRUE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if (!CONSTANT_TRUE) {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if (!CONSTANT_TRUE) {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if !(CONSTANT_TRUE) {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if !!CONSTANT_TRUE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if CONSTANT_TRUE == true {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if CONSTANT_TRUE == false {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if !(CONSTANT_TRUE == true) {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if !(CONSTANT_TRUE == false) {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
test_simple_proc_false :: proc(t: ^testing.T) {
|
||||
if false_result() {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if !false_result() {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
test_simple_proc_true :: proc(t: ^testing.T) {
|
||||
if true_result() {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if !true_result() {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
test_const_false_const_false :: proc(t: ^testing.T) {
|
||||
if CONSTANT_FALSE || CONSTANT_FALSE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if CONSTANT_FALSE && CONSTANT_FALSE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
|
||||
if !CONSTANT_FALSE || CONSTANT_FALSE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if !CONSTANT_FALSE && CONSTANT_FALSE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
|
||||
if CONSTANT_FALSE || !CONSTANT_FALSE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if CONSTANT_FALSE && !CONSTANT_FALSE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
|
||||
if !(CONSTANT_FALSE || CONSTANT_FALSE) {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if !(CONSTANT_FALSE && CONSTANT_FALSE) {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
test_const_false_const_true :: proc(t: ^testing.T) {
|
||||
if CONSTANT_FALSE || CONSTANT_TRUE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if CONSTANT_FALSE && CONSTANT_TRUE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
|
||||
if !CONSTANT_FALSE || CONSTANT_TRUE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if !CONSTANT_FALSE && CONSTANT_TRUE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
|
||||
if CONSTANT_FALSE || !CONSTANT_TRUE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if CONSTANT_FALSE && !CONSTANT_TRUE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
|
||||
if !(CONSTANT_FALSE || CONSTANT_TRUE) {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if !(CONSTANT_FALSE && CONSTANT_TRUE) {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
test_const_true_const_false :: proc(t: ^testing.T) {
|
||||
if CONSTANT_TRUE || CONSTANT_FALSE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if CONSTANT_TRUE && CONSTANT_FALSE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
|
||||
if !CONSTANT_TRUE || CONSTANT_FALSE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if !CONSTANT_TRUE && CONSTANT_FALSE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
|
||||
if CONSTANT_TRUE || !CONSTANT_FALSE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if CONSTANT_TRUE && !CONSTANT_FALSE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
|
||||
if !(CONSTANT_TRUE || CONSTANT_FALSE) {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if !(CONSTANT_TRUE && CONSTANT_FALSE) {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
test_const_true_const_true :: proc(t: ^testing.T) {
|
||||
if CONSTANT_TRUE || CONSTANT_TRUE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if CONSTANT_TRUE && CONSTANT_TRUE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
|
||||
if !CONSTANT_TRUE || CONSTANT_TRUE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if !CONSTANT_TRUE && CONSTANT_TRUE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
|
||||
if CONSTANT_TRUE || !CONSTANT_TRUE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if CONSTANT_TRUE && !CONSTANT_TRUE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
|
||||
if !(CONSTANT_TRUE || CONSTANT_TRUE) {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if !(CONSTANT_TRUE && CONSTANT_TRUE) {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
test_proc_false_const_false :: proc(t: ^testing.T) {
|
||||
if false_result() || CONSTANT_FALSE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if false_result() && CONSTANT_FALSE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
|
||||
if !(false_result() || CONSTANT_FALSE) {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if !(false_result() && CONSTANT_FALSE) {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
test_proc_false_const_true :: proc(t: ^testing.T) {
|
||||
if false_result() || CONSTANT_TRUE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if false_result() && CONSTANT_TRUE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
|
||||
if !(false_result() || CONSTANT_TRUE) {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if !(false_result() && CONSTANT_TRUE) {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
test_proc_true_const_false :: proc(t: ^testing.T) {
|
||||
if true_result() || CONSTANT_FALSE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if true_result() && CONSTANT_FALSE {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
|
||||
if !(true_result() || CONSTANT_FALSE) {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if !(true_result() && CONSTANT_FALSE) {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
test_proc_true_const_true :: proc(t: ^testing.T) {
|
||||
if true_result() || CONSTANT_TRUE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
if true_result() && CONSTANT_TRUE {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
}
|
||||
|
||||
if !(true_result() || CONSTANT_TRUE) {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
if !(true_result() && CONSTANT_TRUE) {
|
||||
tc.expect(t, false, fmt.tprintf("%s: !false\n", #procedure))
|
||||
} else {
|
||||
tc.expect(t, true, fmt.tprintf("%s: !true\n", #procedure))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Tests issue #829 https://github.com/odin-lang/Odin/issues/829
|
||||
package test_issues
|
||||
|
||||
import "core:fmt"
|
||||
import "core:testing"
|
||||
import tc "tests:common"
|
||||
|
||||
/* Original issue #829 example */
|
||||
|
||||
env : map[string]proc(a, b : int) -> int = {
|
||||
"+" = proc(a, b : int) -> int {
|
||||
return a + b
|
||||
},
|
||||
}
|
||||
|
||||
test_orig :: proc() {
|
||||
fmt.println(env["+"](1, 2))
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
t := testing.T{}
|
||||
|
||||
test_orig()
|
||||
|
||||
test_orig_ret(&t)
|
||||
|
||||
tc.report(&t)
|
||||
}
|
||||
|
||||
test_orig_ret :: proc(t: ^testing.T) {
|
||||
r := fmt.tprint(env["+"](1, 2))
|
||||
tc.expect(t, r == "3", fmt.tprintf("%s: \"%s\" != \"3\"\n", #procedure, r))
|
||||
}
|
||||
Reference in New Issue
Block a user