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)