Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More unit tests #221

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions tests/cleo_tests/FilesystemOperations/0AE5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ terminate_this_custom_script
const Test_Path = "cleo\\cleo_test_directory"

function tests
before_each(@cleanup)
after_each(@cleanup)

it("should create directory", test1)
return

:cleanup
delete_directory {path} Test_Path {recursive} true
return

function test1
does_directory_exist {path} Test_Path
assert_result_false()
Expand All @@ -22,9 +28,6 @@ function tests

does_directory_exist {path} Test_Path
assert_result_true()

// cleanup
delete_directory {path} Test_Path {recursive} false
end

end
8 changes: 7 additions & 1 deletion tests/cleo_tests/FilesystemOperations/0B00.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ terminate_this_custom_script
const Test_Path = "cleo\\cleo_test_file.ini"

function tests

before_each(@cleanup)
after_each(@cleanup)

it("should fail on a non-existing file", test1)
it("should delete existing file", test2)
return

:cleanup
delete_file {path} Test_Path
return

function test1
delete_file {path} "cleo\\not_a_file.ini" // tested opcode
assert_result_false()
Expand Down
7 changes: 7 additions & 0 deletions tests/cleo_tests/FilesystemOperations/0B01.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ terminate_this_custom_script
const Test_Path = "cleo\\cleo_test_directory"

function tests
before_each(@cleanup)
after_each(@cleanup)

it("should fail on a non-existing directory", test1)
it("should delete empty directory", test2)
it("should delete directory with contents", test3)
return

:cleanup
set_current_directory {path} 0
delete_directory {dirPath} Test_Path {recursive} true
return

function test1
delete_directory {dirPath} Test_Path {recursive} false // tested opcode
assert_result_false()
Expand Down
10 changes: 7 additions & 3 deletions tests/cleo_tests/FilesystemOperations/0B02.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ const Test_Path_Src = "cleo\\cleo_test_file.ini"
const Test_Path_Dst = "_test_file_B.ini"

function tests
before_each(@cleanup)
after_each(@cleanup)

it("should fail on a non-existing file", test1)
it("should move file", test2)
return

:cleanup
delete_file {path} Test_Path_Src
delete_file {path} Test_Path_Dst
return

function test1
does_file_exist {dirPath} Test_Path_Src
assert_result_false()
Expand Down Expand Up @@ -42,9 +49,6 @@ function tests

int value = read_int_from_ini_file {path} Test_Path_Dst {section} "test" {key} "test"
assert_eq(value, 42)

// cleanup
delete_file {fileName} Test_Path_Dst
end

end
12 changes: 8 additions & 4 deletions tests/cleo_tests/FilesystemOperations/0B03.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ const Test_Path_Src = "cleo\\cleo_test_dir"
const Test_Path_Dst = "test_directory"

function tests
before_each(@cleanup)
after_each(@cleanup)

it("should fail on a non-existing directory", test1)
it("should move directory", test2)
return

:cleanup
set_current_directory {path} 0
delete_directory {path} Test_Path_Src
delete_directory {path} Test_Path_Dst
return

function test1
does_directory_exist {dirPath} Test_Path_Src
assert_result_false()
Expand Down Expand Up @@ -57,10 +65,6 @@ function tests
assert_result_true()
value = read_int_from_ini_file {path} "Test_File.ini" {section} "test" {key} "test"
assert_eq(value, 42)
set_current_directory {path} 0

// cleanup
delete_directory {dirPath} Test_Path_Dst {recursive} true
end

end
17 changes: 10 additions & 7 deletions tests/cleo_tests/FilesystemOperations/0B04.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ const Test_Path_Src = "cleo\\cleo_test_file.ini"
const Test_Path_Dst = "_test_file_B.ini"

function tests
before_each(@cleanup)
after_each(@cleanup)

it("should fail on a non-existing file", test1)
it("should copy file", test2)
return

:cleanup
delete_file {path} Test_Path_Src
delete_file {path} Test_Path_Dst
return

function test1
does_file_exist {dirPath} Test_Path_Src
does_file_exist {path} Test_Path_Src
assert_result_false()

