2015-10-28 02:15:15 +01:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package proptools
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-05-06 00:58:02 +02:00
|
|
|
type appendPropertyTestCase struct {
|
2021-05-21 23:56:53 +02:00
|
|
|
name string
|
|
|
|
dst interface{}
|
|
|
|
src interface{}
|
2019-11-15 10:31:56 +01:00
|
|
|
out interface{}
|
|
|
|
order Order // default is Append
|
|
|
|
filter ExtendPropertyFilterFunc
|
|
|
|
err error
|
2016-05-06 00:58:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func appendPropertiesTestCases() []appendPropertyTestCase {
|
|
|
|
return []appendPropertyTestCase{
|
|
|
|
// Valid inputs
|
|
|
|
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append bool",
|
|
|
|
dst: &struct{ B1, B2, B3, B4 bool }{
|
2016-05-06 00:58:02 +02:00
|
|
|
B1: true,
|
|
|
|
B2: false,
|
|
|
|
B3: true,
|
|
|
|
B4: false,
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ B1, B2, B3, B4 bool }{
|
2016-05-06 00:58:02 +02:00
|
|
|
B1: true,
|
|
|
|
B2: true,
|
|
|
|
B3: false,
|
|
|
|
B4: false,
|
|
|
|
},
|
|
|
|
out: &struct{ B1, B2, B3, B4 bool }{
|
|
|
|
B1: true,
|
|
|
|
B2: true,
|
|
|
|
B3: true,
|
|
|
|
B4: false,
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Prepend bool",
|
|
|
|
dst: &struct{ B1, B2, B3, B4 bool }{
|
2016-05-06 00:58:02 +02:00
|
|
|
B1: true,
|
|
|
|
B2: false,
|
|
|
|
B3: true,
|
|
|
|
B4: false,
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ B1, B2, B3, B4 bool }{
|
2016-05-06 00:58:02 +02:00
|
|
|
B1: true,
|
|
|
|
B2: true,
|
|
|
|
B3: false,
|
|
|
|
B4: false,
|
|
|
|
},
|
|
|
|
out: &struct{ B1, B2, B3, B4 bool }{
|
|
|
|
B1: true,
|
|
|
|
B2: true,
|
|
|
|
B3: true,
|
|
|
|
B4: false,
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2019-11-15 10:31:56 +01:00
|
|
|
order: Prepend,
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append strings",
|
|
|
|
dst: &struct{ S string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string1",
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
out: &struct{ S string }{
|
2015-10-28 02:15:15 +01:00
|
|
|
S: "string1string2",
|
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Prepend strings",
|
|
|
|
dst: &struct{ S string }{
|
2015-10-28 02:15:15 +01:00
|
|
|
S: "string1",
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S string }{
|
2015-10-28 02:15:15 +01:00
|
|
|
S: "string2",
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
out: &struct{ S string }{
|
2015-10-28 02:15:15 +01:00
|
|
|
S: "string2string1",
|
|
|
|
},
|
2019-11-15 10:31:56 +01:00
|
|
|
order: Prepend,
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append pointer to bool",
|
|
|
|
dst: &struct{ B1, B2, B3, B4, B5, B6, B7, B8, B9 *bool }{
|
2016-05-06 00:58:02 +02:00
|
|
|
B1: BoolPtr(true),
|
|
|
|
B2: BoolPtr(false),
|
|
|
|
B3: nil,
|
|
|
|
B4: BoolPtr(true),
|
|
|
|
B5: BoolPtr(false),
|
|
|
|
B6: nil,
|
|
|
|
B7: BoolPtr(true),
|
|
|
|
B8: BoolPtr(false),
|
|
|
|
B9: nil,
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ B1, B2, B3, B4, B5, B6, B7, B8, B9 *bool }{
|
2016-05-06 00:58:02 +02:00
|
|
|
B1: nil,
|
|
|
|
B2: nil,
|
|
|
|
B3: nil,
|
|
|
|
B4: BoolPtr(true),
|
|
|
|
B5: BoolPtr(true),
|
|
|
|
B6: BoolPtr(true),
|
|
|
|
B7: BoolPtr(false),
|
|
|
|
B8: BoolPtr(false),
|
|
|
|
B9: BoolPtr(false),
|
|
|
|
},
|
|
|
|
out: &struct{ B1, B2, B3, B4, B5, B6, B7, B8, B9 *bool }{
|
|
|
|
B1: BoolPtr(true),
|
|
|
|
B2: BoolPtr(false),
|
|
|
|
B3: nil,
|
|
|
|
B4: BoolPtr(true),
|
|
|
|
B5: BoolPtr(true),
|
|
|
|
B6: BoolPtr(true),
|
|
|
|
B7: BoolPtr(false),
|
|
|
|
B8: BoolPtr(false),
|
|
|
|
B9: BoolPtr(false),
|
|
|
|
},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Prepend pointer to bool",
|
|
|
|
dst: &struct{ B1, B2, B3, B4, B5, B6, B7, B8, B9 *bool }{
|
2016-05-06 00:58:02 +02:00
|
|
|
B1: BoolPtr(true),
|
|
|
|
B2: BoolPtr(false),
|
|
|
|
B3: nil,
|
|
|
|
B4: BoolPtr(true),
|
|
|
|
B5: BoolPtr(false),
|
|
|
|
B6: nil,
|
|
|
|
B7: BoolPtr(true),
|
|
|
|
B8: BoolPtr(false),
|
|
|
|
B9: nil,
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ B1, B2, B3, B4, B5, B6, B7, B8, B9 *bool }{
|
2016-05-06 00:58:02 +02:00
|
|
|
B1: nil,
|
|
|
|
B2: nil,
|
|
|
|
B3: nil,
|
|
|
|
B4: BoolPtr(true),
|
|
|
|
B5: BoolPtr(true),
|
|
|
|
B6: BoolPtr(true),
|
|
|
|
B7: BoolPtr(false),
|
|
|
|
B8: BoolPtr(false),
|
|
|
|
B9: BoolPtr(false),
|
|
|
|
},
|
|
|
|
out: &struct{ B1, B2, B3, B4, B5, B6, B7, B8, B9 *bool }{
|
|
|
|
B1: BoolPtr(true),
|
|
|
|
B2: BoolPtr(false),
|
|
|
|
B3: nil,
|
|
|
|
B4: BoolPtr(true),
|
|
|
|
B5: BoolPtr(false),
|
|
|
|
B6: BoolPtr(true),
|
|
|
|
B7: BoolPtr(true),
|
|
|
|
B8: BoolPtr(false),
|
|
|
|
B9: BoolPtr(false),
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2019-11-15 10:31:56 +01:00
|
|
|
order: Prepend,
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append pointer to integer",
|
|
|
|
dst: &struct{ I1, I2, I3, I4, I5, I6, I7, I8, I9 *int64 }{
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I1: Int64Ptr(55),
|
|
|
|
I2: Int64Ptr(-3),
|
|
|
|
I3: nil,
|
|
|
|
I4: Int64Ptr(100),
|
|
|
|
I5: Int64Ptr(33),
|
|
|
|
I6: nil,
|
|
|
|
I7: Int64Ptr(77),
|
|
|
|
I8: Int64Ptr(0),
|
|
|
|
I9: nil,
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ I1, I2, I3, I4, I5, I6, I7, I8, I9 *int64 }{
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I1: nil,
|
|
|
|
I2: nil,
|
|
|
|
I3: nil,
|
|
|
|
I4: Int64Ptr(1),
|
|
|
|
I5: Int64Ptr(-2),
|
|
|
|
I6: Int64Ptr(8),
|
|
|
|
I7: Int64Ptr(9),
|
|
|
|
I8: Int64Ptr(10),
|
|
|
|
I9: Int64Ptr(11),
|
|
|
|
},
|
|
|
|
out: &struct{ I1, I2, I3, I4, I5, I6, I7, I8, I9 *int64 }{
|
|
|
|
I1: Int64Ptr(55),
|
|
|
|
I2: Int64Ptr(-3),
|
|
|
|
I3: nil,
|
|
|
|
I4: Int64Ptr(1),
|
|
|
|
I5: Int64Ptr(-2),
|
|
|
|
I6: Int64Ptr(8),
|
|
|
|
I7: Int64Ptr(9),
|
|
|
|
I8: Int64Ptr(10),
|
|
|
|
I9: Int64Ptr(11),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Prepend pointer to integer",
|
|
|
|
dst: &struct{ I1, I2, I3 *int64 }{
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I1: Int64Ptr(55),
|
|
|
|
I3: nil,
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ I1, I2, I3 *int64 }{
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I2: Int64Ptr(33),
|
|
|
|
},
|
|
|
|
out: &struct{ I1, I2, I3 *int64 }{
|
|
|
|
I1: Int64Ptr(55),
|
|
|
|
I2: Int64Ptr(33),
|
|
|
|
I3: nil,
|
|
|
|
},
|
2019-11-15 10:31:56 +01:00
|
|
|
order: Prepend,
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append pointer to strings",
|
|
|
|
dst: &struct{ S1, S2, S3, S4 *string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S1: StringPtr("string1"),
|
|
|
|
S2: StringPtr("string2"),
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S1, S2, S3, S4 *string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S1: StringPtr("string3"),
|
|
|
|
S3: StringPtr("string4"),
|
|
|
|
},
|
|
|
|
out: &struct{ S1, S2, S3, S4 *string }{
|
|
|
|
S1: StringPtr("string3"),
|
|
|
|
S2: StringPtr("string2"),
|
|
|
|
S3: StringPtr("string4"),
|
|
|
|
S4: nil,
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Prepend pointer to strings",
|
|
|
|
dst: &struct{ S1, S2, S3, S4 *string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S1: StringPtr("string1"),
|
|
|
|
S2: StringPtr("string2"),
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S1, S2, S3, S4 *string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S1: StringPtr("string3"),
|
|
|
|
S3: StringPtr("string4"),
|
|
|
|
},
|
|
|
|
out: &struct{ S1, S2, S3, S4 *string }{
|
|
|
|
S1: StringPtr("string1"),
|
|
|
|
S2: StringPtr("string2"),
|
|
|
|
S3: StringPtr("string4"),
|
|
|
|
S4: nil,
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2019-11-15 10:31:56 +01:00
|
|
|
order: Prepend,
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append slice",
|
|
|
|
dst: &struct{ S []string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: []string{"string1"},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S []string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: []string{"string2"},
|
|
|
|
},
|
|
|
|
out: &struct{ S []string }{
|
|
|
|
S: []string{"string1", "string2"},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Prepend slice",
|
|
|
|
dst: &struct{ S []string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: []string{"string1"},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S []string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: []string{"string2"},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
out: &struct{ S []string }{
|
|
|
|
S: []string{"string2", "string1"},
|
|
|
|
},
|
2019-11-15 10:31:56 +01:00
|
|
|
order: Prepend,
|
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Replace slice",
|
|
|
|
dst: &struct{ S []string }{
|
2019-11-15 10:31:56 +01:00
|
|
|
S: []string{"string1"},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S []string }{
|
2019-11-15 10:31:56 +01:00
|
|
|
S: []string{"string2"},
|
|
|
|
},
|
|
|
|
out: &struct{ S []string }{
|
|
|
|
S: []string{"string2"},
|
|
|
|
},
|
|
|
|
order: Replace,
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append empty slice",
|
|
|
|
dst: &struct{ S1, S2 []string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S1: []string{"string1"},
|
|
|
|
S2: []string{},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S1, S2 []string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S1: []string{},
|
|
|
|
S2: []string{"string2"},
|
|
|
|
},
|
|
|
|
out: &struct{ S1, S2 []string }{
|
|
|
|
S1: []string{"string1"},
|
|
|
|
S2: []string{"string2"},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Prepend empty slice",
|
|
|
|
dst: &struct{ S1, S2 []string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S1: []string{"string1"},
|
|
|
|
S2: []string{},
|
2015-11-21 02:03:25 +01:00
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S1, S2 []string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S1: []string{},
|
|
|
|
S2: []string{"string2"},
|
|
|
|
},
|
|
|
|
out: &struct{ S1, S2 []string }{
|
|
|
|
S1: []string{"string1"},
|
|
|
|
S2: []string{"string2"},
|
2015-11-21 02:03:25 +01:00
|
|
|
},
|
2019-11-15 10:31:56 +01:00
|
|
|
order: Prepend,
|
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Replace empty slice",
|
|
|
|
dst: &struct{ S1, S2 []string }{
|
2019-11-15 10:31:56 +01:00
|
|
|
S1: []string{"string1"},
|
|
|
|
S2: []string{},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S1, S2 []string }{
|
2019-11-15 10:31:56 +01:00
|
|
|
S1: []string{},
|
|
|
|
S2: []string{"string2"},
|
|
|
|
},
|
|
|
|
out: &struct{ S1, S2 []string }{
|
|
|
|
S1: []string{},
|
|
|
|
S2: []string{"string2"},
|
|
|
|
},
|
|
|
|
order: Replace,
|
2015-11-21 02:03:25 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append nil slice",
|
|
|
|
dst: &struct{ S1, S2, S3 []string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S1: []string{"string1"},
|
2015-11-21 02:03:25 +01:00
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S1, S2, S3 []string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S2: []string{"string2"},
|
|
|
|
},
|
|
|
|
out: &struct{ S1, S2, S3 []string }{
|
|
|
|
S1: []string{"string1"},
|
|
|
|
S2: []string{"string2"},
|
|
|
|
S3: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Prepend nil slice",
|
|
|
|
dst: &struct{ S1, S2, S3 []string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S1: []string{"string1"},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S1, S2, S3 []string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S2: []string{"string2"},
|
|
|
|
},
|
|
|
|
out: &struct{ S1, S2, S3 []string }{
|
|
|
|
S1: []string{"string1"},
|
|
|
|
S2: []string{"string2"},
|
|
|
|
S3: nil,
|
|
|
|
},
|
2019-11-15 10:31:56 +01:00
|
|
|
order: Prepend,
|
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Replace nil slice",
|
|
|
|
dst: &struct{ S1, S2, S3 []string }{
|
2019-11-15 10:31:56 +01:00
|
|
|
S1: []string{"string1"},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S1, S2, S3 []string }{
|
2019-11-15 10:31:56 +01:00
|
|
|
S2: []string{"string2"},
|
|
|
|
},
|
|
|
|
out: &struct{ S1, S2, S3 []string }{
|
|
|
|
S1: []string{"string1"},
|
|
|
|
S2: []string{"string2"},
|
|
|
|
S3: nil,
|
|
|
|
},
|
|
|
|
order: Replace,
|
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Replace embedded slice",
|
|
|
|
dst: &struct{ S *struct{ S1 []string } }{
|
2019-11-15 10:31:56 +01:00
|
|
|
S: &struct{ S1 []string }{
|
|
|
|
S1: []string{"string1"},
|
|
|
|
},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S *struct{ S1 []string } }{
|
2019-11-15 10:31:56 +01:00
|
|
|
S: &struct{ S1 []string }{
|
|
|
|
S1: []string{"string2"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct{ S *struct{ S1 []string } }{
|
|
|
|
S: &struct{ S1 []string }{
|
|
|
|
S1: []string{"string2"},
|
|
|
|
},
|
Implement list of maps
Allow property value to be a list of maps, e.g.
my_module {
my_list: [
{ name: "foo", value: 42, something: true, },
{ name: "bar", value: 34, something: false, },
],
}
Test: internal
Change-Id: I2fc37d692aac39f23c9aa7bda2859ab49f3bc672
2020-02-12 07:39:47 +01:00
|
|
|
},
|
|
|
|
order: Replace,
|
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append slice of structs",
|
|
|
|
dst: &struct{ S []struct{ F string } }{
|
Implement list of maps
Allow property value to be a list of maps, e.g.
my_module {
my_list: [
{ name: "foo", value: 42, something: true, },
{ name: "bar", value: 34, something: false, },
],
}
Test: internal
Change-Id: I2fc37d692aac39f23c9aa7bda2859ab49f3bc672
2020-02-12 07:39:47 +01:00
|
|
|
S: []struct{ F string }{
|
|
|
|
{F: "foo"}, {F: "bar"},
|
|
|
|
},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S []struct{ F string } }{
|
Implement list of maps
Allow property value to be a list of maps, e.g.
my_module {
my_list: [
{ name: "foo", value: 42, something: true, },
{ name: "bar", value: 34, something: false, },
],
}
Test: internal
Change-Id: I2fc37d692aac39f23c9aa7bda2859ab49f3bc672
2020-02-12 07:39:47 +01:00
|
|
|
S: []struct{ F string }{
|
|
|
|
{F: "baz"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct{ S []struct{ F string } }{
|
|
|
|
S: []struct{ F string }{
|
|
|
|
{F: "foo"}, {F: "bar"}, {F: "baz"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
order: Append,
|
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Prepend slice of structs",
|
|
|
|
dst: &struct{ S []struct{ F string } }{
|
Implement list of maps
Allow property value to be a list of maps, e.g.
my_module {
my_list: [
{ name: "foo", value: 42, something: true, },
{ name: "bar", value: 34, something: false, },
],
}
Test: internal
Change-Id: I2fc37d692aac39f23c9aa7bda2859ab49f3bc672
2020-02-12 07:39:47 +01:00
|
|
|
S: []struct{ F string }{
|
|
|
|
{F: "foo"}, {F: "bar"},
|
|
|
|
},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S []struct{ F string } }{
|
Implement list of maps
Allow property value to be a list of maps, e.g.
my_module {
my_list: [
{ name: "foo", value: 42, something: true, },
{ name: "bar", value: 34, something: false, },
],
}
Test: internal
Change-Id: I2fc37d692aac39f23c9aa7bda2859ab49f3bc672
2020-02-12 07:39:47 +01:00
|
|
|
S: []struct{ F string }{
|
|
|
|
{F: "baz"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct{ S []struct{ F string } }{
|
|
|
|
S: []struct{ F string }{
|
|
|
|
{F: "baz"}, {F: "foo"}, {F: "bar"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
order: Prepend,
|
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append map",
|
|
|
|
dst: &struct{ S map[string]string }{
|
|
|
|
S: map[string]string{
|
|
|
|
"key0": "",
|
|
|
|
"key1": "dst_value1",
|
|
|
|
"key2": "dst_value2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
src: &struct{ S map[string]string }{
|
|
|
|
S: map[string]string{
|
|
|
|
"key0": "src_value0",
|
|
|
|
"key1": "src_value1",
|
|
|
|
"key3": "src_value3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct{ S map[string]string }{
|
|
|
|
S: map[string]string{
|
|
|
|
"key0": "src_value0",
|
|
|
|
"key1": "src_value1",
|
|
|
|
"key2": "dst_value2",
|
|
|
|
"key3": "src_value3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
order: Append,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Prepend map",
|
|
|
|
dst: &struct{ S map[string]string }{
|
|
|
|
S: map[string]string{
|
|
|
|
"key0": "",
|
|
|
|
"key1": "dst_value1",
|
|
|
|
"key2": "dst_value2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
src: &struct{ S map[string]string }{
|
|
|
|
S: map[string]string{
|
|
|
|
"key0": "src_value0",
|
|
|
|
"key1": "src_value1",
|
|
|
|
"key3": "src_value3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct{ S map[string]string }{
|
|
|
|
S: map[string]string{
|
|
|
|
"key0": "",
|
|
|
|
"key1": "dst_value1",
|
|
|
|
"key2": "dst_value2",
|
|
|
|
"key3": "src_value3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
order: Prepend,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Replace map",
|
|
|
|
dst: &struct{ S map[string]string }{
|
|
|
|
S: map[string]string{
|
|
|
|
"key0": "",
|
|
|
|
"key1": "dst_value1",
|
|
|
|
"key2": "dst_value2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
src: &struct{ S map[string]string }{
|
|
|
|
S: map[string]string{
|
|
|
|
"key0": "src_value0",
|
|
|
|
"key1": "src_value1",
|
|
|
|
"key3": "src_value3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct{ S map[string]string }{
|
|
|
|
S: map[string]string{
|
|
|
|
"key0": "src_value0",
|
|
|
|
"key1": "src_value1",
|
|
|
|
"key3": "src_value3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
order: Replace,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Append empty map",
|
|
|
|
dst: &struct{ S1, S2 map[string]string }{
|
|
|
|
S1: map[string]string{"key0": "dst_value0"},
|
|
|
|
S2: map[string]string{},
|
|
|
|
},
|
|
|
|
src: &struct{ S1, S2 map[string]string }{
|
|
|
|
S1: map[string]string{},
|
|
|
|
S2: map[string]string{"key0": "src_value0"},
|
|
|
|
},
|
|
|
|
out: &struct{ S1, S2 map[string]string }{
|
|
|
|
S1: map[string]string{"key0": "dst_value0"},
|
|
|
|
S2: map[string]string{"key0": "src_value0"},
|
|
|
|
},
|
|
|
|
order: Append,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Prepend empty map",
|
|
|
|
dst: &struct{ S1, S2 map[string]string }{
|
|
|
|
S1: map[string]string{"key0": "dst_value0"},
|
|
|
|
S2: map[string]string{},
|
|
|
|
},
|
|
|
|
src: &struct{ S1, S2 map[string]string }{
|
|
|
|
S1: map[string]string{},
|
|
|
|
S2: map[string]string{"key0": "src_value0"},
|
|
|
|
},
|
|
|
|
out: &struct{ S1, S2 map[string]string }{
|
|
|
|
S1: map[string]string{"key0": "dst_value0"},
|
|
|
|
S2: map[string]string{"key0": "src_value0"},
|
|
|
|
},
|
|
|
|
order: Prepend,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Replace empty map",
|
|
|
|
dst: &struct{ S1, S2 map[string]string }{
|
|
|
|
S1: map[string]string{"key0": "dst_value0"},
|
|
|
|
S2: map[string]string{},
|
|
|
|
},
|
|
|
|
src: &struct{ S1, S2 map[string]string }{
|
|
|
|
S1: map[string]string{},
|
|
|
|
S2: map[string]string{"key0": "src_value0"},
|
|
|
|
},
|
|
|
|
out: &struct{ S1, S2 map[string]string }{
|
|
|
|
S1: map[string]string{},
|
|
|
|
S2: map[string]string{"key0": "src_value0"},
|
|
|
|
},
|
|
|
|
order: Replace,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Append nil map",
|
|
|
|
dst: &struct{ S1, S2, S3 map[string]string }{
|
|
|
|
S1: map[string]string{"key0": "dst_value0"},
|
|
|
|
},
|
|
|
|
src: &struct{ S1, S2, S3 map[string]string }{
|
|
|
|
S2: map[string]string{"key0": "src_value0"},
|
|
|
|
},
|
|
|
|
out: &struct{ S1, S2, S3 map[string]string }{
|
|
|
|
S1: map[string]string{"key0": "dst_value0"},
|
|
|
|
S2: map[string]string{"key0": "src_value0"},
|
|
|
|
},
|
|
|
|
order: Append,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Prepend nil map",
|
|
|
|
dst: &struct{ S1, S2, S3 map[string]string }{
|
|
|
|
S1: map[string]string{"key0": "dst_value0"},
|
|
|
|
},
|
|
|
|
src: &struct{ S1, S2, S3 map[string]string }{
|
|
|
|
S2: map[string]string{"key0": "src_value0"},
|
|
|
|
},
|
|
|
|
out: &struct{ S1, S2, S3 map[string]string }{
|
|
|
|
S1: map[string]string{"key0": "dst_value0"},
|
|
|
|
S2: map[string]string{"key0": "src_value0"},
|
|
|
|
},
|
|
|
|
order: Prepend,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Replace nil map",
|
|
|
|
dst: &struct{ S1, S2, S3 map[string]string }{
|
|
|
|
S1: map[string]string{"key0": "dst_value0"},
|
|
|
|
},
|
|
|
|
src: &struct{ S1, S2, S3 map[string]string }{
|
|
|
|
S2: map[string]string{"key0": "src_value0"},
|
|
|
|
},
|
|
|
|
out: &struct{ S1, S2, S3 map[string]string }{
|
|
|
|
S1: map[string]string{"key0": "dst_value0"},
|
|
|
|
S2: map[string]string{"key0": "src_value0"},
|
|
|
|
S3: nil,
|
|
|
|
},
|
|
|
|
order: Replace,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Replace slice of structs",
|
|
|
|
dst: &struct{ S []struct{ F string } }{
|
Implement list of maps
Allow property value to be a list of maps, e.g.
my_module {
my_list: [
{ name: "foo", value: 42, something: true, },
{ name: "bar", value: 34, something: false, },
],
}
Test: internal
Change-Id: I2fc37d692aac39f23c9aa7bda2859ab49f3bc672
2020-02-12 07:39:47 +01:00
|
|
|
S: []struct{ F string }{
|
|
|
|
{F: "foo"}, {F: "bar"},
|
|
|
|
},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S []struct{ F string } }{
|
Implement list of maps
Allow property value to be a list of maps, e.g.
my_module {
my_list: [
{ name: "foo", value: 42, something: true, },
{ name: "bar", value: 34, something: false, },
],
}
Test: internal
Change-Id: I2fc37d692aac39f23c9aa7bda2859ab49f3bc672
2020-02-12 07:39:47 +01:00
|
|
|
S: []struct{ F string }{
|
|
|
|
{F: "baz"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct{ S []struct{ F string } }{
|
|
|
|
S: []struct{ F string }{
|
|
|
|
{F: "baz"},
|
|
|
|
},
|
2019-11-15 10:31:56 +01:00
|
|
|
},
|
|
|
|
order: Replace,
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append pointer",
|
|
|
|
dst: &struct{ S *struct{ S string } }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &struct{ S string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S *struct{ S string } }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &struct{ S string }{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct{ S *struct{ S string } }{
|
|
|
|
S: &struct{ S string }{
|
|
|
|
S: "string1string2",
|
2015-11-21 02:03:25 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Prepend pointer",
|
|
|
|
dst: &struct{ S *struct{ S string } }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &struct{ S string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
2015-11-21 02:03:25 +01:00
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S *struct{ S string } }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &struct{ S string }{
|
|
|
|
S: "string2",
|
2015-11-21 02:03:25 +01:00
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
out: &struct{ S *struct{ S string } }{
|
|
|
|
S: &struct{ S string }{
|
|
|
|
S: "string2string1",
|
|
|
|
},
|
|
|
|
},
|
2019-11-15 10:31:56 +01:00
|
|
|
order: Prepend,
|
2015-11-21 02:03:25 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append interface",
|
|
|
|
dst: &struct{ S interface{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &struct{ S string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
2015-11-21 02:03:25 +01:00
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S interface{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &struct{ S string }{
|
2015-11-21 02:03:25 +01:00
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
out: &struct{ S interface{} }{
|
|
|
|
S: &struct{ S string }{
|
|
|
|
S: "string1string2",
|
|
|
|
},
|
|
|
|
},
|
2015-11-21 02:03:25 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Prepend interface",
|
|
|
|
dst: &struct{ S interface{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &struct{ S string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
2015-11-21 02:03:25 +01:00
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S interface{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &struct{ S string }{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct{ S interface{} }{
|
|
|
|
S: &struct{ S string }{
|
|
|
|
S: "string2string1",
|
2015-11-21 02:03:25 +01:00
|
|
|
},
|
|
|
|
},
|
2019-11-15 10:31:56 +01:00
|
|
|
order: Prepend,
|
2015-11-21 02:03:25 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Unexported field",
|
|
|
|
dst: &struct{ s string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
s: "string1",
|
2015-11-21 02:03:25 +01:00
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ s string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
s: "string2",
|
|
|
|
},
|
|
|
|
out: &struct{ s string }{
|
|
|
|
s: "string1",
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
|
|
|
},
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Unexported field",
|
|
|
|
dst: &struct{ i *int64 }{
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
i: Int64Ptr(33),
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ i *int64 }{
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
i: Int64Ptr(5),
|
|
|
|
},
|
|
|
|
out: &struct{ i *int64 }{
|
|
|
|
i: Int64Ptr(33),
|
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Empty struct",
|
|
|
|
dst: &struct{}{},
|
|
|
|
src: &struct{}{},
|
|
|
|
out: &struct{}{},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Interface nil",
|
|
|
|
dst: &struct{ S interface{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: nil,
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S interface{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: nil,
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
out: &struct{ S interface{} }{
|
|
|
|
S: nil,
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Pointer nil",
|
|
|
|
dst: &struct{ S *struct{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: nil,
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S *struct{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: nil,
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
out: &struct{ S *struct{} }{
|
|
|
|
S: nil,
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Anonymous struct",
|
|
|
|
dst: &struct {
|
2016-05-06 00:58:02 +02:00
|
|
|
EmbeddedStruct
|
|
|
|
Nested struct{ EmbeddedStruct }
|
|
|
|
}{
|
|
|
|
EmbeddedStruct: EmbeddedStruct{
|
|
|
|
S: "string1",
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I: Int64Ptr(55),
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
Nested: struct{ EmbeddedStruct }{
|
|
|
|
EmbeddedStruct: EmbeddedStruct{
|
|
|
|
S: "string2",
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I: Int64Ptr(-4),
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct {
|
2016-05-06 00:58:02 +02:00
|
|
|
EmbeddedStruct
|
|
|
|
Nested struct{ EmbeddedStruct }
|
|
|
|
}{
|
|
|
|
EmbeddedStruct: EmbeddedStruct{
|
|
|
|
S: "string3",
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I: Int64Ptr(66),
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
Nested: struct{ EmbeddedStruct }{
|
|
|
|
EmbeddedStruct: EmbeddedStruct{
|
|
|
|
S: "string4",
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I: Int64Ptr(-8),
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
out: &struct {
|
|
|
|
EmbeddedStruct
|
|
|
|
Nested struct{ EmbeddedStruct }
|
|
|
|
}{
|
|
|
|
EmbeddedStruct: EmbeddedStruct{
|
|
|
|
S: "string1string3",
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I: Int64Ptr(66),
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
Nested: struct{ EmbeddedStruct }{
|
|
|
|
EmbeddedStruct: EmbeddedStruct{
|
|
|
|
S: "string2string4",
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I: Int64Ptr(-8),
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
|
|
|
},
|
2021-06-26 01:44:30 +02:00
|
|
|
{
|
|
|
|
name: "BlueprintEmbed struct",
|
|
|
|
dst: &struct {
|
|
|
|
BlueprintEmbed EmbeddedStruct
|
|
|
|
Nested struct{ BlueprintEmbed EmbeddedStruct }
|
|
|
|
}{
|
|
|
|
BlueprintEmbed: EmbeddedStruct{
|
|
|
|
S: "string1",
|
|
|
|
I: Int64Ptr(55),
|
|
|
|
},
|
|
|
|
Nested: struct{ BlueprintEmbed EmbeddedStruct }{
|
|
|
|
BlueprintEmbed: EmbeddedStruct{
|
|
|
|
S: "string2",
|
|
|
|
I: Int64Ptr(-4),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
src: &struct {
|
|
|
|
BlueprintEmbed EmbeddedStruct
|
|
|
|
Nested struct{ BlueprintEmbed EmbeddedStruct }
|
|
|
|
}{
|
|
|
|
BlueprintEmbed: EmbeddedStruct{
|
|
|
|
S: "string3",
|
|
|
|
I: Int64Ptr(66),
|
|
|
|
},
|
|
|
|
Nested: struct{ BlueprintEmbed EmbeddedStruct }{
|
|
|
|
BlueprintEmbed: EmbeddedStruct{
|
|
|
|
S: "string4",
|
|
|
|
I: Int64Ptr(-8),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct {
|
|
|
|
BlueprintEmbed EmbeddedStruct
|
|
|
|
Nested struct{ BlueprintEmbed EmbeddedStruct }
|
|
|
|
}{
|
|
|
|
BlueprintEmbed: EmbeddedStruct{
|
|
|
|
S: "string1string3",
|
|
|
|
I: Int64Ptr(66),
|
|
|
|
},
|
|
|
|
Nested: struct{ BlueprintEmbed EmbeddedStruct }{
|
|
|
|
BlueprintEmbed: EmbeddedStruct{
|
|
|
|
S: "string2string4",
|
|
|
|
I: Int64Ptr(-8),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Anonymous interface",
|
|
|
|
dst: &struct {
|
2016-05-06 00:58:02 +02:00
|
|
|
EmbeddedInterface
|
|
|
|
Nested struct{ EmbeddedInterface }
|
|
|
|
}{
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
EmbeddedInterface: &struct {
|
|
|
|
S string
|
|
|
|
I *int64
|
|
|
|
}{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string1",
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I: Int64Ptr(-8),
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
Nested: struct{ EmbeddedInterface }{
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
EmbeddedInterface: &struct {
|
|
|
|
S string
|
|
|
|
I *int64
|
|
|
|
}{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string2",
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I: Int64Ptr(55),
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct {
|
2016-05-06 00:58:02 +02:00
|
|
|
EmbeddedInterface
|
|
|
|
Nested struct{ EmbeddedInterface }
|
|
|
|
}{
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
EmbeddedInterface: &struct {
|
|
|
|
S string
|
|
|
|
I *int64
|
|
|
|
}{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string3",
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I: Int64Ptr(6),
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
Nested: struct{ EmbeddedInterface }{
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
EmbeddedInterface: &struct {
|
|
|
|
S string
|
|
|
|
I *int64
|
|
|
|
}{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string4",
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I: Int64Ptr(6),
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct {
|
|
|
|
EmbeddedInterface
|
|
|
|
Nested struct{ EmbeddedInterface }
|
|
|
|
}{
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
EmbeddedInterface: &struct {
|
|
|
|
S string
|
|
|
|
I *int64
|
|
|
|
}{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string1string3",
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I: Int64Ptr(6),
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
Nested: struct{ EmbeddedInterface }{
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
EmbeddedInterface: &struct {
|
|
|
|
S string
|
|
|
|
I *int64
|
|
|
|
}{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string2string4",
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I: Int64Ptr(6),
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-08-06 02:19:36 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Nil pointer to a struct",
|
|
|
|
dst: &struct {
|
2016-08-06 02:19:36 +02:00
|
|
|
Nested *struct {
|
|
|
|
S string
|
|
|
|
}
|
|
|
|
}{},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct {
|
2016-08-06 02:19:36 +02:00
|
|
|
Nested *struct {
|
|
|
|
S string
|
|
|
|
}
|
|
|
|
}{
|
|
|
|
Nested: &struct {
|
|
|
|
S string
|
|
|
|
}{
|
|
|
|
S: "string",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct {
|
|
|
|
Nested *struct {
|
|
|
|
S string
|
|
|
|
}
|
|
|
|
}{
|
|
|
|
Nested: &struct {
|
|
|
|
S string
|
|
|
|
}{
|
|
|
|
S: "string",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Nil pointer to a struct in an interface",
|
|
|
|
dst: &struct {
|
2016-08-06 02:19:36 +02:00
|
|
|
Nested interface{}
|
|
|
|
}{
|
|
|
|
Nested: (*struct{ S string })(nil),
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct {
|
2016-08-06 02:19:36 +02:00
|
|
|
Nested interface{}
|
|
|
|
}{
|
|
|
|
Nested: &struct {
|
|
|
|
S string
|
|
|
|
}{
|
|
|
|
S: "string",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct {
|
|
|
|
Nested interface{}
|
|
|
|
}{
|
|
|
|
Nested: &struct {
|
|
|
|
S string
|
|
|
|
}{
|
|
|
|
S: "string",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-08-20 03:16:33 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Interface src nil",
|
|
|
|
dst: &struct{ S interface{} }{
|
2016-08-20 03:16:33 +02:00
|
|
|
S: &struct{ S string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S interface{} }{
|
2016-08-20 03:16:33 +02:00
|
|
|
S: nil,
|
|
|
|
},
|
|
|
|
out: &struct{ S interface{} }{
|
|
|
|
S: &struct{ S string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
|
|
|
|
// Errors
|
|
|
|
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Non-pointer dst",
|
|
|
|
dst: struct{}{},
|
|
|
|
src: &struct{}{},
|
|
|
|
err: errors.New("expected pointer to struct, got struct {}"),
|
|
|
|
out: struct{}{},
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Non-pointer src",
|
|
|
|
dst: &struct{}{},
|
|
|
|
src: struct{}{},
|
|
|
|
err: errors.New("expected pointer to struct, got struct {}"),
|
|
|
|
out: &struct{}{},
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Non-struct dst",
|
|
|
|
dst: &[]string{"bad"},
|
|
|
|
src: &struct{}{},
|
|
|
|
err: errors.New("expected pointer to struct, got *[]string"),
|
|
|
|
out: &[]string{"bad"},
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Non-struct src",
|
|
|
|
dst: &struct{}{},
|
|
|
|
src: &[]string{"bad"},
|
|
|
|
err: errors.New("expected pointer to struct, got *[]string"),
|
|
|
|
out: &struct{}{},
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Mismatched types",
|
|
|
|
dst: &struct{ A string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
A: "string1",
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ B string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
B: "string2",
|
|
|
|
},
|
|
|
|
out: &struct{ A string }{
|
|
|
|
A: "string1",
|
|
|
|
},
|
|
|
|
err: errors.New("expected matching types for dst and src, got *struct { A string } and *struct { B string }"),
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Unsupported kind",
|
|
|
|
dst: &struct{ I int }{
|
2015-10-28 02:15:15 +01:00
|
|
|
I: 1,
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ I int }{
|
2015-10-28 02:15:15 +01:00
|
|
|
I: 2,
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
out: &struct{ I int }{
|
2015-10-28 02:15:15 +01:00
|
|
|
I: 1,
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
err: extendPropertyErrorf("i", "unsupported kind int"),
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Unsupported kind",
|
|
|
|
dst: &struct{ I int64 }{
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I: 1,
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ I int64 }{
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
I: 2,
|
|
|
|
},
|
|
|
|
out: &struct{ I int64 }{
|
|
|
|
I: 1,
|
|
|
|
},
|
|
|
|
err: extendPropertyErrorf("i", "unsupported kind int64"),
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Interface nilitude mismatch",
|
|
|
|
dst: &struct{ S interface{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: nil,
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S interface{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &struct{ S string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
},
|
2016-08-20 03:16:33 +02:00
|
|
|
out: &struct{ S interface{} }{
|
|
|
|
S: nil,
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
err: extendPropertyErrorf("s", "nilitude mismatch"),
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Interface type mismatch",
|
|
|
|
dst: &struct{ S interface{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &struct{ A string }{
|
|
|
|
A: "string1",
|
|
|
|
},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S interface{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &struct{ B string }{
|
|
|
|
B: "string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct{ S interface{} }{
|
|
|
|
S: &struct{ A string }{
|
|
|
|
A: "string1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
err: extendPropertyErrorf("s", "mismatched types struct { A string } and struct { B string }"),
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Interface not a pointer",
|
|
|
|
dst: &struct{ S interface{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: struct{ S string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S interface{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: struct{ S string }{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct{ S interface{} }{
|
|
|
|
S: struct{ S string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
err: extendPropertyErrorf("s", "interface not a pointer"),
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Pointer not a struct",
|
|
|
|
dst: &struct{ S *[]string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &[]string{"string1"},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S *[]string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &[]string{"string2"},
|
|
|
|
},
|
|
|
|
out: &struct{ S *[]string }{
|
|
|
|
S: &[]string{"string1"},
|
|
|
|
},
|
|
|
|
err: extendPropertyErrorf("s", "pointer is a slice"),
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Error in nested struct",
|
|
|
|
dst: &struct{ S interface{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &struct{ I int }{
|
|
|
|
I: 1,
|
|
|
|
},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S interface{} }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &struct{ I int }{
|
|
|
|
I: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct{ S interface{} }{
|
|
|
|
S: &struct{ I int }{
|
|
|
|
I: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
err: extendPropertyErrorf("s.i", "unsupported kind int"),
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
|
|
|
|
// Filters
|
|
|
|
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Filter true",
|
|
|
|
dst: &struct{ S string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string1",
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
out: &struct{ S string }{
|
|
|
|
S: "string1string2",
|
|
|
|
},
|
2024-02-01 23:37:14 +01:00
|
|
|
filter: func(dstField, srcField reflect.StructField) (bool, error) {
|
2016-05-06 00:58:02 +02:00
|
|
|
return true, nil
|
|
|
|
},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Filter false",
|
|
|
|
dst: &struct{ S string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string1",
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
out: &struct{ S string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
2024-02-01 23:37:14 +01:00
|
|
|
filter: func(dstField, srcField reflect.StructField) (bool, error) {
|
2016-05-06 00:58:02 +02:00
|
|
|
return false, nil
|
|
|
|
},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Filter check args",
|
|
|
|
dst: &struct{ S string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string1",
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
out: &struct{ S string }{
|
|
|
|
S: "string1string2",
|
|
|
|
},
|
2024-02-01 23:37:14 +01:00
|
|
|
filter: func(dstField, srcField reflect.StructField) (bool, error) {
|
|
|
|
return dstField.Name == "S" && srcField.Name == "S", nil
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Filter mutated",
|
|
|
|
dst: &struct {
|
2016-05-06 00:58:02 +02:00
|
|
|
S string `blueprint:"mutated"`
|
|
|
|
}{
|
|
|
|
S: "string1",
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct {
|
2016-05-06 00:58:02 +02:00
|
|
|
S string `blueprint:"mutated"`
|
|
|
|
}{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
out: &struct {
|
|
|
|
S string `blueprint:"mutated"`
|
|
|
|
}{
|
|
|
|
S: "string1",
|
|
|
|
},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Filter mutated",
|
|
|
|
dst: &struct {
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
S *int64 `blueprint:"mutated"`
|
|
|
|
}{
|
|
|
|
S: Int64Ptr(4),
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct {
|
Support parsing int64 in Blueprint file.
Support int64 number instead of int to be more fixed to bit size so
that the underlying arch won't affect overflow cases. Besides,
refection: func (v Value) Int() int64 always cast to int64 no matter the
input is int, int16, int32. Currently we always treat "-" as negative
sign to bind to next value, and "+" as plus operator to add operands
together.
So we allow:
a = 5 + -4 + 5 or a = -4 + 5
But we don't allow:
a = +5 + 4 + -4 since we don't treat "+" as a positive sign, otherwise,
a = 5 + +5 would exist which looks pretty weird. In the future, we may
want fully support number calculator logic eg, "+"/"-" can be
positive/negative sign or operator, and "(" and ")" will be considered
to group expressions with a higher precedence.
int & uint properties within struct keeps unchanged, which is only
allowed when tagged with 'blueprint:mutated'. We only allow *int64
property instead of int64 property within struct since it does't make
sense to do prepending or appending to int64.
Change-Id: I565e046dbd268af3538aee148cd7300037e56523
2017-11-01 22:03:28 +01:00
|
|
|
S *int64 `blueprint:"mutated"`
|
|
|
|
}{
|
|
|
|
S: Int64Ptr(5),
|
|
|
|
},
|
|
|
|
out: &struct {
|
|
|
|
S *int64 `blueprint:"mutated"`
|
|
|
|
}{
|
|
|
|
S: Int64Ptr(4),
|
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Filter error",
|
|
|
|
dst: &struct{ S string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string1",
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
out: &struct{ S string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
2024-02-01 23:37:14 +01:00
|
|
|
filter: func(dstField, srcField reflect.StructField) (bool, error) {
|
2016-05-06 00:58:02 +02:00
|
|
|
return true, fmt.Errorf("filter error")
|
|
|
|
},
|
|
|
|
err: extendPropertyErrorf("s", "filter error"),
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
Select statements
Select statements are a new blueprint feature inspired by bazel's select
statements. They are essentially alternative syntax for soong config
variables that require less boilerplate. In addition, they support
making decisions based on a module's variant, which will eliminate
the need for manual property struct manipulation, such as the arch
mutator's arch: and target: properties.
In order to support decisions based on the variant, select statements
cannot be evaluated as soon as they're parsed. Instead, they must be
stored in the property struct unevaluated. This means that individual
properties need to change their type from say, string, to
Configurable[string]. Currently, only configurable strings, bools, and
string slices are supported, but more types can be added later.
The module implementation must call my_property.Evaluate(ctx) in order
to get the final, resolved value of the select statement.
Bug: 323382414
Test: go tests
Change-Id: I62f8721d7f0ac3d1df4a06d7eaa260a5aa7fcba3
2024-02-02 02:44:27 +01:00
|
|
|
{
|
|
|
|
name: "Append configurable",
|
|
|
|
dst: &struct{ S Configurable[[]string] }{
|
|
|
|
S: Configurable[[]string]{
|
2024-04-27 01:39:54 +02:00
|
|
|
inner: &configurableInner[[]string]{
|
|
|
|
single: singleConfigurable[[]string]{
|
|
|
|
conditions: []ConfigurableCondition{{
|
|
|
|
functionName: "soong_config_variable",
|
|
|
|
args: []string{
|
|
|
|
"my_namespace",
|
|
|
|
"foo",
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
cases: []ConfigurableCase[[]string]{{
|
|
|
|
patterns: []ConfigurablePattern{{
|
|
|
|
typ: configurablePatternTypeString,
|
|
|
|
stringValue: "a",
|
|
|
|
}},
|
|
|
|
value: &[]string{"1", "2"},
|
|
|
|
}},
|
Support multi-variable selects and typed selects
This adds support for selecting on multiple variables at once, so that
you can do AND/OR combindations of them. For example:
select((
arch(),
os(),
), {
("arm64", "linux"): ["libfoo64"],
(default, "linux"): ["libfoo"],
(default, "windows"): ["libfoowindows"],
(default, default): ["libbar"],
})
It also allows for select conditions to be boolean-typed. You can
write literal true and false without quotes to select on them. Currently
we don't have any boolean-typed variables though, so a fake one was
added for testing.
Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ibe586e7b21865b8734027848cc421594cbd1d8cc
2024-04-10 23:57:34 +02:00
|
|
|
},
|
2024-04-27 01:39:54 +02:00
|
|
|
},
|
Select statements
Select statements are a new blueprint feature inspired by bazel's select
statements. They are essentially alternative syntax for soong config
variables that require less boilerplate. In addition, they support
making decisions based on a module's variant, which will eliminate
the need for manual property struct manipulation, such as the arch
mutator's arch: and target: properties.
In order to support decisions based on the variant, select statements
cannot be evaluated as soon as they're parsed. Instead, they must be
stored in the property struct unevaluated. This means that individual
properties need to change their type from say, string, to
Configurable[string]. Currently, only configurable strings, bools, and
string slices are supported, but more types can be added later.
The module implementation must call my_property.Evaluate(ctx) in order
to get the final, resolved value of the select statement.
Bug: 323382414
Test: go tests
Change-Id: I62f8721d7f0ac3d1df4a06d7eaa260a5aa7fcba3
2024-02-02 02:44:27 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
src: &struct{ S Configurable[[]string] }{
|
|
|
|
S: Configurable[[]string]{
|
2024-04-27 01:39:54 +02:00
|
|
|
inner: &configurableInner[[]string]{
|
|
|
|
single: singleConfigurable[[]string]{
|
|
|
|
conditions: []ConfigurableCondition{{
|
|
|
|
functionName: "release_variable",
|
|
|
|
args: []string{
|
|
|
|
"bar",
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
cases: []ConfigurableCase[[]string]{{
|
|
|
|
patterns: []ConfigurablePattern{{
|
|
|
|
typ: configurablePatternTypeString,
|
|
|
|
stringValue: "b",
|
|
|
|
}},
|
|
|
|
value: &[]string{"3", "4"},
|
|
|
|
}},
|
Support multi-variable selects and typed selects
This adds support for selecting on multiple variables at once, so that
you can do AND/OR combindations of them. For example:
select((
arch(),
os(),
), {
("arm64", "linux"): ["libfoo64"],
(default, "linux"): ["libfoo"],
(default, "windows"): ["libfoowindows"],
(default, default): ["libbar"],
})
It also allows for select conditions to be boolean-typed. You can
write literal true and false without quotes to select on them. Currently
we don't have any boolean-typed variables though, so a fake one was
added for testing.
Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ibe586e7b21865b8734027848cc421594cbd1d8cc
2024-04-10 23:57:34 +02:00
|
|
|
},
|
2024-04-27 01:39:54 +02:00
|
|
|
},
|
Select statements
Select statements are a new blueprint feature inspired by bazel's select
statements. They are essentially alternative syntax for soong config
variables that require less boilerplate. In addition, they support
making decisions based on a module's variant, which will eliminate
the need for manual property struct manipulation, such as the arch
mutator's arch: and target: properties.
In order to support decisions based on the variant, select statements
cannot be evaluated as soon as they're parsed. Instead, they must be
stored in the property struct unevaluated. This means that individual
properties need to change their type from say, string, to
Configurable[string]. Currently, only configurable strings, bools, and
string slices are supported, but more types can be added later.
The module implementation must call my_property.Evaluate(ctx) in order
to get the final, resolved value of the select statement.
Bug: 323382414
Test: go tests
Change-Id: I62f8721d7f0ac3d1df4a06d7eaa260a5aa7fcba3
2024-02-02 02:44:27 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct{ S Configurable[[]string] }{
|
|
|
|
S: Configurable[[]string]{
|
2024-04-27 01:39:54 +02:00
|
|
|
inner: &configurableInner[[]string]{
|
|
|
|
single: singleConfigurable[[]string]{
|
Support multi-variable selects and typed selects
This adds support for selecting on multiple variables at once, so that
you can do AND/OR combindations of them. For example:
select((
arch(),
os(),
), {
("arm64", "linux"): ["libfoo64"],
(default, "linux"): ["libfoo"],
(default, "windows"): ["libfoowindows"],
(default, default): ["libbar"],
})
It also allows for select conditions to be boolean-typed. You can
write literal true and false without quotes to select on them. Currently
we don't have any boolean-typed variables though, so a fake one was
added for testing.
Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ibe586e7b21865b8734027848cc421594cbd1d8cc
2024-04-10 23:57:34 +02:00
|
|
|
conditions: []ConfigurableCondition{{
|
2024-04-27 01:39:54 +02:00
|
|
|
functionName: "soong_config_variable",
|
|
|
|
args: []string{
|
|
|
|
"my_namespace",
|
|
|
|
"foo",
|
Support multi-variable selects and typed selects
This adds support for selecting on multiple variables at once, so that
you can do AND/OR combindations of them. For example:
select((
arch(),
os(),
), {
("arm64", "linux"): ["libfoo64"],
(default, "linux"): ["libfoo"],
(default, "windows"): ["libfoowindows"],
(default, default): ["libbar"],
})
It also allows for select conditions to be boolean-typed. You can
write literal true and false without quotes to select on them. Currently
we don't have any boolean-typed variables though, so a fake one was
added for testing.
Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ibe586e7b21865b8734027848cc421594cbd1d8cc
2024-04-10 23:57:34 +02:00
|
|
|
},
|
|
|
|
}},
|
2024-04-23 22:50:40 +02:00
|
|
|
cases: []ConfigurableCase[[]string]{{
|
|
|
|
patterns: []ConfigurablePattern{{
|
Support multi-variable selects and typed selects
This adds support for selecting on multiple variables at once, so that
you can do AND/OR combindations of them. For example:
select((
arch(),
os(),
), {
("arm64", "linux"): ["libfoo64"],
(default, "linux"): ["libfoo"],
(default, "windows"): ["libfoowindows"],
(default, default): ["libbar"],
})
It also allows for select conditions to be boolean-typed. You can
write literal true and false without quotes to select on them. Currently
we don't have any boolean-typed variables though, so a fake one was
added for testing.
Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ibe586e7b21865b8734027848cc421594cbd1d8cc
2024-04-10 23:57:34 +02:00
|
|
|
typ: configurablePatternTypeString,
|
2024-04-27 01:39:54 +02:00
|
|
|
stringValue: "a",
|
Support multi-variable selects and typed selects
This adds support for selecting on multiple variables at once, so that
you can do AND/OR combindations of them. For example:
select((
arch(),
os(),
), {
("arm64", "linux"): ["libfoo64"],
(default, "linux"): ["libfoo"],
(default, "windows"): ["libfoowindows"],
(default, default): ["libbar"],
})
It also allows for select conditions to be boolean-typed. You can
write literal true and false without quotes to select on them. Currently
we don't have any boolean-typed variables though, so a fake one was
added for testing.
Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ibe586e7b21865b8734027848cc421594cbd1d8cc
2024-04-10 23:57:34 +02:00
|
|
|
}},
|
2024-04-27 01:39:54 +02:00
|
|
|
value: &[]string{"1", "2"},
|
Support multi-variable selects and typed selects
This adds support for selecting on multiple variables at once, so that
you can do AND/OR combindations of them. For example:
select((
arch(),
os(),
), {
("arm64", "linux"): ["libfoo64"],
(default, "linux"): ["libfoo"],
(default, "windows"): ["libfoowindows"],
(default, default): ["libbar"],
})
It also allows for select conditions to be boolean-typed. You can
write literal true and false without quotes to select on them. Currently
we don't have any boolean-typed variables though, so a fake one was
added for testing.
Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ibe586e7b21865b8734027848cc421594cbd1d8cc
2024-04-10 23:57:34 +02:00
|
|
|
}},
|
2024-04-27 01:39:54 +02:00
|
|
|
},
|
|
|
|
next: &configurableInner[[]string]{
|
|
|
|
single: singleConfigurable[[]string]{
|
|
|
|
conditions: []ConfigurableCondition{{
|
|
|
|
functionName: "release_variable",
|
|
|
|
args: []string{
|
|
|
|
"bar",
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
cases: []ConfigurableCase[[]string]{{
|
|
|
|
patterns: []ConfigurablePattern{{
|
|
|
|
typ: configurablePatternTypeString,
|
|
|
|
stringValue: "b",
|
|
|
|
}},
|
|
|
|
value: &[]string{"3", "4"},
|
|
|
|
}},
|
|
|
|
},
|
Select statements
Select statements are a new blueprint feature inspired by bazel's select
statements. They are essentially alternative syntax for soong config
variables that require less boilerplate. In addition, they support
making decisions based on a module's variant, which will eliminate
the need for manual property struct manipulation, such as the arch
mutator's arch: and target: properties.
In order to support decisions based on the variant, select statements
cannot be evaluated as soon as they're parsed. Instead, they must be
stored in the property struct unevaluated. This means that individual
properties need to change their type from say, string, to
Configurable[string]. Currently, only configurable strings, bools, and
string slices are supported, but more types can be added later.
The module implementation must call my_property.Evaluate(ctx) in order
to get the final, resolved value of the select statement.
Bug: 323382414
Test: go tests
Change-Id: I62f8721d7f0ac3d1df4a06d7eaa260a5aa7fcba3
2024-02-02 02:44:27 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Prepend configurable",
|
|
|
|
order: Prepend,
|
|
|
|
dst: &struct{ S Configurable[[]string] }{
|
|
|
|
S: Configurable[[]string]{
|
2024-04-27 01:39:54 +02:00
|
|
|
inner: &configurableInner[[]string]{
|
|
|
|
single: singleConfigurable[[]string]{
|
|
|
|
conditions: []ConfigurableCondition{{
|
|
|
|
functionName: "soong_config_variable",
|
|
|
|
args: []string{
|
|
|
|
"my_namespace",
|
|
|
|
"foo",
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
cases: []ConfigurableCase[[]string]{{
|
|
|
|
patterns: []ConfigurablePattern{{
|
|
|
|
typ: configurablePatternTypeString,
|
|
|
|
stringValue: "a",
|
|
|
|
}},
|
|
|
|
value: &[]string{"1", "2"},
|
|
|
|
}},
|
Support multi-variable selects and typed selects
This adds support for selecting on multiple variables at once, so that
you can do AND/OR combindations of them. For example:
select((
arch(),
os(),
), {
("arm64", "linux"): ["libfoo64"],
(default, "linux"): ["libfoo"],
(default, "windows"): ["libfoowindows"],
(default, default): ["libbar"],
})
It also allows for select conditions to be boolean-typed. You can
write literal true and false without quotes to select on them. Currently
we don't have any boolean-typed variables though, so a fake one was
added for testing.
Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ibe586e7b21865b8734027848cc421594cbd1d8cc
2024-04-10 23:57:34 +02:00
|
|
|
},
|
2024-04-27 01:39:54 +02:00
|
|
|
},
|
Select statements
Select statements are a new blueprint feature inspired by bazel's select
statements. They are essentially alternative syntax for soong config
variables that require less boilerplate. In addition, they support
making decisions based on a module's variant, which will eliminate
the need for manual property struct manipulation, such as the arch
mutator's arch: and target: properties.
In order to support decisions based on the variant, select statements
cannot be evaluated as soon as they're parsed. Instead, they must be
stored in the property struct unevaluated. This means that individual
properties need to change their type from say, string, to
Configurable[string]. Currently, only configurable strings, bools, and
string slices are supported, but more types can be added later.
The module implementation must call my_property.Evaluate(ctx) in order
to get the final, resolved value of the select statement.
Bug: 323382414
Test: go tests
Change-Id: I62f8721d7f0ac3d1df4a06d7eaa260a5aa7fcba3
2024-02-02 02:44:27 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
src: &struct{ S Configurable[[]string] }{
|
|
|
|
S: Configurable[[]string]{
|
2024-04-27 01:39:54 +02:00
|
|
|
inner: &configurableInner[[]string]{
|
|
|
|
single: singleConfigurable[[]string]{
|
|
|
|
conditions: []ConfigurableCondition{{
|
|
|
|
functionName: "release_variable",
|
|
|
|
args: []string{
|
|
|
|
"bar",
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
cases: []ConfigurableCase[[]string]{{
|
|
|
|
patterns: []ConfigurablePattern{{
|
|
|
|
typ: configurablePatternTypeString,
|
|
|
|
stringValue: "b",
|
|
|
|
}},
|
|
|
|
value: &[]string{"3", "4"},
|
|
|
|
}},
|
Support multi-variable selects and typed selects
This adds support for selecting on multiple variables at once, so that
you can do AND/OR combindations of them. For example:
select((
arch(),
os(),
), {
("arm64", "linux"): ["libfoo64"],
(default, "linux"): ["libfoo"],
(default, "windows"): ["libfoowindows"],
(default, default): ["libbar"],
})
It also allows for select conditions to be boolean-typed. You can
write literal true and false without quotes to select on them. Currently
we don't have any boolean-typed variables though, so a fake one was
added for testing.
Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ibe586e7b21865b8734027848cc421594cbd1d8cc
2024-04-10 23:57:34 +02:00
|
|
|
},
|
2024-04-27 01:39:54 +02:00
|
|
|
},
|
Select statements
Select statements are a new blueprint feature inspired by bazel's select
statements. They are essentially alternative syntax for soong config
variables that require less boilerplate. In addition, they support
making decisions based on a module's variant, which will eliminate
the need for manual property struct manipulation, such as the arch
mutator's arch: and target: properties.
In order to support decisions based on the variant, select statements
cannot be evaluated as soon as they're parsed. Instead, they must be
stored in the property struct unevaluated. This means that individual
properties need to change their type from say, string, to
Configurable[string]. Currently, only configurable strings, bools, and
string slices are supported, but more types can be added later.
The module implementation must call my_property.Evaluate(ctx) in order
to get the final, resolved value of the select statement.
Bug: 323382414
Test: go tests
Change-Id: I62f8721d7f0ac3d1df4a06d7eaa260a5aa7fcba3
2024-02-02 02:44:27 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
out: &struct{ S Configurable[[]string] }{
|
|
|
|
S: Configurable[[]string]{
|
2024-04-27 01:39:54 +02:00
|
|
|
inner: &configurableInner[[]string]{
|
|
|
|
single: singleConfigurable[[]string]{
|
Support multi-variable selects and typed selects
This adds support for selecting on multiple variables at once, so that
you can do AND/OR combindations of them. For example:
select((
arch(),
os(),
), {
("arm64", "linux"): ["libfoo64"],
(default, "linux"): ["libfoo"],
(default, "windows"): ["libfoowindows"],
(default, default): ["libbar"],
})
It also allows for select conditions to be boolean-typed. You can
write literal true and false without quotes to select on them. Currently
we don't have any boolean-typed variables though, so a fake one was
added for testing.
Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ibe586e7b21865b8734027848cc421594cbd1d8cc
2024-04-10 23:57:34 +02:00
|
|
|
conditions: []ConfigurableCondition{{
|
2024-04-27 01:39:54 +02:00
|
|
|
functionName: "release_variable",
|
|
|
|
args: []string{
|
|
|
|
"bar",
|
Support multi-variable selects and typed selects
This adds support for selecting on multiple variables at once, so that
you can do AND/OR combindations of them. For example:
select((
arch(),
os(),
), {
("arm64", "linux"): ["libfoo64"],
(default, "linux"): ["libfoo"],
(default, "windows"): ["libfoowindows"],
(default, default): ["libbar"],
})
It also allows for select conditions to be boolean-typed. You can
write literal true and false without quotes to select on them. Currently
we don't have any boolean-typed variables though, so a fake one was
added for testing.
Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ibe586e7b21865b8734027848cc421594cbd1d8cc
2024-04-10 23:57:34 +02:00
|
|
|
},
|
|
|
|
}},
|
2024-04-23 22:50:40 +02:00
|
|
|
cases: []ConfigurableCase[[]string]{{
|
|
|
|
patterns: []ConfigurablePattern{{
|
Support multi-variable selects and typed selects
This adds support for selecting on multiple variables at once, so that
you can do AND/OR combindations of them. For example:
select((
arch(),
os(),
), {
("arm64", "linux"): ["libfoo64"],
(default, "linux"): ["libfoo"],
(default, "windows"): ["libfoowindows"],
(default, default): ["libbar"],
})
It also allows for select conditions to be boolean-typed. You can
write literal true and false without quotes to select on them. Currently
we don't have any boolean-typed variables though, so a fake one was
added for testing.
Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ibe586e7b21865b8734027848cc421594cbd1d8cc
2024-04-10 23:57:34 +02:00
|
|
|
typ: configurablePatternTypeString,
|
2024-04-27 01:39:54 +02:00
|
|
|
stringValue: "b",
|
Support multi-variable selects and typed selects
This adds support for selecting on multiple variables at once, so that
you can do AND/OR combindations of them. For example:
select((
arch(),
os(),
), {
("arm64", "linux"): ["libfoo64"],
(default, "linux"): ["libfoo"],
(default, "windows"): ["libfoowindows"],
(default, default): ["libbar"],
})
It also allows for select conditions to be boolean-typed. You can
write literal true and false without quotes to select on them. Currently
we don't have any boolean-typed variables though, so a fake one was
added for testing.
Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ibe586e7b21865b8734027848cc421594cbd1d8cc
2024-04-10 23:57:34 +02:00
|
|
|
}},
|
2024-04-27 01:39:54 +02:00
|
|
|
value: &[]string{"3", "4"},
|
Support multi-variable selects and typed selects
This adds support for selecting on multiple variables at once, so that
you can do AND/OR combindations of them. For example:
select((
arch(),
os(),
), {
("arm64", "linux"): ["libfoo64"],
(default, "linux"): ["libfoo"],
(default, "windows"): ["libfoowindows"],
(default, default): ["libbar"],
})
It also allows for select conditions to be boolean-typed. You can
write literal true and false without quotes to select on them. Currently
we don't have any boolean-typed variables though, so a fake one was
added for testing.
Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ibe586e7b21865b8734027848cc421594cbd1d8cc
2024-04-10 23:57:34 +02:00
|
|
|
}},
|
2024-04-27 01:39:54 +02:00
|
|
|
},
|
|
|
|
next: &configurableInner[[]string]{
|
|
|
|
single: singleConfigurable[[]string]{
|
|
|
|
conditions: []ConfigurableCondition{{
|
|
|
|
functionName: "soong_config_variable",
|
|
|
|
args: []string{
|
|
|
|
"my_namespace",
|
|
|
|
"foo",
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
cases: []ConfigurableCase[[]string]{{
|
|
|
|
patterns: []ConfigurablePattern{{
|
|
|
|
typ: configurablePatternTypeString,
|
|
|
|
stringValue: "a",
|
|
|
|
}},
|
|
|
|
value: &[]string{"1", "2"},
|
|
|
|
}},
|
|
|
|
},
|
Select statements
Select statements are a new blueprint feature inspired by bazel's select
statements. They are essentially alternative syntax for soong config
variables that require less boilerplate. In addition, they support
making decisions based on a module's variant, which will eliminate
the need for manual property struct manipulation, such as the arch
mutator's arch: and target: properties.
In order to support decisions based on the variant, select statements
cannot be evaluated as soon as they're parsed. Instead, they must be
stored in the property struct unevaluated. This means that individual
properties need to change their type from say, string, to
Configurable[string]. Currently, only configurable strings, bools, and
string slices are supported, but more types can be added later.
The module implementation must call my_property.Evaluate(ctx) in order
to get the final, resolved value of the select statement.
Bug: 323382414
Test: go tests
Change-Id: I62f8721d7f0ac3d1df4a06d7eaa260a5aa7fcba3
2024-02-02 02:44:27 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
}
|
2015-10-28 02:15:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAppendProperties(t *testing.T) {
|
2016-05-06 00:58:02 +02:00
|
|
|
for _, testCase := range appendPropertiesTestCases() {
|
2021-05-21 23:56:53 +02:00
|
|
|
t.Run(testCase.name, func(t *testing.T) {
|
2015-10-28 02:15:15 +01:00
|
|
|
|
2021-05-21 23:56:53 +02:00
|
|
|
got := testCase.dst
|
|
|
|
var err error
|
|
|
|
var testType string
|
2015-10-28 02:15:15 +01:00
|
|
|
|
2021-05-21 23:56:53 +02:00
|
|
|
switch testCase.order {
|
|
|
|
case Append:
|
|
|
|
testType = "append"
|
|
|
|
err = AppendProperties(got, testCase.src, testCase.filter)
|
|
|
|
case Prepend:
|
|
|
|
testType = "prepend"
|
|
|
|
err = PrependProperties(got, testCase.src, testCase.filter)
|
|
|
|
case Replace:
|
|
|
|
testType = "replace"
|
|
|
|
err = ExtendProperties(got, testCase.src, testCase.filter, OrderReplace)
|
|
|
|
}
|
2015-10-28 02:15:15 +01:00
|
|
|
|
2021-05-21 23:56:53 +02:00
|
|
|
check(t, testType, testCase.name, got, err, testCase.out, testCase.err)
|
|
|
|
})
|
2015-10-28 02:15:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-06 00:58:02 +02:00
|
|
|
func TestExtendProperties(t *testing.T) {
|
|
|
|
for _, testCase := range appendPropertiesTestCases() {
|
2021-05-21 23:56:53 +02:00
|
|
|
t.Run(testCase.name, func(t *testing.T) {
|
2016-05-06 00:58:02 +02:00
|
|
|
|
2021-05-21 23:56:53 +02:00
|
|
|
got := testCase.dst
|
|
|
|
var err error
|
|
|
|
var testType string
|
|
|
|
|
2024-02-01 23:37:14 +01:00
|
|
|
order := func(dstField, srcField reflect.StructField) (Order, error) {
|
2021-05-21 23:56:53 +02:00
|
|
|
switch testCase.order {
|
|
|
|
case Append:
|
|
|
|
return Append, nil
|
|
|
|
case Prepend:
|
|
|
|
return Prepend, nil
|
|
|
|
case Replace:
|
|
|
|
return Replace, nil
|
|
|
|
}
|
|
|
|
return Append, errors.New("unknown order")
|
|
|
|
}
|
2016-05-06 00:58:02 +02:00
|
|
|
|
2019-11-15 10:31:56 +01:00
|
|
|
switch testCase.order {
|
|
|
|
case Append:
|
2021-05-21 23:56:53 +02:00
|
|
|
testType = "prepend"
|
2019-11-15 10:31:56 +01:00
|
|
|
case Prepend:
|
2021-05-21 23:56:53 +02:00
|
|
|
testType = "append"
|
2019-11-15 10:31:56 +01:00
|
|
|
case Replace:
|
2021-05-21 23:56:53 +02:00
|
|
|
testType = "replace"
|
2016-05-06 00:58:02 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 23:56:53 +02:00
|
|
|
err = ExtendProperties(got, testCase.src, testCase.filter, order)
|
2016-05-06 00:58:02 +02:00
|
|
|
|
2021-05-21 23:56:53 +02:00
|
|
|
check(t, testType, testCase.name, got, err, testCase.out, testCase.err)
|
|
|
|
})
|
2016-05-06 00:58:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type appendMatchingPropertiesTestCase struct {
|
2021-05-21 23:56:53 +02:00
|
|
|
name string
|
|
|
|
dst []interface{}
|
|
|
|
src interface{}
|
2019-11-15 10:31:56 +01:00
|
|
|
out []interface{}
|
|
|
|
order Order // default is Append
|
|
|
|
filter ExtendPropertyFilterFunc
|
|
|
|
err error
|
2016-05-06 00:58:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func appendMatchingPropertiesTestCases() []appendMatchingPropertiesTestCase {
|
|
|
|
return []appendMatchingPropertiesTestCase{
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append strings",
|
|
|
|
dst: []interface{}{&struct{ S string }{
|
2015-10-28 02:15:15 +01:00
|
|
|
S: "string1",
|
2016-05-06 00:58:02 +02:00
|
|
|
}},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S string }{
|
2015-10-28 02:15:15 +01:00
|
|
|
S: "string2",
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
out: []interface{}{&struct{ S string }{
|
|
|
|
S: "string1string2",
|
|
|
|
}},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Prepend strings",
|
|
|
|
dst: []interface{}{&struct{ S string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string1",
|
|
|
|
}},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
out: []interface{}{&struct{ S string }{
|
|
|
|
S: "string2string1",
|
|
|
|
}},
|
2019-11-15 10:31:56 +01:00
|
|
|
order: Prepend,
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append all",
|
|
|
|
dst: []interface{}{
|
2016-05-06 00:58:02 +02:00
|
|
|
&struct{ S, A string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
&struct{ S, B string }{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string3",
|
|
|
|
},
|
|
|
|
out: []interface{}{
|
|
|
|
&struct{ S, A string }{
|
|
|
|
S: "string1string3",
|
|
|
|
},
|
|
|
|
&struct{ S, B string }{
|
|
|
|
S: "string2string3",
|
|
|
|
},
|
|
|
|
},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append some",
|
|
|
|
dst: []interface{}{
|
2016-05-06 00:58:02 +02:00
|
|
|
&struct{ S, A string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
&struct{ B string }{},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
out: []interface{}{
|
|
|
|
&struct{ S, A string }{
|
|
|
|
S: "string1string2",
|
|
|
|
},
|
|
|
|
&struct{ B string }{},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append mismatched structs",
|
|
|
|
dst: []interface{}{&struct{ S, A string }{
|
2015-10-28 02:15:15 +01:00
|
|
|
S: "string1",
|
2016-05-06 00:58:02 +02:00
|
|
|
}},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: "string2",
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
out: []interface{}{&struct{ S, A string }{
|
|
|
|
S: "string1string2",
|
|
|
|
}},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append mismatched pointer structs",
|
|
|
|
dst: []interface{}{&struct{ S *struct{ S, A string } }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &struct{ S, A string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
}},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S *struct{ S string } }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: &struct{ S string }{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: []interface{}{&struct{ S *struct{ S, A string } }{
|
|
|
|
S: &struct{ S, A string }{
|
|
|
|
S: "string1string2",
|
|
|
|
},
|
|
|
|
}},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-08-20 03:16:33 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append through mismatched types",
|
|
|
|
dst: []interface{}{
|
2016-08-20 03:16:33 +02:00
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ S interface{} }{
|
|
|
|
S: &struct{ S, A string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S struct{ S string } }{
|
2016-08-20 03:16:33 +02:00
|
|
|
S: struct{ S string }{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: []interface{}{
|
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ S interface{} }{
|
|
|
|
S: &struct{ S, A string }{
|
|
|
|
S: "string1string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append through mismatched types and nil",
|
|
|
|
dst: []interface{}{
|
2016-08-20 03:16:33 +02:00
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ S interface{} }{
|
|
|
|
S: (*struct{ S, A string })(nil),
|
|
|
|
},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S struct{ S string } }{
|
2016-08-20 03:16:33 +02:00
|
|
|
S: struct{ S string }{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: []interface{}{
|
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ S interface{} }{
|
|
|
|
S: &struct{ S, A string }{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append through multiple matches",
|
|
|
|
dst: []interface{}{
|
2016-08-20 03:16:33 +02:00
|
|
|
&struct {
|
|
|
|
S struct{ S, A string }
|
|
|
|
}{
|
|
|
|
S: struct{ S, A string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&struct {
|
|
|
|
S struct{ S, B string }
|
|
|
|
}{
|
|
|
|
S: struct{ S, B string }{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S struct{ B string } }{
|
2016-08-20 03:16:33 +02:00
|
|
|
S: struct{ B string }{
|
|
|
|
B: "string3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: []interface{}{
|
|
|
|
&struct {
|
|
|
|
S struct{ S, A string }
|
|
|
|
}{
|
|
|
|
S: struct{ S, A string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&struct {
|
|
|
|
S struct{ S, B string }
|
|
|
|
}{
|
|
|
|
S: struct{ S, B string }{
|
|
|
|
S: "string2",
|
|
|
|
B: "string3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-26 01:44:30 +02:00
|
|
|
{
|
|
|
|
name: "Append through embedded struct",
|
|
|
|
dst: []interface{}{
|
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ EmbeddedStruct }{
|
|
|
|
EmbeddedStruct: EmbeddedStruct{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
src: &struct{ S string }{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
out: []interface{}{
|
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ EmbeddedStruct }{
|
|
|
|
EmbeddedStruct: EmbeddedStruct{
|
|
|
|
S: "string1string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Append through BlueprintEmbed struct",
|
|
|
|
dst: []interface{}{
|
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ BlueprintEmbed EmbeddedStruct }{
|
|
|
|
BlueprintEmbed: EmbeddedStruct{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
src: &struct{ S string }{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
out: []interface{}{
|
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ BlueprintEmbed EmbeddedStruct }{
|
|
|
|
BlueprintEmbed: EmbeddedStruct{
|
|
|
|
S: "string1string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Append through embedded pointer to struct",
|
|
|
|
dst: []interface{}{
|
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ *EmbeddedStruct }{
|
|
|
|
EmbeddedStruct: &EmbeddedStruct{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
src: &struct{ S string }{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
out: []interface{}{
|
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ *EmbeddedStruct }{
|
|
|
|
EmbeddedStruct: &EmbeddedStruct{
|
|
|
|
S: "string1string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Append through BlueprintEmbed pointer to struct",
|
|
|
|
dst: []interface{}{
|
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ BlueprintEmbed *EmbeddedStruct }{
|
|
|
|
BlueprintEmbed: &EmbeddedStruct{
|
|
|
|
S: "string1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
src: &struct{ S string }{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
out: []interface{}{
|
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ BlueprintEmbed *EmbeddedStruct }{
|
|
|
|
BlueprintEmbed: &EmbeddedStruct{
|
|
|
|
S: "string1string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Append through embedded nil pointer to struct",
|
|
|
|
dst: []interface{}{
|
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ *EmbeddedStruct }{},
|
|
|
|
},
|
|
|
|
src: &struct{ S string }{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
out: []interface{}{
|
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ *EmbeddedStruct }{
|
|
|
|
EmbeddedStruct: &EmbeddedStruct{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Append through BlueprintEmbed nil pointer to struct",
|
|
|
|
dst: []interface{}{
|
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ BlueprintEmbed *EmbeddedStruct }{},
|
|
|
|
},
|
|
|
|
src: &struct{ S string }{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
out: []interface{}{
|
|
|
|
&struct{ B string }{},
|
|
|
|
&struct{ BlueprintEmbed *EmbeddedStruct }{
|
|
|
|
BlueprintEmbed: &EmbeddedStruct{
|
|
|
|
S: "string2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
|
|
|
|
// Errors
|
|
|
|
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Non-pointer dst",
|
|
|
|
dst: []interface{}{struct{}{}},
|
|
|
|
src: &struct{}{},
|
|
|
|
err: errors.New("expected pointer to struct, got struct {}"),
|
|
|
|
out: []interface{}{struct{}{}},
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Non-pointer src",
|
|
|
|
dst: []interface{}{&struct{}{}},
|
|
|
|
src: struct{}{},
|
|
|
|
err: errors.New("expected pointer to struct, got struct {}"),
|
|
|
|
out: []interface{}{&struct{}{}},
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Non-struct dst",
|
|
|
|
dst: []interface{}{&[]string{"bad"}},
|
|
|
|
src: &struct{}{},
|
|
|
|
err: errors.New("expected pointer to struct, got *[]string"),
|
|
|
|
out: []interface{}{&[]string{"bad"}},
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Non-struct src",
|
|
|
|
dst: []interface{}{&struct{}{}},
|
|
|
|
src: &[]string{"bad"},
|
|
|
|
err: errors.New("expected pointer to struct, got *[]string"),
|
|
|
|
out: []interface{}{&struct{}{}},
|
2016-05-06 00:58:02 +02:00
|
|
|
},
|
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append none",
|
|
|
|
dst: []interface{}{
|
2016-05-06 00:58:02 +02:00
|
|
|
&struct{ A string }{},
|
|
|
|
&struct{ B string }{},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S string }{
|
2015-10-28 02:15:15 +01:00
|
|
|
S: "string1",
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
out: []interface{}{
|
|
|
|
&struct{ A string }{},
|
|
|
|
&struct{ B string }{},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
err: extendPropertyErrorf("s", "failed to find property to extend"),
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append mismatched kinds",
|
|
|
|
dst: []interface{}{
|
2016-05-06 00:58:02 +02:00
|
|
|
&struct{ S string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S []string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: []string{"string2"},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
out: []interface{}{
|
|
|
|
&struct{ S string }{
|
|
|
|
S: "string1",
|
|
|
|
},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
err: extendPropertyErrorf("s", "mismatched types string and []string"),
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
{
|
2021-05-21 23:56:53 +02:00
|
|
|
name: "Append mismatched types",
|
|
|
|
dst: []interface{}{
|
2016-05-06 00:58:02 +02:00
|
|
|
&struct{ S []int }{
|
|
|
|
S: []int{1},
|
|
|
|
},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2021-05-21 23:56:53 +02:00
|
|
|
src: &struct{ S []string }{
|
2016-05-06 00:58:02 +02:00
|
|
|
S: []string{"string2"},
|
|
|
|
},
|
|
|
|
out: []interface{}{
|
|
|
|
&struct{ S []int }{
|
|
|
|
S: []int{1},
|
|
|
|
},
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
err: extendPropertyErrorf("s", "mismatched types []int and []string"),
|
2015-10-28 02:15:15 +01:00
|
|
|
},
|
2024-04-17 19:24:51 +02:00
|
|
|
{
|
|
|
|
name: "Append *bool to Configurable[bool]",
|
|
|
|
order: Append,
|
|
|
|
dst: []interface{}{
|
|
|
|
&struct{ S Configurable[bool] }{
|
|
|
|
S: Configurable[bool]{
|
2024-04-27 01:39:54 +02:00
|
|
|
inner: &configurableInner[bool]{
|
|
|
|
single: singleConfigurable[bool]{
|
|
|
|
conditions: []ConfigurableCondition{{
|
|
|
|
functionName: "soong_config_variable",
|
|
|
|
args: []string{
|
|
|
|
"my_namespace",
|
|
|
|
"foo",
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
cases: []ConfigurableCase[bool]{{
|
|
|
|
patterns: []ConfigurablePattern{{
|
|
|
|
typ: configurablePatternTypeString,
|
|
|
|
stringValue: "a",
|
|
|
|
}},
|
|
|
|
value: BoolPtr(true),
|
|
|
|
}, {
|
|
|
|
patterns: []ConfigurablePattern{{
|
|
|
|
typ: configurablePatternTypeDefault,
|
|
|
|
}},
|
|
|
|
value: BoolPtr(false),
|
|
|
|
}},
|
2024-04-17 19:24:51 +02:00
|
|
|
},
|
2024-04-27 01:39:54 +02:00
|
|
|
},
|
2024-04-17 19:24:51 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
src: &struct{ S *bool }{
|
|
|
|
S: BoolPtr(true),
|
|
|
|
},
|
|
|
|
out: []interface{}{
|
|
|
|
&struct{ S Configurable[bool] }{
|
|
|
|
S: Configurable[bool]{
|
2024-04-27 01:39:54 +02:00
|
|
|
inner: &configurableInner[bool]{
|
|
|
|
single: singleConfigurable[bool]{
|
|
|
|
conditions: []ConfigurableCondition{{
|
|
|
|
functionName: "soong_config_variable",
|
|
|
|
args: []string{
|
|
|
|
"my_namespace",
|
|
|
|
"foo",
|
|
|
|
},
|
|
|
|
}},
|
2024-04-17 19:24:51 +02:00
|
|
|
cases: []ConfigurableCase[bool]{{
|
2024-04-27 01:39:54 +02:00
|
|
|
patterns: []ConfigurablePattern{{
|
|
|
|
typ: configurablePatternTypeString,
|
|
|
|
stringValue: "a",
|
|
|
|
}},
|
2024-04-17 19:24:51 +02:00
|
|
|
value: BoolPtr(true),
|
2024-04-27 01:39:54 +02:00
|
|
|
}, {
|
|
|
|
patterns: []ConfigurablePattern{{
|
|
|
|
typ: configurablePatternTypeDefault,
|
|
|
|
}},
|
|
|
|
value: BoolPtr(false),
|
2024-04-17 19:24:51 +02:00
|
|
|
}},
|
2024-04-27 01:39:54 +02:00
|
|
|
},
|
|
|
|
next: &configurableInner[bool]{
|
|
|
|
single: singleConfigurable[bool]{
|
|
|
|
cases: []ConfigurableCase[bool]{{
|
|
|
|
value: BoolPtr(true),
|
|
|
|
}},
|
|
|
|
},
|
2024-04-17 19:24:51 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Append bool to Configurable[bool]",
|
|
|
|
order: Append,
|
|
|
|
dst: []interface{}{
|
|
|
|
&struct{ S Configurable[bool] }{
|
|
|
|
S: Configurable[bool]{
|
2024-04-27 01:39:54 +02:00
|
|
|
inner: &configurableInner[bool]{
|
|
|
|
single: singleConfigurable[bool]{
|
|
|
|
conditions: []ConfigurableCondition{{
|
|
|
|
functionName: "soong_config_variable",
|
|
|
|
args: []string{
|
|
|
|
"my_namespace",
|
|
|
|
"foo",
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
cases: []ConfigurableCase[bool]{{
|
|
|
|
patterns: []ConfigurablePattern{{
|
|
|
|
typ: configurablePatternTypeString,
|
|
|
|
stringValue: "a",
|
|
|
|
}},
|
|
|
|
value: BoolPtr(true),
|
|
|
|
}, {
|
|
|
|
patterns: []ConfigurablePattern{{
|
|
|
|
typ: configurablePatternTypeDefault,
|
|
|
|
}},
|
|
|
|
value: BoolPtr(false),
|
|
|
|
}},
|
2024-04-17 19:24:51 +02:00
|
|
|
},
|
2024-04-27 01:39:54 +02:00
|
|
|
},
|
2024-04-17 19:24:51 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
src: &struct{ S bool }{
|
|
|
|
S: true,
|
|
|
|
},
|
|
|
|
out: []interface{}{
|
|
|
|
&struct{ S Configurable[bool] }{
|
|
|
|
S: Configurable[bool]{
|
2024-04-27 01:39:54 +02:00
|
|
|
inner: &configurableInner[bool]{
|
|
|
|
single: singleConfigurable[bool]{
|
|
|
|
conditions: []ConfigurableCondition{{
|
|
|
|
functionName: "soong_config_variable",
|
|
|
|
args: []string{
|
|
|
|
"my_namespace",
|
|
|
|
"foo",
|
|
|
|
},
|
|
|
|
}},
|
2024-04-17 19:24:51 +02:00
|
|
|
cases: []ConfigurableCase[bool]{{
|
2024-04-27 01:39:54 +02:00
|
|
|
patterns: []ConfigurablePattern{{
|
|
|
|
typ: configurablePatternTypeString,
|
|
|
|
stringValue: "a",
|
|
|
|
}},
|
2024-04-17 19:24:51 +02:00
|
|
|
value: BoolPtr(true),
|
2024-04-27 01:39:54 +02:00
|
|
|
}, {
|
|
|
|
patterns: []ConfigurablePattern{{
|
|
|
|
typ: configurablePatternTypeDefault,
|
|
|
|
}},
|
|
|
|
value: BoolPtr(false),
|
2024-04-17 19:24:51 +02:00
|
|
|
}},
|
2024-04-27 01:39:54 +02:00
|
|
|
},
|
|
|
|
next: &configurableInner[bool]{
|
|
|
|
single: singleConfigurable[bool]{
|
|
|
|
cases: []ConfigurableCase[bool]{{
|
|
|
|
value: BoolPtr(true),
|
|
|
|
}},
|
|
|
|
},
|
2024-04-17 19:24:51 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-05-06 00:58:02 +02:00
|
|
|
}
|
2015-10-28 02:15:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAppendMatchingProperties(t *testing.T) {
|
2016-05-06 00:58:02 +02:00
|
|
|
for _, testCase := range appendMatchingPropertiesTestCases() {
|
2021-05-21 23:56:53 +02:00
|
|
|
t.Run(testCase.name, func(t *testing.T) {
|
2015-10-28 02:15:15 +01:00
|
|
|
|
2021-05-21 23:56:53 +02:00
|
|
|
got := testCase.dst
|
|
|
|
var err error
|
|
|
|
var testType string
|
2015-10-28 02:15:15 +01:00
|
|
|
|
2021-05-21 23:56:53 +02:00
|
|
|
switch testCase.order {
|
|
|
|
case Append:
|
|
|
|
testType = "append"
|
|
|
|
err = AppendMatchingProperties(got, testCase.src, testCase.filter)
|
|
|
|
case Prepend:
|
|
|
|
testType = "prepend"
|
|
|
|
err = PrependMatchingProperties(got, testCase.src, testCase.filter)
|
|
|
|
case Replace:
|
|
|
|
testType = "replace"
|
|
|
|
err = ExtendMatchingProperties(got, testCase.src, testCase.filter, OrderReplace)
|
|
|
|
}
|
2015-10-28 02:15:15 +01:00
|
|
|
|
2021-05-21 23:56:53 +02:00
|
|
|
check(t, testType, testCase.name, got, err, testCase.out, testCase.err)
|
|
|
|
})
|
2015-10-28 02:15:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-06 00:58:02 +02:00
|
|
|
func TestExtendMatchingProperties(t *testing.T) {
|
|
|
|
for _, testCase := range appendMatchingPropertiesTestCases() {
|
2021-05-21 23:56:53 +02:00
|
|
|
t.Run(testCase.name, func(t *testing.T) {
|
2016-05-06 00:58:02 +02:00
|
|
|
|
2021-05-21 23:56:53 +02:00
|
|
|
got := testCase.dst
|
|
|
|
var err error
|
|
|
|
var testType string
|
|
|
|
|
2024-02-01 23:37:14 +01:00
|
|
|
order := func(dstField, srcField reflect.StructField) (Order, error) {
|
2021-05-21 23:56:53 +02:00
|
|
|
switch testCase.order {
|
|
|
|
case Append:
|
|
|
|
return Append, nil
|
|
|
|
case Prepend:
|
|
|
|
return Prepend, nil
|
|
|
|
case Replace:
|
|
|
|
return Replace, nil
|
|
|
|
}
|
|
|
|
return Append, errors.New("unknown order")
|
|
|
|
}
|
2016-05-06 00:58:02 +02:00
|
|
|
|
2019-11-15 10:31:56 +01:00
|
|
|
switch testCase.order {
|
|
|
|
case Append:
|
2021-05-21 23:56:53 +02:00
|
|
|
testType = "prepend matching"
|
2019-11-15 10:31:56 +01:00
|
|
|
case Prepend:
|
2021-05-21 23:56:53 +02:00
|
|
|
testType = "append matching"
|
2019-11-15 10:31:56 +01:00
|
|
|
case Replace:
|
2021-05-21 23:56:53 +02:00
|
|
|
testType = "replace matching"
|
2016-05-06 00:58:02 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 23:56:53 +02:00
|
|
|
err = ExtendMatchingProperties(got, testCase.src, testCase.filter, order)
|
2016-05-06 00:58:02 +02:00
|
|
|
|
2021-05-21 23:56:53 +02:00
|
|
|
check(t, testType, testCase.name, got, err, testCase.out, testCase.err)
|
|
|
|
})
|
2016-05-06 00:58:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-28 02:15:15 +01:00
|
|
|
func check(t *testing.T, testType, testString string,
|
|
|
|
got interface{}, err error,
|
|
|
|
expected interface{}, expectedErr error) {
|
|
|
|
|
|
|
|
printedTestCase := false
|
|
|
|
e := func(s string, expected, got interface{}) {
|
|
|
|
if !printedTestCase {
|
|
|
|
t.Errorf("test case %s: %s", testType, testString)
|
|
|
|
printedTestCase = true
|
|
|
|
}
|
|
|
|
t.Errorf("incorrect %s", s)
|
|
|
|
t.Errorf(" expected: %s", p(expected))
|
|
|
|
t.Errorf(" got: %s", p(got))
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if expectedErr != nil {
|
|
|
|
if err.Error() != expectedErr.Error() {
|
|
|
|
e("unexpected error", expectedErr.Error(), err.Error())
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
e("unexpected error", nil, err.Error())
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if expectedErr != nil {
|
|
|
|
e("missing error", expectedErr, nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expected, got) {
|
|
|
|
e("output:", expected, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func p(in interface{}) string {
|
|
|
|
if v, ok := in.([]interface{}); ok {
|
|
|
|
s := make([]string, len(v))
|
|
|
|
for i := range v {
|
|
|
|
s[i] = fmt.Sprintf("%#v", v[i])
|
|
|
|
}
|
|
|
|
return "[" + strings.Join(s, ", ") + "]"
|
|
|
|
} else {
|
|
|
|
return fmt.Sprintf("%#v", in)
|
|
|
|
}
|
|
|
|
}
|