diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..025d611 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,32 @@ +# TypeSchema + +## Tests + +This directory contains test TypeSchema specifications using different features of the specification. +If you want to build a generator or parser it is recommended to test your library against these tests. +Your generator is level 5 compliant in case it can work with all levels of the specification. + +## Level 1 + +Tests whether it is possible to work with a simple structures. It tests also that it is possible to +reference a different struct. This is the most basic feature which every processor should support. + +## Level 2 + +Tests whether it is possible to use array and map data types. Inline means that the native array/map +data types are used. Array and map definition types result in a custom array or map implementation. + +## Level 3 + +Tests whether it is possible to extend a struct. If supported a generator should produce two classes +with an actual extend. + +## Level 4 + +Tests whether it is possible to use generics. Generic placeholder at a struct can be replaced on usage +with actual types. A generator should produce actual generics if the language supports this. + +## Level 5 + +Tests whether it is possible to use discriminated union. Through a discriminated union it is possible +to use different schemas depending on a discriminated type value. diff --git a/tests/level_1_simple.json b/tests/level_1_simple.json new file mode 100644 index 0000000..98120d9 --- /dev/null +++ b/tests/level_1_simple.json @@ -0,0 +1,32 @@ +{ + "definitions": { + "Student": { + "description": "A student struct with an assigned faculty", + "type": "struct", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + }, + "age": { + "type": "integer" + }, + "faculty": { + "type": "reference", + "target": "Faculty" + } + } + }, + "Faculty": { + "type": "struct", + "properties": { + "name": { + "type": "string" + } + } + } + }, + "root": "Student" +} \ No newline at end of file diff --git a/tests/level_2_array_inline_reference.json b/tests/level_2_array_inline_reference.json new file mode 100644 index 0000000..1e9ea66 --- /dev/null +++ b/tests/level_2_array_inline_reference.json @@ -0,0 +1,37 @@ +{ + "definitions": { + "Student": { + "type": "struct", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + }, + "age": { + "type": "integer" + }, + "properties": { + "type": "array", + "schema": { + "type": "reference", + "target": "Student_Property" + } + } + } + }, + "Student_Property": { + "type": "struct", + "properties": { + "name": { + "type": "string" + }, + "value": { + "type": "string" + } + } + } + }, + "root": "Student" +} \ No newline at end of file diff --git a/tests/level_2_array_inline_string.json b/tests/level_2_array_inline_string.json new file mode 100644 index 0000000..71334ba --- /dev/null +++ b/tests/level_2_array_inline_string.json @@ -0,0 +1,25 @@ +{ + "definitions": { + "Student": { + "type": "struct", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + }, + "age": { + "type": "integer" + }, + "properties": { + "type": "array", + "schema": { + "type": "string" + } + } + } + } + }, + "root": "Student" +} \ No newline at end of file diff --git a/tests/level_2_array_reference.json b/tests/level_2_array_reference.json new file mode 100644 index 0000000..cd95dc9 --- /dev/null +++ b/tests/level_2_array_reference.json @@ -0,0 +1,41 @@ +{ + "definitions": { + "Student": { + "type": "struct", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + }, + "age": { + "type": "integer" + }, + "properties": { + "type": "reference", + "target": "Student_Array_Reference" + } + } + }, + "Student_Array_Reference": { + "type": "array", + "schema": { + "type": "reference", + "target": "Student_Property" + } + }, + "Student_Property": { + "type": "struct", + "properties": { + "name": { + "type": "string" + }, + "value": { + "type": "string" + } + } + } + }, + "root": "Student" +} \ No newline at end of file diff --git a/tests/level_2_array_string.json b/tests/level_2_array_string.json new file mode 100644 index 0000000..bf7852b --- /dev/null +++ b/tests/level_2_array_string.json @@ -0,0 +1,29 @@ +{ + "definitions": { + "Student": { + "type": "struct", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + }, + "age": { + "type": "integer" + }, + "properties": { + "type": "reference", + "target": "Student_Array_String" + } + } + }, + "Student_Array_String": { + "type": "array", + "schema": { + "type": "string" + } + } + }, + "root": "Student" +} \ No newline at end of file diff --git a/tests/level_2_map_inline_reference.json b/tests/level_2_map_inline_reference.json new file mode 100644 index 0000000..416bdf4 --- /dev/null +++ b/tests/level_2_map_inline_reference.json @@ -0,0 +1,37 @@ +{ + "definitions": { + "Student": { + "type": "struct", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + }, + "age": { + "type": "integer" + }, + "properties": { + "type": "map", + "schema": { + "type": "reference", + "target": "Student_Property" + } + } + } + }, + "Student_Property": { + "type": "struct", + "properties": { + "name": { + "type": "string" + }, + "value": { + "type": "string" + } + } + } + }, + "root": "Student" +} \ No newline at end of file diff --git a/tests/level_2_map_inline_string.json b/tests/level_2_map_inline_string.json new file mode 100644 index 0000000..12fb674 --- /dev/null +++ b/tests/level_2_map_inline_string.json @@ -0,0 +1,25 @@ +{ + "definitions": { + "Student": { + "type": "struct", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + }, + "age": { + "type": "integer" + }, + "properties": { + "type": "map", + "schema": { + "type": "string" + } + } + } + } + }, + "root": "Student" +} \ No newline at end of file diff --git a/tests/level_2_map_reference.json b/tests/level_2_map_reference.json new file mode 100644 index 0000000..7b4b350 --- /dev/null +++ b/tests/level_2_map_reference.json @@ -0,0 +1,41 @@ +{ + "definitions": { + "Student": { + "type": "struct", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + }, + "age": { + "type": "integer" + }, + "properties": { + "type": "reference", + "target": "Student_Map_Reference" + } + } + }, + "Student_Map_Reference": { + "type": "map", + "schema": { + "type": "reference", + "target": "Student_Property" + } + }, + "Student_Property": { + "type": "struct", + "properties": { + "name": { + "type": "string" + }, + "value": { + "type": "string" + } + } + } + }, + "root": "Student" +} \ No newline at end of file diff --git a/tests/level_2_map_string.json b/tests/level_2_map_string.json new file mode 100644 index 0000000..64b88ec --- /dev/null +++ b/tests/level_2_map_string.json @@ -0,0 +1,29 @@ +{ + "definitions": { + "Student": { + "type": "struct", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + }, + "age": { + "type": "integer" + }, + "properties": { + "type": "reference", + "target": "Student_Map_String" + } + } + }, + "Student_Map_String": { + "type": "map", + "schema": { + "type": "string" + } + } + }, + "root": "Student" +} \ No newline at end of file diff --git a/tests/level_3_inheritance.json b/tests/level_3_inheritance.json new file mode 100644 index 0000000..1cd64cf --- /dev/null +++ b/tests/level_3_inheritance.json @@ -0,0 +1,31 @@ +{ + "definitions": { + "Human": { + "type": "struct", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + }, + "age": { + "type": "integer" + } + } + }, + "Student": { + "parent": { + "type": "reference", + "target": "Human" + }, + "type": "struct", + "properties": { + "studentId": { + "type": "string" + } + } + } + }, + "root": "Student" +} \ No newline at end of file diff --git a/tests/level_4_generic.json b/tests/level_4_generic.json new file mode 100644 index 0000000..23ef1d5 --- /dev/null +++ b/tests/level_4_generic.json @@ -0,0 +1,38 @@ +{ + "definitions": { + "Student": { + "type": "struct", + "properties": { + "matricleNumber": { + "type": "integer" + } + } + }, + "StudentMap": { + "type": "struct", + "parent": { + "type": "reference", + "target": "Map", + "template": { + "T": "Student" + } + } + }, + "Map": { + "type": "struct", + "properties": { + "totalResults": { + "type": "integer" + }, + "entries": { + "type": "array", + "schema": { + "type": "generic", + "name": "T" + } + } + } + } + }, + "root": "StudentMap" +} \ No newline at end of file diff --git a/tests/level_5_discriminator.json b/tests/level_5_discriminator.json new file mode 100644 index 0000000..9dd9681 --- /dev/null +++ b/tests/level_5_discriminator.json @@ -0,0 +1,61 @@ +{ + "definitions": { + "Human": { + "type": "struct", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + }, + "location": { + "type": "reference", + "target": "Location" + } + } + }, + "Location": { + "type": "struct", + "base": true, + "properties": { + "type": { + "type": "string" + } + }, + "discriminator": "type", + "mapping": { + "Web": "web", + "World": "world" + } + }, + "Web": { + "parent": { + "type": "reference", + "target": "Location" + }, + "type": "struct", + "properties": { + "url": { + "type": "string" + } + } + }, + "World": { + "parent": { + "type": "reference", + "target": "Location" + }, + "type": "struct", + "properties": { + "lat": { + "type": "string" + }, + "long": { + "type": "string" + } + } + } + }, + "root": "Human" +} \ No newline at end of file