copy_file {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
Expand All @@ -27,9 +34,9 @@ function tests
// setup
write_int_to_ini_file {value} 42 {path} Test_Path_Src {section} "test" {key} "test"
assert_result_true()
does_file_exist {dirPath} Test_Path_Src
does_file_exist {path} Test_Path_Src
assert_result_true()
does_file_exist {dirPath} Test_Path_Dst
does_file_exist {path} Test_Path_Dst
assert_result_false()

// act
Expand All @@ -41,10 +48,6 @@ function tests

value = read_int_from_ini_file {path} Test_Path_Dst {section} "test" {key} "test"
assert_eq(value, 42)

// cleanup
delete_file {fileName} Test_Path_Src
delete_file {fileName} Test_Path_Dst
end

end
13 changes: 8 additions & 5 deletions tests/cleo_tests/FilesystemOperations/0B05.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ const Test_Path_Src = "cleo\\cleo_test_dir"
const Test_Path_Dst = "test_directory"

function tests
before_each(@cleanup)
after_each(@cleanup)

it("should fail on a non-existing directory", test1)
it("should move directory", test2)
return

:cleanup
set_current_directory {path} 0
delete_directory {path} Test_Path_Src {recursive} true
delete_directory {path} Test_Path_Dst {recursive} true
return

function test1
does_directory_exist {dirPath} Test_Path_Src
assert_result_false()
Expand Down Expand Up @@ -64,11 +72,6 @@ function tests
assert_result_true()
value = read_int_from_ini_file {path} "Test_File.ini" {section} "test" {key} "test"
assert_eq(value, 42)
set_current_directory {path} 0

// cleanup
delete_directory {dirPath} Test_Path_Src {recursive} true
delete_directory {dirPath} Test_Path_Dst {recursive} true
end

end
59 changes: 59 additions & 0 deletions tests/cleo_tests/IniFiles/0AF0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0AF0"
test("0AF0 (read_int_from_ini_file)", tests)
terminate_this_custom_script


const Test_Path = "cleo\\cleo_test_file.ini"

function tests
before_each(@setup)
after_each(@cleanup)

it("should fail on not-existing file", test1)
it("should fail on invalid file", test2)
it("should fail on not existing value", test3)
it("should fail on invalid type", test4)
it("should read value", test5)

return

:setup
delete_file {path} Test_Path
write_int_to_ini_file {value} 42 {path} Test_Path {section} "test" {key} "test_int"
write_float_to_ini_file {value} 50.0 {path} Test_Path {section} "test" {key} "test_float"
write_string_to_ini_file {value} "value_one" {path} Test_Path {section} "test" {key} "test_string"
return

:cleanup
delete_file {path} Test_Path
return

function test1
int value = read_int_from_ini_file {path} "not_a_file.ini" {section} "test" {key} "test_int"
assert_result_false()
end

function test2
int value = read_int_from_ini_file {path} "cleo.asi" {section} "test" {key} "test_int"
assert_result_false()
end

function test3
int value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "invalid_key"
assert_result_false()
end

function test4
int value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "test_string"
assert_result_false()
end

function test5
int value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "test_int"
assert_result_true()
assert_eq(value, 42)
end
end
81 changes: 81 additions & 0 deletions tests/cleo_tests/IniFiles/0AF1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0AF1"
test("0AF1 (write_int_to_ini_file)", tests)
terminate_this_custom_script


const Test_Path = "cleo\\cleo_test_file.ini"

function tests
before_each(@cleanup)
after_each(@cleanup)

it("should fail to overwrite file", test1)
it("should fail to overwrite directory", test2)
it("should create new file", test3)
it("should append to existing file", test4)
it("should overwrite value", test5)
return

:cleanup
delete_file {path} Test_Path
return

function test1
write_int_to_ini_file {value} 42 {path} "gta_sa.exe" {section} "test" {key} "test"
assert_result_false()
end

function test2
write_int_to_ini_file {value} 42 {path} "cleo" {section} "test" {key} "test"
assert_result_false()
end

function test3
does_file_exist {path} Test_Path
assert_result_false()

write_int_to_ini_file {value} 42 {path} Test_Path {section} "test" {key} "test"
assert_result_true()

does_file_exist {path} Test_Path
assert_result_true()

int value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "test"
assert_eq(value, 42)
end

function test4
does_file_exist {path} Test_Path
assert_result_false()

write_int_to_ini_file {value} 42 {path} Test_Path {section} "test" {key} "testA"
assert_result_true()

write_int_to_ini_file {value} 50 {path} Test_Path {section} "test" {key} "testB"
assert_result_true()

int value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "testA"
assert_eq(value, 42)

value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "testB"
assert_eq(value, 50)
end

function test5
does_file_exist {path} Test_Path
assert_result_false()

write_int_to_ini_file {value} 42 {path} Test_Path {section} "test" {key} "test"
assert_result_true()

write_int_to_ini_file {value} 50 {path} Test_Path {section} "test" {key} "test"
assert_result_true()

int value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "test"
assert_eq(value, 50)
end

end
Loading