Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Nov 29, 2024
1 parent 7508ec6 commit ee612ff
Show file tree
Hide file tree
Showing 13 changed files with 458 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -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.
32 changes: 32 additions & 0 deletions tests/level_1_simple.json
Original file line number Diff line number Diff line change
@@ -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"
}
37 changes: 37 additions & 0 deletions tests/level_2_array_inline_reference.json
Original file line number Diff line number Diff line change
@@ -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"
}
25 changes: 25 additions & 0 deletions tests/level_2_array_inline_string.json
Original file line number Diff line number Diff line change
@@ -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"
}
41 changes: 41 additions & 0 deletions tests/level_2_array_reference.json
Original file line number Diff line number Diff line change
@@ -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"
}
29 changes: 29 additions & 0 deletions tests/level_2_array_string.json
Original file line number Diff line number Diff line change
@@ -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"
}
37 changes: 37 additions & 0 deletions tests/level_2_map_inline_reference.json
Original file line number Diff line number Diff line change
@@ -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"
}
25 changes: 25 additions & 0 deletions tests/level_2_map_inline_string.json
Original file line number Diff line number Diff line change
@@ -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"
}
41 changes: 41 additions & 0 deletions tests/level_2_map_reference.json
Original file line number Diff line number Diff line change
@@ -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"
}
29 changes: 29 additions & 0 deletions tests/level_2_map_string.json
Original file line number Diff line number Diff line change
@@ -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"
}
31 changes: 31 additions & 0 deletions tests/level_3_inheritance.json
Original file line number Diff line number Diff line change
@@ -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"
}
Loading

0 comments on commit ee612ff

Please sign in to comment.