1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: include float kind in struct field type defaults (#18228)

This commit is contained in:
Turiiya
2023-05-24 05:50:45 +02:00
committed by GitHub
parent 598673314b
commit e8046439f0
2 changed files with 50 additions and 35 deletions

View File

@@ -28,77 +28,92 @@ struct OmitEmptySumType {
bug MySum [omitempty]
}
fn main() {
test_struct()
test_alias()
test_map()
test_sumtype()
test_array()
struct FNumStruct {
f_num f64
}
struct OmitEmptyFNumStruct {
bug FNumStruct [omitempty]
}
fn test_struct() {
test2 := OmitEmptyStruct{
test := OmitEmptyStruct{
bug: Struct{}
}
encoded2 := json.encode(test2)
dump(encoded2)
test := OmitEmptyStruct{
encoded := json.encode(test)
dump(encoded)
test2 := OmitEmptyStruct{
bug: Struct{
name: 'mybug'
}
}
encoded2 := json.encode(test2)
dump(encoded2)
}
fn test_fnum_struct() {
test := OmitEmptyFNumStruct{
bug: FNumStruct{}
}
encoded := json.encode(test)
dump(encoded)
test2 := OmitEmptyFNumStruct{
bug: FNumStruct{
f_num: 1.5
}
}
encoded2 := json.encode(test2)
dump(encoded2)
}
fn test_alias() {
test3 := OmitEmptyAlias{
test := OmitEmptyAlias{
bug: ''
}
encoded3 := json.encode(test3)
dump(encoded3)
test4 := OmitEmptyAlias{
encoded := json.encode(test)
dump(encoded)
test2 := OmitEmptyAlias{
bug: 'foo'
}
encoded4 := json.encode(test4)
dump(encoded4)
encoded2 := json.encode(test2)
dump(encoded2)
}
fn test_map() {
test3 := OmitEmptyMap{
test := OmitEmptyMap{
bug: {}
}
encoded3 := json.encode(test3)
dump(encoded3)
test4 := OmitEmptyMap{
encoded := json.encode(test)
dump(encoded)
test2 := OmitEmptyMap{
bug: {
'foo': 'bar'
}
}
encoded4 := json.encode(test4)
dump(encoded4)
encoded2 := json.encode(test2)
dump(encoded2)
}
fn test_sumtype() {
test3 := OmitEmptySumType{}
encoded3 := json.encode(test3)
dump(encoded3)
test4 := OmitEmptySumType{
test := OmitEmptySumType{}
encoded := json.encode(test)
dump(encoded)
test2 := OmitEmptySumType{
bug: 1
}
encoded4 := json.encode(test4)
dump(encoded4)
encoded2 := json.encode(test2)
dump(encoded2)
}
fn test_array() {
test3 := OmitEmptyArray{
test := OmitEmptyArray{
bug: []
}
encoded3 := json.encode(test3)
dump(encoded3)
test4 := OmitEmptyArray{
encoded := json.encode(test)
dump(encoded)
test2 := OmitEmptyArray{
bug: ['1']
}
encoded4 := json.encode(test4)
dump(encoded4)
encoded2 := json.encode(test2)
dump(encoded2)
}