1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/x/json2/encode_struct_todo_test.vv
2023-01-09 09:36:45 +03:00

189 lines
9.6 KiB
V

import x.json2 as json
type StringAlias = string
type BoolAlias = bool
type IntAlias = int
type SumTypes = bool | int | string
struct StructType[T] {
mut:
val T
}
struct StructTypeOption[T] {
mut:
val ?T
}
struct StructTypePointer[T] {
mut:
val &T
}
fn test_option_alias() {
assert json.encode(StructTypeOption[BoolAlias]{ val: none }) == '{}'
assert json.encode(StructTypeOption[BoolAlias]{}) == '{"val":false}'
assert json.encode(StructTypeOption[BoolAlias]{ val: false }) == '{"val":false}'
assert json.encode(StructTypeOption[BoolAlias]{ val: true }) == '{"val":true}'
assert json.encode(StructTypeOption[IntAlias]{ val: none }) == '{}'
assert json.encode(StructTypeOption[IntAlias]{}) == '{"val":0}'
assert json.encode(StructTypeOption[IntAlias]{ val: 0 }) == '{"val":0}'
assert json.encode(StructTypeOption[IntAlias]{ val: 1 }) == '{"val":1}'
}
fn test_sumtypes() {
assert json.encode(StructType[SumTypes]{}) == '{}' // REVIEW
assert json.encode(StructType[SumTypes]{ val: '' }) == '{"val":""}'
assert json.encode(StructType[SumTypes]{ val: 'a' }) == '{"val":"a"}'
assert json.encode(StructType[SumTypes]{ val: false }) == '{"val":false}'
assert json.encode(StructType[SumTypes]{ val: true }) == '{"val":true}'
assert json.encode(StructType[SumTypes]{ val: 0 }) == '{"val":0}'
assert json.encode(StructType[SumTypes]{ val: 1 }) == '{"val":1}'
}
fn test_option_sumtypes() {
assert json.encode(StructTypeOption[SumTypes]{}) == '{}' // REVIEW
assert json.encode(StructTypeOption[SumTypes]{ val: '' }) == '{"val":""}'
assert json.encode(StructTypeOption[SumTypes]{ val: 'a' }) == '{"val":"a"}'
assert json.encode(StructTypeOption[SumTypes]{ val: false }) == '{"val":false}'
assert json.encode(StructTypeOption[SumTypes]{ val: true }) == '{"val":true}'
assert json.encode(StructTypeOption[SumTypes]{ val: 0 }) == '{"val":0}'
assert json.encode(StructTypeOption[SumTypes]{ val: 1 }) == '{"val":1}'
}
fn test_pointer() {
// mut string_initialized_with_reference := ""
assert json.encode(StructTypePointer[string]{ val: 0 }) == '{"val":""}' // REVIEW
assert json.encode(StructTypePointer[string]{ val: &string_initialized_with_reference }) == '{"val":""}'
string_initialized_with_reference = 'a'
assert json.encode(StructTypePointer[string]{ val: &string_initialized_with_reference }) == '{"val":"a"}'
mut bool_initialized_with_reference := false
assert json.encode(StructTypePointer[bool]{ val: 0 }) == '{"val":false}' // REVIEW
assert json.encode(StructTypePointer[bool]{ val: &bool_initialized_with_reference }) == '{"val":false}'
bool_initialized_with_reference = true
assert json.encode(StructTypePointer[bool]{ val: &bool_initialized_with_reference }) == '{"val":true}'
mut int_initialized_with_reference := 0
assert json.encode(StructTypePointer[int]{ val: 0 }) == '{"val":0}' // REVIEW
assert json.encode(StructTypePointer[int]{ val: &int_initialized_with_reference }) == '{"val":0}'
int_initialized_with_reference = 1
assert json.encode(StructTypePointer[int]{ val: &int_initialized_with_reference }) == '{"val":1}'
}
fn test_caos() {
typed_string_struct := StructType[string]{
val: 'a'
}
// StructType
assert json.encode(StructType[StructType]{}) == 'TODO'
assert json.encode(StructType[StructType[string]]{ val: typed_string_struct }) == 'TODO'
assert json.encode(StructType[StructType[StringAlias]]{ val: typed_string_struct }) == 'TODO'
assert json.encode(StructType[StructType[SumTypes]]{ val: typed_string_struct }) == 'TODO'
assert json.encode(StructType[StructTypeOption]{typed_string_struct}) == 'TODO'
assert json.encode(StructType[StructTypeOption[string]]{ val: StructType{'a'} }) == 'TODO'
assert json.encode(StructType[StructTypeOption[StringAlias]]{typed_string_struct}) == 'TODO'
assert json.encode(StructType[StructTypeOption[SumTypes]]{typed_string_struct}) == 'TODO'
assert json.encode(StructType[StructTypePointer]{typed_string_struct}) == 'TODO'
assert json.encode(StructType[StructTypePointer[string]]{typed_string_struct}) == 'TODO'
assert json.encode(StructType[StructTypePointer[StringAlias]]{typed_string_struct}) == 'TODO'
assert json.encode(StructType[StructTypePointer[SumTypes]]{typed_string_struct}) == 'TODO'
// StructTypeOptional
assert json.encode(StructTypeOption[StructType]{}) == 'TODO'
assert json.encode(StructTypeOption[StructType[string]]{ val: '' }) == 'TODO'
assert json.encode(StructTypeOption[StructType[StringAlias]]{ val: '' }) == 'TODO'
assert json.encode(StructTypeOption[StructType[SumTypes]]{ val: '' }) == 'TODO'
assert json.encode(StructTypeOption[StructTypeOption]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypeOption[StructTypeOption[string]]{ val: StructType{'a'} }) == 'TODO'
assert json.encode(StructTypeOption[StructTypeOption[StringAlias]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypeOption[StructTypeOption[SumTypes]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypeOption[StructTypePointer]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypeOption[StructTypePointer[string]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypeOption[StructTypePointer[StringAlias]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypeOption[StructTypePointer[SumTypes]]{typed_string_struct}) == 'TODO'
// StructTypePointer
assert json.encode(StructTypePointer[StructType]{}) == 'TODO'
assert json.encode(StructTypePointer[StructType[string]]{ val: '' }) == 'TODO'
assert json.encode(StructTypePointer[StructType[StringAlias]]{ val: '' }) == 'TODO'
assert json.encode(StructTypePointer[StructType[SumTypes]]{ val: '' }) == 'TODO'
assert json.encode(StructTypePointer[StructTypeOption]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypePointer[StructTypeOption[string]]{ val: StructType{'a'} }) == 'TODO'
assert json.encode(StructTypePointer[StructTypeOption[StringAlias]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypePointer[StructTypeOption[SumTypes]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypePointer[StructTypePointer]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypePointer[StructTypePointer[string]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypePointer[StructTypePointer[StringAlias]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypePointer[StructTypePointer[SumTypes]]{typed_string_struct}) == 'TODO'
}
fn test_caos_array() {
typed_string_struct := [StructType[string]{
val: 'a'
}]
// StructType
assert json.encode(StructType[[]StructType]{}) == 'TODO'
assert json.encode(StructType[[]StructType[string]]{ val: typed_string_struct }) == 'TODO'
assert json.encode(StructType[[]StructType[StringAlias]]{ val: typed_string_struct }) == 'TODO'
assert json.encode(StructType[[]StructType[SumTypes]]{ val: typed_string_struct }) == 'TODO'
assert json.encode(StructType[[]StructTypeOption]{typed_string_struct}) == 'TODO'
assert json.encode(StructType[[]StructTypeOption[string]]{ val: StructType{'a'} }) == 'TODO'
assert json.encode(StructType[[]StructTypeOption[StringAlias]]{typed_string_struct}) == 'TODO'
assert json.encode(StructType[[]StructTypeOption[SumTypes]]{typed_string_struct}) == 'TODO'
assert json.encode(StructType[[]StructTypePointer]{typed_string_struct}) == 'TODO'
assert json.encode(StructType[[]StructTypePointer[string]]{typed_string_struct}) == 'TODO'
assert json.encode(StructType[[]StructTypePointer[StringAlias]]{typed_string_struct}) == 'TODO'
assert json.encode(StructType[[]StructTypePointer[SumTypes]]{typed_string_struct}) == 'TODO'
// StructTypeOptional
assert json.encode(StructTypeOption[[]StructType]{}) == 'TODO'
assert json.encode(StructTypeOption[[]StructType[string]]{ val: '' }) == 'TODO'
assert json.encode(StructTypeOption[[]StructType[StringAlias]]{ val: '' }) == 'TODO'
assert json.encode(StructTypeOption[[]StructType[SumTypes]]{ val: '' }) == 'TODO'
assert json.encode(StructTypeOption[[]StructTypeOption]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypeOption[[]StructTypeOption[string]]{ val: StructType{'a'} }) == 'TODO'
assert json.encode(StructTypeOption[[]StructTypeOption[StringAlias]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypeOption[[]StructTypeOption[SumTypes]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypeOption[[]StructTypePointer]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypeOption[[]StructTypePointer[string]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypeOption[[]StructTypePointer[StringAlias]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypeOption[[]StructTypePointer[SumTypes]]{typed_string_struct}) == 'TODO'
// StructTypePointer
assert json.encode(StructTypePointer[[]StructType]{}) == 'TODO'
assert json.encode(StructTypePointer[[]StructType[string]]{ val: '' }) == 'TODO'
assert json.encode(StructTypePointer[[]StructType[StringAlias]]{ val: '' }) == 'TODO'
assert json.encode(StructTypePointer[[]StructType[SumTypes]]{ val: '' }) == 'TODO'
assert json.encode(StructTypePointer[[]StructTypeOption]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypePointer[[]StructTypeOption[string]]{ val: StructType{'a'} }) == 'TODO'
assert json.encode(StructTypePointer[[]StructTypeOption[StringAlias]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypePointer[[]StructTypeOption[SumTypes]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypePointer[[]StructTypePointer]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypePointer[[]StructTypePointer[string]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypePointer[[]StructTypePointer[StringAlias]]{typed_string_struct}) == 'TODO'
assert json.encode(StructTypePointer[[]StructTypePointer[SumTypes]]{typed_string_struct}) == 'TODO'
}