Add more tests and some impl improvements from their results
This commit is contained in:
+11
-6
@@ -131,7 +131,10 @@ read :: proc(
|
||||
t: ^testing.T,
|
||||
path: string,
|
||||
allocator := context.allocator,
|
||||
) -> string {
|
||||
) -> (
|
||||
bool,
|
||||
string,
|
||||
) {
|
||||
relpath, err := os.join_path({ts.input_dir, path}, allocator)
|
||||
testing.expect(t, err == nil, os.error_string(err))
|
||||
defer delete(relpath, allocator)
|
||||
@@ -144,12 +147,14 @@ read :: proc(
|
||||
testing.expect(t, err3 == nil, chunks.format_error(err3))
|
||||
defer chunks.reader_destroy(&r)
|
||||
|
||||
exists, i, err4 := chunks.file_exists(&r, relpath)
|
||||
testing.expect(t, exists)
|
||||
exists, i, err4 := chunks.asset_exists(&r, relpath)
|
||||
testing.expect(t, err4 == nil, chunks.format_error(err4))
|
||||
|
||||
bytes, err5 := chunks.read_file(&r, relpath)
|
||||
testing.expect(t, err5 == nil, chunks.format_error(err5))
|
||||
if exists {
|
||||
bytes, err5 := chunks.read_asset(&r, relpath)
|
||||
testing.expect(t, err5 == nil, chunks.format_error(err5))
|
||||
return true, string(bytes)
|
||||
}
|
||||
|
||||
return string(bytes)
|
||||
return false, {}
|
||||
}
|
||||
|
||||
+295
-51
@@ -1,30 +1,10 @@
|
||||
package tests
|
||||
|
||||
import "core:strings"
|
||||
import "core:testing"
|
||||
|
||||
@(test)
|
||||
single_tiny_file_read_from_chunk :: proc(t: ^testing.T) {
|
||||
// Arrange
|
||||
|
||||
ts := test_state_init(t, #procedure)
|
||||
defer test_state_destroy(&ts, t)
|
||||
|
||||
delete_path(&ts, t, "")
|
||||
create_file(&ts, t, "single_tiny_file", "hello world!")
|
||||
pack(&ts, t, 750)
|
||||
delete_path(&ts, t, "")
|
||||
|
||||
// Act
|
||||
|
||||
read := read(&ts, t, "single_tiny_file")
|
||||
|
||||
// Assert
|
||||
|
||||
testing.expect_value(t, read, "hello world!")
|
||||
}
|
||||
|
||||
@(test)
|
||||
single_file_single_chunk_read_from_path :: proc(t: ^testing.T) {
|
||||
single_asset_single_chunk_read_from_path :: proc(t: ^testing.T) {
|
||||
// Arrange
|
||||
|
||||
ts := test_state_init(t, #procedure)
|
||||
@@ -38,7 +18,7 @@ single_file_single_chunk_read_from_path :: proc(t: ^testing.T) {
|
||||
|
||||
// Act
|
||||
|
||||
read := read(&ts, t, "single_tiny_file")
|
||||
_, read := read(&ts, t, "single_tiny_file")
|
||||
|
||||
// Assert
|
||||
|
||||
@@ -46,34 +26,53 @@ single_file_single_chunk_read_from_path :: proc(t: ^testing.T) {
|
||||
}
|
||||
|
||||
@(test)
|
||||
multiple_files_single_chunk_read_from_chunk :: proc(t: ^testing.T) {
|
||||
single_asset_single_chunk_read_from_chunk :: proc(t: ^testing.T) {
|
||||
// Arrange
|
||||
|
||||
ts := test_state_init(t, #procedure)
|
||||
defer test_state_destroy(&ts, t)
|
||||
|
||||
delete_path(&ts, t, "")
|
||||
create_file(&ts, t, "a", "hello a!")
|
||||
create_file(&ts, t, "b", "hello b!")
|
||||
create_file(&ts, t, "c", "hello c!")
|
||||
pack(&ts, t, 1750)
|
||||
create_file(&ts, t, "single_tiny_file", "hello world!")
|
||||
pack(&ts, t, 750)
|
||||
delete_path(&ts, t, "")
|
||||
|
||||
// Act
|
||||
|
||||
a := read(&ts, t, "a")
|
||||
b := read(&ts, t, "b")
|
||||
c := read(&ts, t, "c")
|
||||
_, read := read(&ts, t, "single_tiny_file")
|
||||
|
||||
// Assert
|
||||
|
||||
testing.expect_value(t, a, "hello a!")
|
||||
testing.expect_value(t, b, "hello b!")
|
||||
testing.expect_value(t, c, "hello c!")
|
||||
testing.expect_value(t, read, "hello world!")
|
||||
}
|
||||
|
||||
@(test)
|
||||
multiple_files_single_chunk_read_from_path :: proc(t: ^testing.T) {
|
||||
single_asset_multiple_chunks_read_from_chunk :: proc(t: ^testing.T) {
|
||||
// Arrange
|
||||
|
||||
ts := test_state_init(t, #procedure)
|
||||
defer test_state_destroy(&ts, t)
|
||||
|
||||
delete_path(&ts, t, "")
|
||||
content := strings.repeat("abcde", 400)
|
||||
defer delete(content)
|
||||
create_file(&ts, t, "multi_chunk_file", content)
|
||||
pack(&ts, t, 750)
|
||||
delete_path(&ts, t, "")
|
||||
|
||||
// Act
|
||||
|
||||
_, read := read(&ts, t, "multi_chunk_file")
|
||||
|
||||
// Assert
|
||||
|
||||
testing.expect_value(t, read, content)
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
@(test)
|
||||
multiple_assets_single_chunk_read_from_path :: proc(t: ^testing.T) {
|
||||
// Arrange
|
||||
|
||||
ts := test_state_init(t, #procedure)
|
||||
@@ -91,9 +90,9 @@ multiple_files_single_chunk_read_from_path :: proc(t: ^testing.T) {
|
||||
|
||||
// Act
|
||||
|
||||
a := read(&ts, t, "a")
|
||||
b := read(&ts, t, "b")
|
||||
c := read(&ts, t, "c")
|
||||
_, a := read(&ts, t, "a")
|
||||
_, b := read(&ts, t, "b")
|
||||
_, c := read(&ts, t, "c")
|
||||
|
||||
// Assert
|
||||
|
||||
@@ -102,17 +101,262 @@ multiple_files_single_chunk_read_from_path :: proc(t: ^testing.T) {
|
||||
testing.expect_value(t, c, "hello c from path!")
|
||||
}
|
||||
|
||||
// @(test)
|
||||
// blabla :: proc(t: ^testing.T) {
|
||||
// // Arrange
|
||||
//
|
||||
// // Act
|
||||
//
|
||||
// // Assert
|
||||
// }
|
||||
@(test)
|
||||
multiple_assets_single_chunk_read_from_chunk :: proc(t: ^testing.T) {
|
||||
// Arrange
|
||||
|
||||
// TODO:
|
||||
// v multiple files (path and chunk find)
|
||||
// - nested file (path and chunk find)
|
||||
// - not found in path
|
||||
// - not found in path + chunk
|
||||
ts := test_state_init(t, #procedure)
|
||||
defer test_state_destroy(&ts, t)
|
||||
|
||||
delete_path(&ts, t, "")
|
||||
create_file(&ts, t, "a", "hello a!")
|
||||
create_file(&ts, t, "b", "hello b!")
|
||||
create_file(&ts, t, "c", "hello c!")
|
||||
pack(&ts, t, 1750)
|
||||
delete_path(&ts, t, "")
|
||||
|
||||
// Act
|
||||
|
||||
_, a := read(&ts, t, "a")
|
||||
_, b := read(&ts, t, "b")
|
||||
_, c := read(&ts, t, "c")
|
||||
|
||||
// Assert
|
||||
|
||||
testing.expect_value(t, a, "hello a!")
|
||||
testing.expect_value(t, b, "hello b!")
|
||||
testing.expect_value(t, c, "hello c!")
|
||||
}
|
||||
|
||||
@(test)
|
||||
multiple_assets_multiple_chunks_read_from_chunk :: proc(t: ^testing.T) {
|
||||
// Arrange
|
||||
|
||||
ts := test_state_init(t, #procedure)
|
||||
defer test_state_destroy(&ts, t)
|
||||
|
||||
delete_path(&ts, t, "")
|
||||
content_a := strings.repeat("a", 700)
|
||||
defer delete(content_a)
|
||||
content_b := strings.repeat("b", 700)
|
||||
defer delete(content_b)
|
||||
content_c := strings.repeat("c", 700)
|
||||
defer delete(content_c)
|
||||
create_file(&ts, t, "a", content_a)
|
||||
create_file(&ts, t, "b", content_b)
|
||||
create_file(&ts, t, "c", content_c)
|
||||
pack(&ts, t, 1750)
|
||||
delete_path(&ts, t, "")
|
||||
|
||||
// Act
|
||||
|
||||
_, a := read(&ts, t, "a")
|
||||
_, b := read(&ts, t, "b")
|
||||
_, c := read(&ts, t, "c")
|
||||
|
||||
// Assert
|
||||
|
||||
testing.expect_value(t, a, content_a)
|
||||
testing.expect_value(t, b, content_b)
|
||||
testing.expect_value(t, c, content_c)
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
@(test)
|
||||
single_asset_single_chunk_nested_path_read_from_path :: proc(t: ^testing.T) {
|
||||
// Arrange
|
||||
|
||||
ts := test_state_init(t, #procedure)
|
||||
defer test_state_destroy(&ts, t)
|
||||
|
||||
delete_path(&ts, t, "")
|
||||
create_file(&ts, t, "subdir/nested_file", "hello nested!")
|
||||
pack(&ts, t, 750)
|
||||
delete_path(&ts, t, "")
|
||||
create_file(&ts, t, "subdir/nested_file", "hello nested from path!")
|
||||
|
||||
// Act
|
||||
|
||||
_, read := read(&ts, t, "subdir/nested_file")
|
||||
|
||||
// Assert
|
||||
|
||||
testing.expect_value(t, read, "hello nested from path!")
|
||||
}
|
||||
|
||||
@(test)
|
||||
single_asset_single_chunk_nested_path_read_from_chunk :: proc(t: ^testing.T) {
|
||||
// Arrange
|
||||
|
||||
ts := test_state_init(t, #procedure)
|
||||
defer test_state_destroy(&ts, t)
|
||||
|
||||
delete_path(&ts, t, "")
|
||||
create_file(&ts, t, "subdir/nested_file", "hello nested!")
|
||||
pack(&ts, t, 750)
|
||||
delete_path(&ts, t, "")
|
||||
|
||||
// Act
|
||||
|
||||
_, read := read(&ts, t, "subdir/nested_file")
|
||||
|
||||
// Assert
|
||||
|
||||
testing.expect_value(t, read, "hello nested!")
|
||||
}
|
||||
|
||||
@(test)
|
||||
single_asset_multiple_chunks_nested_path_read_from_chunk :: proc(
|
||||
t: ^testing.T,
|
||||
) {
|
||||
// Arrange
|
||||
|
||||
ts := test_state_init(t, #procedure)
|
||||
defer test_state_destroy(&ts, t)
|
||||
|
||||
delete_path(&ts, t, "")
|
||||
content := strings.repeat("abcde", 50)
|
||||
defer delete(content)
|
||||
create_file(&ts, t, "subdir/nested_file", content)
|
||||
pack(&ts, t, 750)
|
||||
delete_path(&ts, t, "")
|
||||
|
||||
// Act
|
||||
|
||||
_, read := read(&ts, t, "subdir/nested_file")
|
||||
|
||||
// Assert
|
||||
|
||||
testing.expect_value(t, read, content)
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
@(test)
|
||||
asset_in_path_not_in_chunk_read_matching_file :: proc(t: ^testing.T) {
|
||||
// Arrange
|
||||
|
||||
ts := test_state_init(t, #procedure)
|
||||
defer test_state_destroy(&ts, t)
|
||||
|
||||
delete_path(&ts, t, "")
|
||||
create_file(&ts, t, "chunk", "hello from chunk!")
|
||||
pack(&ts, t, 750)
|
||||
delete_path(&ts, t, "")
|
||||
create_file(&ts, t, "target", "hello from path!")
|
||||
|
||||
// Act
|
||||
|
||||
_, read := read(&ts, t, "target")
|
||||
|
||||
// Assert
|
||||
|
||||
testing.expect_value(t, read, "hello from path!")
|
||||
}
|
||||
|
||||
@(test)
|
||||
asset_in_chunk_not_in_path_read_matching_file :: proc(t: ^testing.T) {
|
||||
// Arrange
|
||||
|
||||
ts := test_state_init(t, #procedure)
|
||||
defer test_state_destroy(&ts, t)
|
||||
|
||||
delete_path(&ts, t, "")
|
||||
create_file(&ts, t, "target", "hello from chunk!")
|
||||
pack(&ts, t, 750)
|
||||
delete_path(&ts, t, "")
|
||||
|
||||
// Act
|
||||
|
||||
_, read := read(&ts, t, "target")
|
||||
|
||||
// Assert
|
||||
|
||||
testing.expect_value(t, read, "hello from chunk!")
|
||||
}
|
||||
|
||||
@(test)
|
||||
asset_in_chunk_and_in_path_read_matching_file :: proc(t: ^testing.T) {
|
||||
// Arrange
|
||||
|
||||
ts := test_state_init(t, #procedure)
|
||||
defer test_state_destroy(&ts, t)
|
||||
|
||||
delete_path(&ts, t, "")
|
||||
create_file(&ts, t, "target", "hello from chunk!")
|
||||
pack(&ts, t, 750)
|
||||
delete_path(&ts, t, "")
|
||||
create_file(&ts, t, "target", "hello from path!")
|
||||
|
||||
// Act
|
||||
|
||||
_, read := read(&ts, t, "target")
|
||||
|
||||
// Assert
|
||||
|
||||
testing.expect_value(t, read, "hello from path!")
|
||||
}
|
||||
|
||||
@(test)
|
||||
asset_in_path_not_in_chunk_read_non_matching_file :: proc(t: ^testing.T) {
|
||||
// Arrange
|
||||
|
||||
ts := test_state_init(t, #procedure)
|
||||
defer test_state_destroy(&ts, t)
|
||||
|
||||
pack(&ts, t, 750)
|
||||
delete_path(&ts, t, "")
|
||||
create_file(&ts, t, "target", "hello from path!")
|
||||
|
||||
// Act
|
||||
|
||||
exists, _ := read(&ts, t, "non_matching")
|
||||
|
||||
// Assert
|
||||
|
||||
testing.expect(t, !exists)
|
||||
}
|
||||
|
||||
@(test)
|
||||
asset_in_chunk_not_in_path_read_non_matching_file :: proc(t: ^testing.T) {
|
||||
// Arrange
|
||||
|
||||
ts := test_state_init(t, #procedure)
|
||||
defer test_state_destroy(&ts, t)
|
||||
|
||||
delete_path(&ts, t, "")
|
||||
create_file(&ts, t, "target", "hello from chunk!")
|
||||
pack(&ts, t, 750)
|
||||
delete_path(&ts, t, "")
|
||||
|
||||
// Act
|
||||
|
||||
exists, _ := read(&ts, t, "non_matching")
|
||||
|
||||
// Assert
|
||||
|
||||
testing.expect(t, !exists)
|
||||
}
|
||||
|
||||
@(test)
|
||||
asset_in_chunk_and_in_path_read_non_matching_file :: proc(t: ^testing.T) {
|
||||
// Arrange
|
||||
|
||||
ts := test_state_init(t, #procedure)
|
||||
defer test_state_destroy(&ts, t)
|
||||
|
||||
delete_path(&ts, t, "")
|
||||
create_file(&ts, t, "target", "hello from chunk!")
|
||||
pack(&ts, t, 750)
|
||||
delete_path(&ts, t, "")
|
||||
create_file(&ts, t, "target", "hello from path!")
|
||||
|
||||
// Act
|
||||
|
||||
exists, _ := read(&ts, t, "non_matching")
|
||||
|
||||
// Assert
|
||||
|
||||
testing.expect(t, !exists)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user