mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Port tests\core\path\filepath
This commit is contained in:
+1
-1
@@ -54,7 +54,7 @@ encoding_test:
|
|||||||
$(ODIN) test encoding/xml $(COMMON) -out:test_xml
|
$(ODIN) test encoding/xml $(COMMON) -out:test_xml
|
||||||
|
|
||||||
filepath_test:
|
filepath_test:
|
||||||
$(ODIN) run path/filepath $(COMMON) $(COLLECTION) -out:test_core_filepath
|
$(ODIN) test path/filepath $(COMMON) -out:test_core_filepath
|
||||||
|
|
||||||
fmt_test:
|
fmt_test:
|
||||||
$(ODIN) run fmt $(COMMON) -out:test_core_fmt
|
$(ODIN) run fmt $(COMMON) -out:test_core_fmt
|
||||||
|
|||||||
@@ -34,6 +34,11 @@ echo ---
|
|||||||
%PATH_TO_ODIN% test encoding/varint %COMMON% -out:test_varint.exe || exit /b
|
%PATH_TO_ODIN% test encoding/varint %COMMON% -out:test_varint.exe || exit /b
|
||||||
%PATH_TO_ODIN% test encoding/xml %COMMON% -out:test_xml.exe || exit /b
|
%PATH_TO_ODIN% test encoding/xml %COMMON% -out:test_xml.exe || exit /b
|
||||||
|
|
||||||
|
echo ---
|
||||||
|
echo Running core:path/filepath tests
|
||||||
|
echo ---
|
||||||
|
%PATH_TO_ODIN% test path/filepath %COMMON% -out:test_core_filepath.exe || exit /b
|
||||||
|
|
||||||
echo ---
|
echo ---
|
||||||
echo Running core:fmt tests
|
echo Running core:fmt tests
|
||||||
echo ---
|
echo ---
|
||||||
@@ -74,11 +79,6 @@ echo Running core:odin tests
|
|||||||
echo ---
|
echo ---
|
||||||
%PATH_TO_ODIN% run odin %COMMON% -o:size -out:test_core_odin.exe || exit /b
|
%PATH_TO_ODIN% run odin %COMMON% -o:size -out:test_core_odin.exe || exit /b
|
||||||
|
|
||||||
echo ---
|
|
||||||
echo Running core:path/filepath tests
|
|
||||||
echo ---
|
|
||||||
%PATH_TO_ODIN% run path/filepath %COMMON% %COLLECTION% -out:test_core_filepath.exe || exit /b
|
|
||||||
|
|
||||||
echo ---
|
echo ---
|
||||||
echo Running core:reflect tests
|
echo Running core:reflect tests
|
||||||
echo ---
|
echo ---
|
||||||
|
|||||||
@@ -1,26 +1,19 @@
|
|||||||
// Tests "path.odin" in "core:path/filepath".
|
// 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
|
package test_core_filepath
|
||||||
|
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:path/filepath"
|
import "core:path/filepath"
|
||||||
import "core:testing"
|
import "core:testing"
|
||||||
import tc "tests:common"
|
|
||||||
|
|
||||||
main :: proc() {
|
|
||||||
t := testing.T{}
|
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_split_list :: proc(t: ^testing.T) {
|
||||||
when ODIN_OS == .Windows {
|
when ODIN_OS == .Windows {
|
||||||
test_split_list_windows(&t)
|
test_split_list_windows(t)
|
||||||
} else {
|
} else {
|
||||||
test_split_list_unix(&t)
|
test_split_list_unix(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
tc.report(&t)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test
|
|
||||||
test_split_list_windows :: proc(t: ^testing.T) {
|
test_split_list_windows :: proc(t: ^testing.T) {
|
||||||
Datum :: struct {
|
Datum :: struct {
|
||||||
i: int,
|
i: int,
|
||||||
@@ -41,12 +34,12 @@ test_split_list_windows :: proc(t: ^testing.T) {
|
|||||||
for d, i in data {
|
for d, i in data {
|
||||||
assert(i == d.i, fmt.tprintf("wrong data index: i %d != d.i %d\n", i, d.i))
|
assert(i == d.i, fmt.tprintf("wrong data index: i %d != d.i %d\n", i, d.i))
|
||||||
r := filepath.split_list(d.v)
|
r := filepath.split_list(d.v)
|
||||||
defer delete(r)
|
defer delete_split(r)
|
||||||
tc.expect(t, len(r) == len(d.e), fmt.tprintf("i:%d %s(%s) len(r) %d != len(d.e) %d",
|
testing.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)))
|
i, #procedure, d.v, len(r), len(d.e)))
|
||||||
if len(r) == len(d.e) {
|
if len(r) == len(d.e) {
|
||||||
for _, j in r {
|
for _, j in r {
|
||||||
tc.expect(t, r[j] == d.e[j], fmt.tprintf("i:%d %s(%v) -> %v[%d] != %v",
|
testing.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]))
|
i, #procedure, d.v, r[j], j, d.e[j]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,47 +48,43 @@ test_split_list_windows :: proc(t: ^testing.T) {
|
|||||||
{
|
{
|
||||||
v := ""
|
v := ""
|
||||||
r := filepath.split_list(v)
|
r := filepath.split_list(v)
|
||||||
tc.expect(t, r == nil, fmt.tprintf("%s(%s) -> %v != nil", #procedure, v, r))
|
defer delete_split(r)
|
||||||
|
testing.expect(t, r == nil, fmt.tprintf("%s(%s) -> %v != nil", #procedure, v, r))
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
v := "a"
|
v := "a"
|
||||||
r := filepath.split_list(v)
|
r := filepath.split_list(v)
|
||||||
defer delete(r)
|
defer delete_split(r)
|
||||||
tc.expect(t, len(r) == 1, fmt.tprintf("%s(%s) len(r) %d != 1", #procedure, v, len(r)))
|
testing.expect(t, len(r) == 1, fmt.tprintf("%s(%s) len(r) %d != 1", #procedure, v, len(r)))
|
||||||
if len(r) == 1 {
|
if len(r) == 1 {
|
||||||
tc.expect(t, r[0] == "a", fmt.tprintf("%s(%v) -> %v[0] != a", #procedure, v, r[0]))
|
testing.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) {
|
test_split_list_unix :: proc(t: ^testing.T) {
|
||||||
Datum :: struct {
|
Datum :: struct {
|
||||||
i: int,
|
|
||||||
v: string,
|
v: string,
|
||||||
e: [3]string,
|
e: [3]string,
|
||||||
}
|
}
|
||||||
@static data := []Datum{
|
@static data := []Datum{
|
||||||
{ 0, "/opt/butler:/home/fancykillerpanda/Projects/Odin/Odin:/usr/local/sbin",
|
{ "/opt/butler:/home/fancykillerpanda/Projects/Odin/Odin:/usr/local/sbin",
|
||||||
[3]string{"/opt/butler", "/home/fancykillerpanda/Projects/Odin/Odin", "/usr/local/sbin"} }, // Issue #1537
|
[3]string{"/opt/butler", "/home/fancykillerpanda/Projects/Odin/Odin", "/usr/local/sbin"} }, // Issue #1537
|
||||||
{ 1, "a::b", [3]string{"a", "", "b"} },
|
{ "a::b", [3]string{"a", "", "b"} },
|
||||||
{ 2, "a:b:", [3]string{"a", "b", ""} },
|
{ "a:b:", [3]string{"a", "b", ""} },
|
||||||
{ 3, ":a:b", [3]string{"", "a", "b"} },
|
{ ":a:b", [3]string{"", "a", "b"} },
|
||||||
{ 4, "::", [3]string{"", "", ""} },
|
{ "::", [3]string{"", "", ""} },
|
||||||
{ 5, "\"a:b\"c:d:\"f\"", [3]string{"a:bc", "d", "f"} },
|
{ "\"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"} },
|
{ "\"a:b:c\":d\":e\":f", [3]string{"a:b:c", "d:e", "f"} },
|
||||||
}
|
}
|
||||||
|
|
||||||
for d, i in data {
|
for d in data {
|
||||||
assert(i == d.i, fmt.tprintf("wrong data index: i %d != d.i %d\n", i, d.i))
|
|
||||||
r := filepath.split_list(d.v)
|
r := filepath.split_list(d.v)
|
||||||
defer delete(r)
|
defer delete_split(r)
|
||||||
tc.expect(t, len(r) == len(d.e), fmt.tprintf("i:%d %s(%s) len(r) %d != len(d.e) %d",
|
testing.expectf(t, len(r) == len(d.e), "%s len(r) %d != len(d.e) %d", d.v, len(r), len(d.e))
|
||||||
i, #procedure, d.v, len(r), len(d.e)))
|
|
||||||
if len(r) == len(d.e) {
|
if len(r) == len(d.e) {
|
||||||
for _, j in r {
|
for _, j in r {
|
||||||
tc.expect(t, r[j] == d.e[j], fmt.tprintf("i:%d %s(%v) -> %v[%d] != %v",
|
testing.expectf(t, r[j] == d.e[j], "%v -> %v[%d] != %v", d.v, r[j], j, d.e[j])
|
||||||
i, #procedure, d.v, r[j], j, d.e[j]))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,15 +92,23 @@ test_split_list_unix :: proc(t: ^testing.T) {
|
|||||||
{
|
{
|
||||||
v := ""
|
v := ""
|
||||||
r := filepath.split_list(v)
|
r := filepath.split_list(v)
|
||||||
tc.expect(t, r == nil, fmt.tprintf("%s(%s) -> %v != nil", #procedure, v, r))
|
testing.expectf(t, r == nil, "'%s' -> '%v' != nil", v, r)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
v := "a"
|
v := "a"
|
||||||
r := filepath.split_list(v)
|
r := filepath.split_list(v)
|
||||||
defer delete(r)
|
defer delete_split(r)
|
||||||
tc.expect(t, len(r) == 1, fmt.tprintf("%s(%s) len(r) %d != 1", #procedure, v, len(r)))
|
testing.expectf(t, len(r) == 1, "'%s' len(r) %d != 1", v, len(r))
|
||||||
if len(r) == 1 {
|
if len(r) == 1 {
|
||||||
tc.expect(t, r[0] == "a", fmt.tprintf("%s(%v) -> %v[0] != a", #procedure, v, r[0]))
|
testing.expectf(t, r[0] == "a", "'%v' -> %v[0] != a", v, r[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(private)
|
||||||
|
delete_split :: proc(s: []string) {
|
||||||
|
for part in s {
|
||||||
|
delete(part)
|
||||||
|
}
|
||||||
|
delete(s)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user