From 8d79e6f0ab0e5743eea6dee30f31b11d09a1caac Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 15 Aug 2023 03:24:15 +0100 Subject: [PATCH] tests/weaschem: more tests, but not done w/parse_header yet --- .../header_invalid_description_type.json | 16 ++++++++++++ .../testfiles/header_invalid_no_offset.json | 10 +++++++ .../testfiles/header_invalid_no_size.json | 10 +++++++ .tests/parse/file/weaschem_header.test.lua | 26 +++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 .tests/parse/file/testfiles/header_invalid_description_type.json create mode 100644 .tests/parse/file/testfiles/header_invalid_no_offset.json create mode 100644 .tests/parse/file/testfiles/header_invalid_no_size.json diff --git a/.tests/parse/file/testfiles/header_invalid_description_type.json b/.tests/parse/file/testfiles/header_invalid_description_type.json new file mode 100644 index 0000000..ca52c7c --- /dev/null +++ b/.tests/parse/file/testfiles/header_invalid_description_type.json @@ -0,0 +1,16 @@ +{ + "name": "A castle", + "description": 88, + "size": { + "x": 50, + "y": 25, + "z": 75 + }, + "offset": { + "x": 3, + "y": 0, + "z": 5 + }, + "type": "full", + "generator": "WorldEditAdditions v1.14" +} \ No newline at end of file diff --git a/.tests/parse/file/testfiles/header_invalid_no_offset.json b/.tests/parse/file/testfiles/header_invalid_no_offset.json new file mode 100644 index 0000000..800471c --- /dev/null +++ b/.tests/parse/file/testfiles/header_invalid_no_offset.json @@ -0,0 +1,10 @@ +{ + "name": "A castle", + "size": { + "x": 50, + "y": 25, + "z": 75 + }, + "type": "full", + "generator": "WorldEditAdditions v1.14" +} \ No newline at end of file diff --git a/.tests/parse/file/testfiles/header_invalid_no_size.json b/.tests/parse/file/testfiles/header_invalid_no_size.json new file mode 100644 index 0000000..21a56bc --- /dev/null +++ b/.tests/parse/file/testfiles/header_invalid_no_size.json @@ -0,0 +1,10 @@ +{ + "name": "A castle", + "offset": { + "x": 50, + "y": 25, + "z": 75 + }, + "type": "full", + "generator": "WorldEditAdditions v1.14" +} \ No newline at end of file diff --git a/.tests/parse/file/weaschem_header.test.lua b/.tests/parse/file/weaschem_header.test.lua index e5b8703..42a2c50 100644 --- a/.tests/parse/file/weaschem_header.test.lua +++ b/.tests/parse/file/weaschem_header.test.lua @@ -63,5 +63,31 @@ describe("parse.file.weaschem.parse_header", function() assert.are.same("HEADER_NAME_INVALID", code) assert.are.same("string", type(result)) end) + it("should complain for an invalid header with description of wrong type", function() + local content = get_json_string("invalid_description_type") + assert.are_not.same(nil, content) + local success, code, result = weaschem.parse_header(content) + assert.are.same(false, success) + assert.are.same("HEADER_DESCRIPTION_INVALID", code) + assert.are.same("string", type(result)) + end) + it("should complain for an invalid header with no offset", function() + local content = get_json_string("invalid_no_offset") + assert.are_not.same(nil, content) + local success, code, result = weaschem.parse_header(content) + assert.are.same(false, success) + assert.are.same("HEADER_NO_OFFSET", code) + assert.are.same("string", type(result)) + end) + it("should complain for an invalid header with no size", function() + local content = get_json_string("invalid_no_size") + assert.are_not.same(nil, content) + local success, code, result = weaschem.parse_header(content) + assert.are.same(false, success) + assert.are.same("HEADER_NO_SIZE", code) + assert.are.same("string", type(result)) + end) + + -- TODO: Test invalid sizes/offsets, but this is mainly handled by the above end)