diff --git a/syntax/encoding/alloyjson/alloyjson_test.go b/syntax/encoding/alloyjson/alloyjson_test.go index 3af2e02b30..2e9bf65269 100644 --- a/syntax/encoding/alloyjson/alloyjson_test.go +++ b/syntax/encoding/alloyjson/alloyjson_test.go @@ -201,7 +201,7 @@ func TestBlock(t *testing.T) { func TestBlock_Empty_Required_Block_Slice(t *testing.T) { type wrapper struct { - Blocks []testBlock `river:"some_block,block"` + Blocks []testBlock `alloy:"some_block,block"` } tt := []struct { @@ -224,19 +224,19 @@ func TestBlock_Empty_Required_Block_Slice(t *testing.T) { } type testBlock struct { - Number int `river:"number,attr,optional"` - String string `river:"string,attr,optional"` - Boolean bool `river:"boolean,attr,optional"` - Array []any `river:"array,attr,optional"` - Object map[string]any `river:"object,attr,optional"` - - Labeled []labeledBlock `river:"labeled_block,block,optional"` - Blocks []testBlock `river:"inner_block,block,optional"` + Number int `alloy:"number,attr,optional"` + String string `alloy:"string,attr,optional"` + Boolean bool `alloy:"boolean,attr,optional"` + Array []any `alloy:"array,attr,optional"` + Object map[string]any `alloy:"object,attr,optional"` + + Labeled []labeledBlock `alloy:"labeled_block,block,optional"` + Blocks []testBlock `alloy:"inner_block,block,optional"` } type labeledBlock struct { - TestBlock testBlock `river:",squash"` - Label string `river:",label"` + TestBlock testBlock `alloy:",squash"` + Label string `alloy:",label"` } func TestNilBody(t *testing.T) { @@ -300,8 +300,8 @@ func TestHideDefaults(t *testing.T) { } type defaultsBlock struct { - Name string `river:"name,attr,optional"` - Age int `river:"age,attr,optional"` + Name string `alloy:"name,attr,optional"` + Age int `alloy:"age,attr,optional"` } var _ syntax.Defaulter = (*defaultsBlock)(nil) @@ -315,7 +315,7 @@ func (d *defaultsBlock) SetToDefault() { func TestMapBlocks(t *testing.T) { type block struct { - Value map[string]any `river:"block,block,optional"` + Value map[string]any `alloy:"block,block,optional"` } val := block{Value: map[string]any{"field": "value"}} diff --git a/syntax/internal/syntaxtags/syntaxtags.go b/syntax/internal/syntaxtags/syntaxtags.go index 3c1f8f859b..d8262bbb84 100644 --- a/syntax/internal/syntaxtags/syntaxtags.go +++ b/syntax/internal/syntaxtags/syntaxtags.go @@ -109,11 +109,11 @@ func (f Field) IsLabel() bool { return f.Flags&FlagLabel != 0 } // Get returns the list of tagged fields for some struct type ty. Get panics if // ty is not a struct type. // -// Get examines each tagged field in ty for a river key. The river key is then +// Get examines each tagged field in ty for an alloy key. The alloy key is then // parsed as containing a name for the field, followed by a required // comma-separated list of options. The name may be empty for fields which do -// not require a name. Get will ignore any field that is not tagged with a -// river key. +// not require a name. Get will ignore any field that is not tagged with an +// alloy key. // // Get will treat anonymous struct fields as if the inner fields were fields in // the outer struct. @@ -121,31 +121,31 @@ func (f Field) IsLabel() bool { return f.Flags&FlagLabel != 0 } // Examples of struct field tags and their meanings: // // // Field is used as a required block named "my_block". -// Field struct{} `river:"my_block,block"` +// Field struct{} `alloy:"my_block,block"` // // // Field is used as an optional block named "my_block". -// Field struct{} `river:"my_block,block,optional"` +// Field struct{} `alloy:"my_block,block,optional"` // // // Field is used as a required attribute named "my_attr". -// Field string `river:"my_attr,attr"` +// Field string `alloy:"my_attr,attr"` // // // Field is used as an optional attribute named "my_attr". -// Field string `river:"my_attr,attr,optional"` +// Field string `alloy:"my_attr,attr,optional"` // // // Field is used for storing the label of the block which the struct // // represents. -// Field string `river:",label"` +// Field string `alloy:",label"` // // // Attributes and blocks inside of Field are exposed as top-level fields. -// Field struct{} `river:",squash"` +// Field struct{} `alloy:",squash"` // -// Blocks []struct{} `river:"my_block_prefix,enum"` +// Blocks []struct{} `alloy:"my_block_prefix,enum"` // -// With the exception of the `river:",label"` and `river:",squash" tags, all +// With the exception of the `alloy:",label"` and `alloy:",squash" tags, all // tagged fields must have a unique name. // // The type of tagged fields may be any Go type, with the exception of -// `river:",label"` tags, which must be strings. +// `alloy:",label"` tags, which must be strings. func Get(ty reflect.Type) []Field { if k := ty.Kind(); k != reflect.Struct { panic(fmt.Sprintf("syntaxtags: Get requires struct kind, got %s", k)) @@ -164,13 +164,13 @@ func Get(ty reflect.Type) []Field { panic(fmt.Sprintf("syntax: anonymous fields not supported %s", printPathToField(ty, field.Index))) } - tag, tagged := field.Tag.Lookup("river") + tag, tagged := field.Tag.Lookup("alloy") if !tagged { continue } if !field.IsExported() { - panic(fmt.Sprintf("syntax: river tag found on unexported field at %s", printPathToField(ty, field.Index))) + panic(fmt.Sprintf("syntax: alloy tag found on unexported field at %s", printPathToField(ty, field.Index))) } options := strings.SplitN(tag, ",", 2) @@ -195,7 +195,7 @@ func Get(ty reflect.Type) []Field { flags, ok := parseFlags(options[1]) if !ok { - panic(fmt.Sprintf("syntax: unrecognized river tag format %q at %s", tag, printPathToField(ty, tf.Index))) + panic(fmt.Sprintf("syntax: unrecognized alloy tag format %q at %s", tag, printPathToField(ty, tf.Index))) } tf.Flags = flags diff --git a/syntax/internal/syntaxtags/syntaxtags_test.go b/syntax/internal/syntaxtags/syntaxtags_test.go index 6c9b1b4633..e2ecc8ff02 100644 --- a/syntax/internal/syntaxtags/syntaxtags_test.go +++ b/syntax/internal/syntaxtags/syntaxtags_test.go @@ -13,13 +13,13 @@ func Test_Get(t *testing.T) { type Struct struct { IgnoreMe bool - ReqAttr string `river:"req_attr,attr"` - OptAttr string `river:"opt_attr,attr,optional"` - ReqBlock struct{} `river:"req_block,block"` - OptBlock struct{} `river:"opt_block,block,optional"` - ReqEnum []struct{} `river:"req_enum,enum"` - OptEnum []struct{} `river:"opt_enum,enum,optional"` - Label string `river:",label"` + ReqAttr string `alloy:"req_attr,attr"` + OptAttr string `alloy:"opt_attr,attr,optional"` + ReqBlock struct{} `alloy:"req_block,block"` + OptBlock struct{} `alloy:"opt_block,block,optional"` + ReqEnum []struct{} `alloy:"req_enum,enum"` + OptEnum []struct{} `alloy:"opt_enum,enum,optional"` + Label string `alloy:",label"` } fs := syntaxtags.Get(reflect.TypeOf(Struct{})) @@ -39,34 +39,34 @@ func Test_Get(t *testing.T) { func TestEmbedded(t *testing.T) { type InnerStruct struct { - InnerField1 string `river:"inner_field_1,attr"` - InnerField2 string `river:"inner_field_2,attr"` + InnerField1 string `alloy:"inner_field_1,attr"` + InnerField2 string `alloy:"inner_field_2,attr"` } type Struct struct { - Field1 string `river:"parent_field_1,attr"` + Field1 string `alloy:"parent_field_1,attr"` InnerStruct - Field2 string `river:"parent_field_2,attr"` + Field2 string `alloy:"parent_field_2,attr"` } require.PanicsWithValue(t, "syntax: anonymous fields not supported syntaxtags_test.Struct.InnerStruct", func() { syntaxtags.Get(reflect.TypeOf(Struct{})) }) } func TestSquash(t *testing.T) { type InnerStruct struct { - InnerField1 string `river:"inner_field_1,attr"` - InnerField2 string `river:"inner_field_2,attr"` + InnerField1 string `alloy:"inner_field_1,attr"` + InnerField2 string `alloy:"inner_field_2,attr"` } type Struct struct { - Field1 string `river:"parent_field_1,attr"` - Inner InnerStruct `river:",squash"` - Field2 string `river:"parent_field_2,attr"` + Field1 string `alloy:"parent_field_1,attr"` + Inner InnerStruct `alloy:",squash"` + Field2 string `alloy:"parent_field_2,attr"` } type StructWithPointer struct { - Field1 string `river:"parent_field_1,attr"` - Inner *InnerStruct `river:",squash"` - Field2 string `river:"parent_field_2,attr"` + Field1 string `alloy:"parent_field_1,attr"` + Inner *InnerStruct `alloy:",squash"` + Field2 string `alloy:"parent_field_2,attr"` } expect := []syntaxtags.Field{ @@ -101,16 +101,16 @@ func TestSquash(t *testing.T) { func TestDeepSquash(t *testing.T) { type Inner2Struct struct { - InnerField1 string `river:"inner_field_1,attr"` - InnerField2 string `river:"inner_field_2,attr"` + InnerField1 string `alloy:"inner_field_1,attr"` + InnerField2 string `alloy:"inner_field_2,attr"` } type InnerStruct struct { - Inner2Struct Inner2Struct `river:",squash"` + Inner2Struct Inner2Struct `alloy:",squash"` } type Struct struct { - Inner InnerStruct `river:",squash"` + Inner InnerStruct `alloy:",squash"` } expect := []syntaxtags.Field{ @@ -140,15 +140,15 @@ func Test_Get_Panics(t *testing.T) { t.Run("Tagged fields must be exported", func(t *testing.T) { type Struct struct { - attr string `river:"field,attr"` // nolint:unused //nolint:syntaxtags + attr string `alloy:"field,attr"` // nolint:unused //nolint:syntaxtags } - expect := `syntax: river tag found on unexported field at syntaxtags_test.Struct.attr` + expect := `syntax: alloy tag found on unexported field at syntaxtags_test.Struct.attr` expectPanic(t, expect, Struct{}) }) t.Run("Options are required", func(t *testing.T) { type Struct struct { - Attr string `river:"field"` //nolint:syntaxtags + Attr string `alloy:"field"` //nolint:syntaxtags } expect := `syntax: field syntaxtags_test.Struct.Attr tag is missing options` expectPanic(t, expect, Struct{}) @@ -156,8 +156,8 @@ func Test_Get_Panics(t *testing.T) { t.Run("Field names must be unique", func(t *testing.T) { type Struct struct { - Attr string `river:"field1,attr"` - Block string `river:"field1,block,optional"` //nolint:syntaxtags + Attr string `alloy:"field1,attr"` + Block string `alloy:"field1,block,optional"` //nolint:syntaxtags } expect := `syntax: field name field1 already used by syntaxtags_test.Struct.Attr` expectPanic(t, expect, Struct{}) @@ -165,7 +165,7 @@ func Test_Get_Panics(t *testing.T) { t.Run("Name is required for non-label field", func(t *testing.T) { type Struct struct { - Attr string `river:",attr"` //nolint:syntaxtags + Attr string `alloy:",attr"` //nolint:syntaxtags } expect := `syntaxtags: non-empty field name required at syntaxtags_test.Struct.Attr` expectPanic(t, expect, Struct{}) @@ -173,8 +173,8 @@ func Test_Get_Panics(t *testing.T) { t.Run("Only one label field may exist", func(t *testing.T) { type Struct struct { - Label1 string `river:",label"` - Label2 string `river:",label"` + Label1 string `alloy:",label"` + Label2 string `alloy:",label"` } expect := `syntax: label field already used by syntaxtags_test.Struct.Label2` expectPanic(t, expect, Struct{}) diff --git a/syntax/internal/value/decode_test.go b/syntax/internal/value/decode_test.go index a53b9553af..4908a68577 100644 --- a/syntax/internal/value/decode_test.go +++ b/syntax/internal/value/decode_test.go @@ -48,11 +48,11 @@ func TestDecode(t *testing.T) { // Declare some types to use for testing. Person2 is used as a struct // equivalent to Person, but with a different Go type to force casting. type Person struct { - Name string `river:"name,attr"` + Name string `alloy:"name,attr"` } type Person2 struct { - Name string `river:"name,attr"` + Name string `alloy:"name,attr"` } tt := []struct { @@ -288,9 +288,9 @@ func TestDecode_CustomTypes(t *testing.T) { } type customUnmarshaler struct { - UnmarshalCalled bool `river:"unmarshal_called,attr,optional"` - DefaultCalled bool `river:"default_called,attr,optional"` - ValidateCalled bool `river:"validate_called,attr,optional"` + UnmarshalCalled bool `alloy:"unmarshal_called,attr,optional"` + DefaultCalled bool `alloy:"default_called,attr,optional"` + ValidateCalled bool `alloy:"validate_called,attr,optional"` } func (cu *customUnmarshaler) UnmarshalRiver(f func(interface{}) error) error { @@ -359,9 +359,9 @@ func TestDecode_ErrorChain(t *testing.T) { type Target struct { Key struct { Object struct { - Field1 []int `river:"field1,attr"` - } `river:"object,attr"` - } `river:"key,attr"` + Field1 []int `alloy:"field1,attr"` + } `alloy:"object,attr"` + } `alloy:"key,attr"` } val := value.Object(map[string]value.Value{ @@ -457,14 +457,14 @@ func TestDecode_CustomConvert(t *testing.T) { func TestDecode_SquashedFields(t *testing.T) { type InnerStruct struct { - InnerField1 string `river:"inner_field_1,attr,optional"` - InnerField2 string `river:"inner_field_2,attr,optional"` + InnerField1 string `alloy:"inner_field_1,attr,optional"` + InnerField2 string `alloy:"inner_field_2,attr,optional"` } type OuterStruct struct { - OuterField1 string `river:"outer_field_1,attr,optional"` - Inner InnerStruct `river:",squash"` - OuterField2 string `river:"outer_field_2,attr,optional"` + OuterField1 string `alloy:"outer_field_1,attr,optional"` + Inner InnerStruct `alloy:",squash"` + OuterField2 string `alloy:"outer_field_2,attr,optional"` } var ( @@ -492,14 +492,14 @@ func TestDecode_SquashedFields(t *testing.T) { func TestDecode_SquashedFields_Pointer(t *testing.T) { type InnerStruct struct { - InnerField1 string `river:"inner_field_1,attr,optional"` - InnerField2 string `river:"inner_field_2,attr,optional"` + InnerField1 string `alloy:"inner_field_1,attr,optional"` + InnerField2 string `alloy:"inner_field_2,attr,optional"` } type OuterStruct struct { - OuterField1 string `river:"outer_field_1,attr,optional"` - Inner *InnerStruct `river:",squash"` - OuterField2 string `river:"outer_field_2,attr,optional"` + OuterField1 string `alloy:"outer_field_1,attr,optional"` + Inner *InnerStruct `alloy:",squash"` + OuterField2 string `alloy:"outer_field_2,attr,optional"` } var ( @@ -527,11 +527,11 @@ func TestDecode_SquashedFields_Pointer(t *testing.T) { func TestDecode_Slice(t *testing.T) { type Block struct { - Attr int `river:"attr,attr"` + Attr int `alloy:"attr,attr"` } type Struct struct { - Blocks []Block `river:"block.a,block,optional"` + Blocks []Block `alloy:"block.a,block,optional"` } var ( @@ -563,19 +563,19 @@ func TestDecode_Slice(t *testing.T) { func TestDecode_SquashedSlice(t *testing.T) { type Block struct { - Attr int `river:"attr,attr"` + Attr int `alloy:"attr,attr"` } type InnerStruct struct { - BlockA Block `river:"a,block,optional"` - BlockB Block `river:"b,block,optional"` - BlockC Block `river:"c,block,optional"` + BlockA Block `alloy:"a,block,optional"` + BlockB Block `alloy:"b,block,optional"` + BlockC Block `alloy:"c,block,optional"` } type OuterStruct struct { - OuterField1 string `river:"outer_field_1,attr,optional"` - Inner []InnerStruct `river:"block,enum"` - OuterField2 string `river:"outer_field_2,attr,optional"` + OuterField1 string `alloy:"outer_field_1,attr,optional"` + Inner []InnerStruct `alloy:"block,enum"` + OuterField2 string `alloy:"outer_field_2,attr,optional"` } var ( @@ -611,19 +611,19 @@ func TestDecode_SquashedSlice(t *testing.T) { func TestDecode_SquashedSlice_Pointer(t *testing.T) { type Block struct { - Attr int `river:"attr,attr"` + Attr int `alloy:"attr,attr"` } type InnerStruct struct { - BlockA *Block `river:"a,block,optional"` - BlockB *Block `river:"b,block,optional"` - BlockC *Block `river:"c,block,optional"` + BlockA *Block `alloy:"a,block,optional"` + BlockB *Block `alloy:"b,block,optional"` + BlockC *Block `alloy:"c,block,optional"` } type OuterStruct struct { - OuterField1 string `river:"outer_field_1,attr,optional"` - Inner []InnerStruct `river:"block,enum"` - OuterField2 string `river:"outer_field_2,attr,optional"` + OuterField1 string `alloy:"outer_field_1,attr,optional"` + Inner []InnerStruct `alloy:"block,enum"` + OuterField2 string `alloy:"outer_field_2,attr,optional"` } var ( @@ -703,7 +703,7 @@ func TestDecode_KnownTypes_Any(t *testing.T) { }, { input: struct { - Name string `river:"name,attr"` + Name string `alloy:"name,attr"` }{Name: "John"}, expect: map[string]any{"name": "John"}, diff --git a/syntax/internal/value/type_test.go b/syntax/internal/value/type_test.go index 7a595d1a51..066089ed8c 100644 --- a/syntax/internal/value/type_test.go +++ b/syntax/internal/value/type_test.go @@ -43,7 +43,7 @@ var typeTests = []struct { // A slice of labeled blocks should be an object. {[]struct { - Label string `river:",label"` + Label string `alloy:",label"` }{}, value.TypeObject}, {map[string]interface{}{}, value.TypeObject}, diff --git a/syntax/internal/value/value_object_test.go b/syntax/internal/value/value_object_test.go index 1cb90eb872..dabb9ec3ca 100644 --- a/syntax/internal/value/value_object_test.go +++ b/syntax/internal/value/value_object_test.go @@ -11,23 +11,23 @@ import ( // represented correctly. func TestBlockRepresentation(t *testing.T) { type UnlabledBlock struct { - Value int `river:"value,attr"` + Value int `alloy:"value,attr"` } type LabeledBlock struct { - Value int `river:"value,attr"` - Label string `river:",label"` + Value int `alloy:"value,attr"` + Label string `alloy:",label"` } type OuterBlock struct { - Attr1 string `river:"attr_1,attr"` - Attr2 string `river:"attr_2,attr"` + Attr1 string `alloy:"attr_1,attr"` + Attr2 string `alloy:"attr_2,attr"` - UnlabledBlock1 UnlabledBlock `river:"unlabeled.a,block"` - UnlabledBlock2 UnlabledBlock `river:"unlabeled.b,block"` - UnlabledBlock3 UnlabledBlock `river:"other_unlabeled,block"` + UnlabledBlock1 UnlabledBlock `alloy:"unlabeled.a,block"` + UnlabledBlock2 UnlabledBlock `alloy:"unlabeled.b,block"` + UnlabledBlock3 UnlabledBlock `alloy:"other_unlabeled,block"` - LabeledBlock1 LabeledBlock `river:"labeled.a,block"` - LabeledBlock2 LabeledBlock `river:"labeled.b,block"` - LabeledBlock3 LabeledBlock `river:"other_labeled,block"` + LabeledBlock1 LabeledBlock `alloy:"labeled.a,block"` + LabeledBlock2 LabeledBlock `alloy:"labeled.b,block"` + LabeledBlock3 LabeledBlock `alloy:"other_labeled,block"` } val := OuterBlock{ @@ -101,14 +101,14 @@ func TestBlockRepresentation(t *testing.T) { // blocks are represented correctly. func TestSquashedBlockRepresentation(t *testing.T) { type InnerStruct struct { - InnerField1 string `river:"inner_field_1,attr,optional"` - InnerField2 string `river:"inner_field_2,attr,optional"` + InnerField1 string `alloy:"inner_field_1,attr,optional"` + InnerField2 string `alloy:"inner_field_2,attr,optional"` } type OuterStruct struct { - OuterField1 string `river:"outer_field_1,attr,optional"` - Inner InnerStruct `river:",squash"` - OuterField2 string `river:"outer_field_2,attr,optional"` + OuterField1 string `alloy:"outer_field_1,attr,optional"` + Inner InnerStruct `alloy:",squash"` + OuterField2 string `alloy:"outer_field_2,attr,optional"` } val := OuterStruct{ @@ -139,18 +139,18 @@ func TestSquashedBlockRepresentation(t *testing.T) { func TestSliceOfBlocks(t *testing.T) { type UnlabledBlock struct { - Value int `river:"value,attr"` + Value int `alloy:"value,attr"` } type LabeledBlock struct { - Value int `river:"value,attr"` - Label string `river:",label"` + Value int `alloy:"value,attr"` + Label string `alloy:",label"` } type OuterBlock struct { - Attr1 string `river:"attr_1,attr"` - Attr2 string `river:"attr_2,attr"` + Attr1 string `alloy:"attr_1,attr"` + Attr2 string `alloy:"attr_2,attr"` - Unlabeled []UnlabledBlock `river:"unlabeled,block"` - Labeled []LabeledBlock `river:"labeled,block"` + Unlabeled []UnlabledBlock `alloy:"unlabeled,block"` + Labeled []LabeledBlock `alloy:"labeled,block"` } val := OuterBlock{ diff --git a/syntax/internal/value/value_test.go b/syntax/internal/value/value_test.go index ef75a8403f..fbebcabdd7 100644 --- a/syntax/internal/value/value_test.go +++ b/syntax/internal/value/value_test.go @@ -13,7 +13,7 @@ import ( // throughout values with a key lookup. func TestEncodeKeyLookup(t *testing.T) { type Body struct { - Data pointerMarshaler `river:"data,attr"` + Data pointerMarshaler `alloy:"data,attr"` } tt := []struct { @@ -230,7 +230,7 @@ func TestValue_Call(t *testing.T) { func TestValue_Interface_In_Array(t *testing.T) { type Container struct { - Field io.Closer `river:"field,attr"` + Field io.Closer `alloy:"field,attr"` } val := value.Encode(Container{Field: io.NopCloser(nil)}) diff --git a/syntax/syntax.go b/syntax/syntax.go index 44a256603e..8e32975cba 100644 --- a/syntax/syntax.go +++ b/syntax/syntax.go @@ -18,16 +18,16 @@ import ( ) // Marshal returns the pretty-printed encoding of v as a River configuration -// file. v must be a Go struct with river struct tags which determine the +// file. v must be a Go struct with alloy struct tags which determine the // structure of the resulting file. // // Marshal traverses the value v recursively, encoding each struct field as a -// River block or River attribute, based on the flags provided to the river +// River block or River attribute, based on the flags provided to the alloy // struct tag. // // When a struct field represents a River block, Marshal creates a new block // and recursively encodes the value as the body of the block. The name of the -// created block is taken from the name specified by the river struct tag. +// created block is taken from the name specified by the alloy struct tag. // // Struct fields which represent River blocks must be either a Go struct or a // slice of Go structs. When the field is a Go struct, its value is encoded as @@ -40,7 +40,7 @@ import ( // the string type. When specified, there must not be more than one struct // field which represents a block label. // -// The river tag specifies a name, possibly followed by a comma-separated list +// The alloy tag specifies a name, possibly followed by a comma-separated list // of options. The name must be empty if the provided options do not support a // name being defined. The following provides examples for all supported struct // field tags with their meanings: @@ -48,62 +48,62 @@ import ( // // Field appears as a block named "example". It will always appear in the // // resulting encoding. When decoding, "example" is treated as a required // // block and must be present in the source text. -// Field struct{...} `river:"example,block"` +// Field struct{...} `alloy:"example,block"` // // // Field appears as a set of blocks named "example." It will appear in the // // resulting encoding if there is at least one element in the slice. When // // decoding, "example" is treated as a required block and at least one // // "example" block must be present in the source text. -// Field []struct{...} `river:"example,block"` +// Field []struct{...} `alloy:"example,block"` // // // Field appears as block named "example." It will always appear in the // // resulting encoding. When decoding, "example" is treated as an optional // // block and can be omitted from the source text. -// Field struct{...} `river:"example,block,optional"` +// Field struct{...} `alloy:"example,block,optional"` // // // Field appears as a set of blocks named "example." It will appear in the // // resulting encoding if there is at least one element in the slice. When // // decoding, "example" is treated as an optional block and can be omitted // // from the source text. -// Field []struct{...} `river:"example,block,optional"` +// Field []struct{...} `alloy:"example,block,optional"` // // // Field appears as an attribute named "example." It will always appear in // // the resulting encoding. When decoding, "example" is treated as a // // required attribute and must be present in the source text. -// Field bool `river:"example,attr"` +// Field bool `alloy:"example,attr"` // // // Field appears as an attribute named "example." If the field's value is // // the Go zero value, "example" is omitted from the resulting encoding. // // When decoding, "example" is treated as an optional attribute and can be // // omitted from the source text. -// Field bool `river:"example,attr,optional"` +// Field bool `alloy:"example,attr,optional"` // // // The value of Field appears as the block label for the struct being // // converted into a block. When decoding, a block label must be provided. -// Field string `river:",label"` +// Field string `alloy:",label"` // // // The inner attributes and blocks of Field are exposed as top-level // // attributes and blocks of the outer struct. -// Field struct{...} `river:",squash"` +// Field struct{...} `alloy:",squash"` // // // Field appears as a set of blocks starting with "example.". Only the // // first set element in the struct will be encoded. Each field in struct // // must be a block. The name of the block is prepended to the enum name. // // When decoding, enum blocks are treated as optional blocks and can be // // omitted from the source text. -// Field []struct{...} `river:"example,enum"` +// Field []struct{...} `alloy:"example,enum"` // -// // Field is equivalent to `river:"example,enum"`. -// Field []struct{...} `river:"example,enum,optional"` +// // Field is equivalent to `alloy:"example,enum"`. +// Field []struct{...} `alloy:"example,enum,optional"` // -// If a river tag specifies a required or optional block, the name is permitted +// If an alloy tag specifies a required or optional block, the name is permitted // to contain period `.` characters. // -// Marshal will panic if it encounters a struct with invalid river tags. +// Marshal will panic if it encounters a struct with invalid alloy tags. // // When a struct field represents a River attribute, Marshal encodes the struct // value as a River value. The attribute name will be taken from the name -// specified by the river struct tag. See MarshalValue for the rules used to +// specified by the alloy struct tag. See MarshalValue for the rules used to // convert a Go value into a River value. func Marshal(v interface{}) ([]byte, error) { var buf bytes.Buffer @@ -152,13 +152,13 @@ func Marshal(v interface{}) ([]byte, error) { // // Field appears as an object field named "my_name". It will always // // appear in the resulting encoding. When decoding, "my_name" is treated // // as a required attribute and must be present in the source text. -// Field bool `river:"my_name,attr"` +// Field bool `alloy:"my_name,attr"` // // // Field appears as an object field named "my_name". If the field's value // // is the Go zero value, "example" is omitted from the resulting encoding. // // When decoding, "my_name" is treated as an optional attribute and can be // // omitted from the source text. -// Field bool `river:"my_name,attr,optional"` +// Field bool `alloy:"my_name,attr,optional"` func MarshalValue(v interface{}) ([]byte, error) { var buf bytes.Buffer if err := NewEncoder(&buf).EncodeValue(v); err != nil { @@ -219,10 +219,10 @@ func (enc *Encoder) EncodeValue(v interface{}) error { // unmarshaling into a map. // // To unmarshal a River body into a struct, Unmarshal matches incoming -// attributes and blocks to the river struct tags specified by v. Incoming -// attribute and blocks which do not match to a river struct tag cause a +// attributes and blocks to the alloy struct tags specified by v. Incoming +// attribute and blocks which do not match to an alloy struct tag cause a // decoding error. Additionally, any attribute or block marked as required by -// the river struct tag that are not present in the source text will generate a +// the alloy struct tag that are not present in the source text will generate a // decoding error. // // To unmarshal a list of River blocks into a slice, Unmarshal resets the slice @@ -254,9 +254,9 @@ func Unmarshal(in []byte, v interface{}) error { // ConvertibleIntoCapsule. // // To unmarshal a River object into a struct, UnmarshalValue matches incoming -// object fields to the river struct tags specified by v. Incoming object -// fields which do not match to a river struct tag cause a decoding error. -// Additionally, any object field marked as required by the river struct +// object fields to the alloy struct tags specified by v. Incoming object +// fields which do not match to an alloy struct tag cause a decoding error. +// Additionally, any object field marked as required by the alloy struct // tag that are not present in the source text will generate a decoding error. // // To unmarshal River into an interface value, Unmarshal stores one of the diff --git a/syntax/syntax_test.go b/syntax/syntax_test.go index 747c2c4b6c..28daa923d8 100644 --- a/syntax/syntax_test.go +++ b/syntax/syntax_test.go @@ -12,23 +12,23 @@ func ExampleUnmarshal() { // book. type Character struct { // Name of the character. The name is decoded from the block label. - Name string `river:",label"` + Name string `alloy:",label"` // Age of the character. The age is a required attribute within the block, // and must be set in the config. - Age int `river:"age,attr"` + Age int `alloy:"age,attr"` // Location the character lives in. The location is an optional attribute // within the block. Optional attributes do not have to bet set. - Location string `river:"location,attr,optional"` + Location string `alloy:"location,attr,optional"` } // Book is our overall type where we decode the overall River file into. type Book struct { // Title of the book (required attribute). - Title string `river:"title,attr"` + Title string `alloy:"title,attr"` // List of characters. Each character is a labeled block. The optional tag // means that it is valid not provide a character block. Decoding into a // slice permits there to be multiple specified character blocks. - Characters []*Character `river:"character,block,optional"` + Characters []*Character `alloy:"character,block,optional"` } // Create our book with two characters. @@ -76,7 +76,7 @@ func ExampleUnmarshal_functions() { _ = os.Setenv("EXAMPLE", "Jane Doe") type Data struct { - String string `river:"string,attr"` + String string `alloy:"string,attr"` } input := ` @@ -106,9 +106,9 @@ func ExampleUnmarshalValue() { func ExampleMarshal() { type Person struct { - Name string `river:"name,attr"` - Age int `river:"age,attr"` - Location string `river:"location,attr,optional"` + Name string `alloy:"name,attr"` + Age int `alloy:"age,attr"` + Location string `alloy:"location,attr,optional"` } p := Person{ @@ -129,8 +129,8 @@ func ExampleMarshal() { func ExampleMarshalValue() { type Person struct { - Name string `river:"name,attr"` - Age int `river:"age,attr"` + Name string `alloy:"name,attr"` + Age int `alloy:"age,attr"` } p := Person{ diff --git a/syntax/token/builder/builder_test.go b/syntax/token/builder/builder_test.go index 9869ad6dea..6bb5361af9 100644 --- a/syntax/token/builder/builder_test.go +++ b/syntax/token/builder/builder_test.go @@ -103,8 +103,8 @@ func TestBuilder_GoEncode_SortMapKeys(t *testing.T) { f := builder.NewFile() type Ordered struct { - SomeKey string `river:"some_key,attr"` - OtherKey string `river:"other_key,attr"` + SomeKey string `alloy:"some_key,attr"` + OtherKey string `alloy:"other_key,attr"` } // Maps are unordered because you can't iterate over their keys in a @@ -135,14 +135,14 @@ func TestBuilder_GoEncode_SortMapKeys(t *testing.T) { func TestBuilder_AppendFrom(t *testing.T) { type InnerBlock struct { - Number int `river:"number,attr"` + Number int `alloy:"number,attr"` } type Structure struct { - Field string `river:"field,attr"` + Field string `alloy:"field,attr"` - Block InnerBlock `river:"block,block"` - OtherBlocks []InnerBlock `river:"other_block,block"` + Block InnerBlock `alloy:"block,block"` + OtherBlocks []InnerBlock `alloy:"other_block,block"` } f := builder.NewFile() @@ -177,19 +177,19 @@ func TestBuilder_AppendFrom(t *testing.T) { func TestBuilder_AppendFrom_EnumSlice(t *testing.T) { type InnerBlock struct { - Number int `river:"number,attr"` + Number int `alloy:"number,attr"` } type EnumBlock struct { - BlockA InnerBlock `river:"a,block,optional"` - BlockB InnerBlock `river:"b,block,optional"` - BlockC InnerBlock `river:"c,block,optional"` + BlockA InnerBlock `alloy:"a,block,optional"` + BlockB InnerBlock `alloy:"b,block,optional"` + BlockC InnerBlock `alloy:"c,block,optional"` } type Structure struct { - Field string `river:"field,attr"` + Field string `alloy:"field,attr"` - OtherBlocks []EnumBlock `river:"block,enum"` + OtherBlocks []EnumBlock `alloy:"block,enum"` } f := builder.NewFile() @@ -223,19 +223,19 @@ func TestBuilder_AppendFrom_EnumSlice(t *testing.T) { func TestBuilder_AppendFrom_EnumSlice_Pointer(t *testing.T) { type InnerBlock struct { - Number int `river:"number,attr"` + Number int `alloy:"number,attr"` } type EnumBlock struct { - BlockA *InnerBlock `river:"a,block,optional"` - BlockB *InnerBlock `river:"b,block,optional"` - BlockC *InnerBlock `river:"c,block,optional"` + BlockA *InnerBlock `alloy:"a,block,optional"` + BlockB *InnerBlock `alloy:"b,block,optional"` + BlockC *InnerBlock `alloy:"c,block,optional"` } type Structure struct { - Field string `river:"field,attr"` + Field string `alloy:"field,attr"` - OtherBlocks []EnumBlock `river:"block,enum"` + OtherBlocks []EnumBlock `alloy:"block,enum"` } f := builder.NewFile() @@ -269,10 +269,10 @@ func TestBuilder_AppendFrom_EnumSlice_Pointer(t *testing.T) { func TestBuilder_SkipOptional(t *testing.T) { type Structure struct { - OptFieldA string `river:"opt_field_a,attr,optional"` - OptFieldB string `river:"opt_field_b,attr,optional"` - ReqFieldA string `river:"req_field_a,attr"` - ReqFieldB string `river:"req_field_b,attr"` + OptFieldA string `alloy:"opt_field_a,attr,optional"` + OptFieldB string `alloy:"opt_field_b,attr,optional"` + ReqFieldA string `alloy:"req_field_a,attr"` + ReqFieldB string `alloy:"req_field_b,attr"` } f := builder.NewFile() @@ -346,14 +346,14 @@ func TestBuilder_GoEncode_Tokenizer(t *testing.T) { func TestBuilder_ValueOverrideHook(t *testing.T) { type InnerBlock struct { - AnotherField string `river:"another_field,attr"` + AnotherField string `alloy:"another_field,attr"` } type Structure struct { - Field string `river:"field,attr"` + Field string `alloy:"field,attr"` - Block InnerBlock `river:"block,block"` - OtherBlocks []InnerBlock `river:"other_block,block"` + Block InnerBlock `alloy:"block,block"` + OtherBlocks []InnerBlock `alloy:"other_block,block"` } f := builder.NewFile() @@ -391,7 +391,7 @@ func TestBuilder_ValueOverrideHook(t *testing.T) { func TestBuilder_MapBlocks(t *testing.T) { type block struct { - Value map[string]any `river:"block,block,optional"` + Value map[string]any `alloy:"block,block,optional"` } f := builder.NewFile() diff --git a/syntax/token/builder/nested_defaults_test.go b/syntax/token/builder/nested_defaults_test.go index bd6048a188..90eec5e4d4 100644 --- a/syntax/token/builder/nested_defaults_test.go +++ b/syntax/token/builder/nested_defaults_test.go @@ -165,7 +165,7 @@ func TestPtrPropagatingDefaultWithNil(t *testing.T) { // StructPropagatingDefault has the outer defaults matching the inner block's defaults. The inner block is a struct. type StructPropagatingDefault struct { - Inner AttrWithDefault `river:"inner,block,optional"` + Inner AttrWithDefault `alloy:"inner,block,optional"` } func (o *StructPropagatingDefault) SetToDefault() { @@ -176,7 +176,7 @@ func (o *StructPropagatingDefault) SetToDefault() { // PtrPropagatingDefault has the outer defaults matching the inner block's defaults. The inner block is a pointer. type PtrPropagatingDefault struct { - Inner *AttrWithDefault `river:"inner,block,optional"` + Inner *AttrWithDefault `alloy:"inner,block,optional"` } func (o *PtrPropagatingDefault) SetToDefault() { @@ -187,7 +187,7 @@ func (o *PtrPropagatingDefault) SetToDefault() { // MismatchingDefault has the outer defaults NOT matching the inner block's defaults. The inner block is a pointer. type MismatchingDefault struct { - Inner *AttrWithDefault `river:"inner,block,optional"` + Inner *AttrWithDefault `alloy:"inner,block,optional"` } func (o *MismatchingDefault) SetToDefault() { @@ -198,7 +198,7 @@ func (o *MismatchingDefault) SetToDefault() { // ZeroDefault has the outer defaults setting to zero values. The inner block is a pointer. type ZeroDefault struct { - Inner *AttrWithDefault `river:"inner,block,optional"` + Inner *AttrWithDefault `alloy:"inner,block,optional"` } func (o *ZeroDefault) SetToDefault() { @@ -207,12 +207,12 @@ func (o *ZeroDefault) SetToDefault() { // NoDefaultDefined has no defaults defined. The inner block is a pointer. type NoDefaultDefined struct { - Inner *AttrWithDefault `river:"inner,block,optional"` + Inner *AttrWithDefault `alloy:"inner,block,optional"` } // AttrWithDefault has a default value of a non-zero number. type AttrWithDefault struct { - Number int `river:"number,attr,optional"` + Number int `alloy:"number,attr,optional"` } func (i *AttrWithDefault) SetToDefault() { diff --git a/syntax/types.go b/syntax/types.go index 1005b56da8..585c71b273 100644 --- a/syntax/types.go +++ b/syntax/types.go @@ -24,7 +24,7 @@ type Unmarshaler interface { // UnmarshalRiver is invoked when decoding a River value into a Go value. f // should be called with a pointer to a value to decode into. UnmarshalRiver // will not be called on types which are squashed into the parent struct - // using `river:",squash"`. + // using `alloy:",squash"`. UnmarshalRiver(f func(v interface{}) error) error } @@ -33,7 +33,7 @@ type Unmarshaler interface { type Defaulter interface { // SetToDefault is called when evaluating a block or body to set the value // to its defaults. SetToDefault will not be called on types which are - // squashed into the parent struct using `river:",squash"`. + // squashed into the parent struct using `alloy:",squash"`. SetToDefault() } @@ -42,7 +42,7 @@ type Defaulter interface { type Validator interface { // Validate is called when evaluating a block or body to enforce the // value is valid. Validate will not be called on types which are - // squashed into the parent struct using `river:",squash"`. + // squashed into the parent struct using `alloy:",squash"`. Validate() error } diff --git a/syntax/vm/vm_benchmarks_test.go b/syntax/vm/vm_benchmarks_test.go index 24938b6206..0d1e37335d 100644 --- a/syntax/vm/vm_benchmarks_test.go +++ b/syntax/vm/vm_benchmarks_test.go @@ -56,9 +56,9 @@ func BenchmarkExprs(b *testing.B) { age = 42, }`, expect: struct { - Name string `river:"name,attr"` - Age int `river:"age,attr"` - Country string `river:"country,attr,optional"` + Name string `alloy:"name,attr"` + Age int `alloy:"age,attr"` + Country string `alloy:"country,attr,optional"` }{ Name: "John Doe", Age: 42, diff --git a/syntax/vm/vm_block_test.go b/syntax/vm/vm_block_test.go index 7b4cd34a68..fd39e437b7 100644 --- a/syntax/vm/vm_block_test.go +++ b/syntax/vm/vm_block_test.go @@ -16,14 +16,14 @@ import ( func TestVM_File(t *testing.T) { type block struct { - String string `river:"string,attr"` - Number int `river:"number,attr,optional"` + String string `alloy:"string,attr"` + Number int `alloy:"number,attr,optional"` } type file struct { - SettingA int `river:"setting_a,attr"` - SettingB int `river:"setting_b,attr,optional"` + SettingA int `alloy:"setting_a,attr"` + SettingB int `alloy:"setting_b,attr,optional"` - Block block `river:"some_block,block,optional"` + Block block `alloy:"some_block,block,optional"` } input := ` @@ -54,8 +54,8 @@ func TestVM_File(t *testing.T) { func TestVM_Block_Attributes(t *testing.T) { t.Run("Decodes attributes", func(t *testing.T) { type block struct { - Number int `river:"number,attr"` - String string `river:"string,attr"` + Number int `alloy:"number,attr"` + String string `alloy:"string,attr"` } input := `some_block { @@ -72,7 +72,7 @@ func TestVM_Block_Attributes(t *testing.T) { t.Run("Fails if attribute used as block", func(t *testing.T) { type block struct { - Number int `river:"number,attr"` + Number int `alloy:"number,attr"` } input := `some_block { @@ -86,8 +86,8 @@ func TestVM_Block_Attributes(t *testing.T) { t.Run("Fails if required attributes are not present", func(t *testing.T) { type block struct { - Number int `river:"number,attr"` - String string `river:"string,attr"` + Number int `alloy:"number,attr"` + String string `alloy:"string,attr"` } input := `some_block { @@ -101,8 +101,8 @@ func TestVM_Block_Attributes(t *testing.T) { t.Run("Succeeds if optional attributes are not present", func(t *testing.T) { type block struct { - Number int `river:"number,attr"` - String string `river:"string,attr,optional"` + Number int `alloy:"number,attr"` + String string `alloy:"string,attr,optional"` } input := `some_block { @@ -118,7 +118,7 @@ func TestVM_Block_Attributes(t *testing.T) { t.Run("Fails if attribute is not defined in struct", func(t *testing.T) { type block struct { - Number int `river:"number,attr"` + Number int `alloy:"number,attr"` } input := `some_block { @@ -133,7 +133,7 @@ func TestVM_Block_Attributes(t *testing.T) { t.Run("Tests decoding into an interface", func(t *testing.T) { type block struct { - Anything interface{} `river:"anything,attr"` + Anything interface{} `alloy:"anything,attr"` } tests := []struct { @@ -169,10 +169,10 @@ func TestVM_Block_Attributes(t *testing.T) { t.Run("Supports arbitrarily nested struct pointer fields", func(t *testing.T) { type block struct { - NumberA int `river:"number_a,attr"` - NumberB *int `river:"number_b,attr"` - NumberC **int `river:"number_c,attr"` - NumberD ***int `river:"number_d,attr"` + NumberA int `alloy:"number_a,attr"` + NumberB *int `alloy:"number_b,attr"` + NumberC **int `alloy:"number_c,attr"` + NumberD ***int `alloy:"number_d,attr"` } input := `some_block { @@ -193,14 +193,14 @@ func TestVM_Block_Attributes(t *testing.T) { t.Run("Supports squashed attributes", func(t *testing.T) { type InnerStruct struct { - InnerField1 string `river:"inner_field_1,attr,optional"` - InnerField2 string `river:"inner_field_2,attr,optional"` + InnerField1 string `alloy:"inner_field_1,attr,optional"` + InnerField2 string `alloy:"inner_field_2,attr,optional"` } type OuterStruct struct { - OuterField1 string `river:"outer_field_1,attr,optional"` - Inner InnerStruct `river:",squash"` - OuterField2 string `river:"outer_field_2,attr,optional"` + OuterField1 string `alloy:"outer_field_1,attr,optional"` + Inner InnerStruct `alloy:",squash"` + OuterField2 string `alloy:"outer_field_2,attr,optional"` } var ( @@ -229,14 +229,14 @@ func TestVM_Block_Attributes(t *testing.T) { t.Run("Supports squashed attributes in pointers", func(t *testing.T) { type InnerStruct struct { - InnerField1 string `river:"inner_field_1,attr,optional"` - InnerField2 string `river:"inner_field_2,attr,optional"` + InnerField1 string `alloy:"inner_field_1,attr,optional"` + InnerField2 string `alloy:"inner_field_2,attr,optional"` } type OuterStruct struct { - OuterField1 string `river:"outer_field_1,attr,optional"` - Inner *InnerStruct `river:",squash"` - OuterField2 string `river:"outer_field_2,attr,optional"` + OuterField1 string `alloy:"outer_field_1,attr,optional"` + Inner *InnerStruct `alloy:",squash"` + OuterField2 string `alloy:"outer_field_2,attr,optional"` } var ( @@ -266,13 +266,13 @@ func TestVM_Block_Attributes(t *testing.T) { func TestVM_Block_Children_Blocks(t *testing.T) { type childBlock struct { - Attr bool `river:"attr,attr"` + Attr bool `alloy:"attr,attr"` } t.Run("Decodes children blocks", func(t *testing.T) { type block struct { - Value int `river:"value,attr"` - Child childBlock `river:"child.block,block"` + Value int `alloy:"value,attr"` + Child childBlock `alloy:"child.block,block"` } input := `some_block { @@ -290,8 +290,8 @@ func TestVM_Block_Children_Blocks(t *testing.T) { t.Run("Decodes multiple instances of children blocks", func(t *testing.T) { type block struct { - Value int `river:"value,attr"` - Children []childBlock `river:"child.block,block"` + Value int `alloy:"value,attr"` + Children []childBlock `alloy:"child.block,block"` } input := `some_block { @@ -314,8 +314,8 @@ func TestVM_Block_Children_Blocks(t *testing.T) { t.Run("Decodes multiple instances of children blocks into an array", func(t *testing.T) { type block struct { - Value int `river:"value,attr"` - Children [3]childBlock `river:"child.block,block"` + Value int `alloy:"value,attr"` + Children [3]childBlock `alloy:"child.block,block"` } input := `some_block { @@ -337,7 +337,7 @@ func TestVM_Block_Children_Blocks(t *testing.T) { t.Run("Fails if block used as an attribute", func(t *testing.T) { type block struct { - Child childBlock `river:"child,block"` + Child childBlock `alloy:"child,block"` } input := `some_block { @@ -351,8 +351,8 @@ func TestVM_Block_Children_Blocks(t *testing.T) { t.Run("Fails if required children blocks are not present", func(t *testing.T) { type block struct { - Value int `river:"value,attr"` - Child childBlock `river:"child.block,block"` + Value int `alloy:"value,attr"` + Child childBlock `alloy:"child.block,block"` } input := `some_block { @@ -366,8 +366,8 @@ func TestVM_Block_Children_Blocks(t *testing.T) { t.Run("Succeeds if optional children blocks are not present", func(t *testing.T) { type block struct { - Value int `river:"value,attr"` - Child childBlock `river:"child.block,block,optional"` + Value int `alloy:"value,attr"` + Child childBlock `alloy:"child.block,block,optional"` } input := `some_block { @@ -382,7 +382,7 @@ func TestVM_Block_Children_Blocks(t *testing.T) { t.Run("Fails if child block is not defined in struct", func(t *testing.T) { type block struct { - Value int `river:"value,attr"` + Value int `alloy:"value,attr"` } input := `some_block { @@ -398,10 +398,10 @@ func TestVM_Block_Children_Blocks(t *testing.T) { t.Run("Supports arbitrarily nested struct pointer fields", func(t *testing.T) { type block struct { - BlockA childBlock `river:"block_a,block"` - BlockB *childBlock `river:"block_b,block"` - BlockC **childBlock `river:"block_c,block"` - BlockD ***childBlock `river:"block_d,block"` + BlockA childBlock `alloy:"block_a,block"` + BlockB *childBlock `alloy:"block_b,block"` + BlockC **childBlock `alloy:"block_c,block"` + BlockD ***childBlock `alloy:"block_d,block"` } input := `some_block { @@ -422,14 +422,14 @@ func TestVM_Block_Children_Blocks(t *testing.T) { t.Run("Supports squashed blocks", func(t *testing.T) { type InnerStruct struct { - Inner1 childBlock `river:"inner_block_1,block"` - Inner2 childBlock `river:"inner_block_2,block"` + Inner1 childBlock `alloy:"inner_block_1,block"` + Inner2 childBlock `alloy:"inner_block_2,block"` } type OuterStruct struct { - Outer1 childBlock `river:"outer_block_1,block"` - Inner InnerStruct `river:",squash"` - Outer2 childBlock `river:"outer_block_2,block"` + Outer1 childBlock `alloy:"outer_block_1,block"` + Inner InnerStruct `alloy:",squash"` + Outer2 childBlock `alloy:"outer_block_2,block"` } var ( @@ -458,14 +458,14 @@ func TestVM_Block_Children_Blocks(t *testing.T) { t.Run("Supports squashed blocks in pointers", func(t *testing.T) { type InnerStruct struct { - Inner1 *childBlock `river:"inner_block_1,block"` - Inner2 *childBlock `river:"inner_block_2,block"` + Inner1 *childBlock `alloy:"inner_block_1,block"` + Inner2 *childBlock `alloy:"inner_block_2,block"` } type OuterStruct struct { - Outer1 childBlock `river:"outer_block_1,block"` - Inner *InnerStruct `river:",squash"` - Outer2 childBlock `river:"outer_block_2,block"` + Outer1 childBlock `alloy:"outer_block_1,block"` + Inner *InnerStruct `alloy:",squash"` + Outer2 childBlock `alloy:"outer_block_2,block"` } var ( @@ -497,20 +497,20 @@ func TestVM_Block_Children_Blocks(t *testing.T) { func TestVM_Block_Enum_Block(t *testing.T) { type childBlock struct { - Attr int `river:"attr,attr"` + Attr int `alloy:"attr,attr"` } type enumBlock struct { - BlockA *childBlock `river:"a,block,optional"` - BlockB *childBlock `river:"b,block,optional"` - BlockC *childBlock `river:"c,block,optional"` - BlockD *childBlock `river:"d,block,optional"` + BlockA *childBlock `alloy:"a,block,optional"` + BlockB *childBlock `alloy:"b,block,optional"` + BlockC *childBlock `alloy:"c,block,optional"` + BlockD *childBlock `alloy:"d,block,optional"` } t.Run("Decodes enum blocks", func(t *testing.T) { type block struct { - Value int `river:"value,attr"` - Blocks []*enumBlock `river:"child,enum,optional"` + Value int `alloy:"value,attr"` + Blocks []*enumBlock `alloy:"child,enum,optional"` } input := `some_block { @@ -534,8 +534,8 @@ func TestVM_Block_Enum_Block(t *testing.T) { t.Run("Decodes multiple enum blocks", func(t *testing.T) { type block struct { - Value int `river:"value,attr"` - Blocks []*enumBlock `river:"child,enum,optional"` + Value int `alloy:"value,attr"` + Blocks []*enumBlock `alloy:"child,enum,optional"` } input := `some_block { @@ -563,8 +563,8 @@ func TestVM_Block_Enum_Block(t *testing.T) { t.Run("Decodes multiple enum blocks with repeating blocks", func(t *testing.T) { type block struct { - Value int `river:"value,attr"` - Blocks []*enumBlock `river:"child,enum,optional"` + Value int `alloy:"value,attr"` + Blocks []*enumBlock `alloy:"child,enum,optional"` } input := `some_block { @@ -596,7 +596,7 @@ func TestVM_Block_Enum_Block(t *testing.T) { func TestVM_Block_Label(t *testing.T) { t.Run("Decodes label into string field", func(t *testing.T) { type block struct { - Label string `river:",label"` + Label string `alloy:",label"` } input := `some_block "label_value_1" {}` @@ -619,7 +619,7 @@ func TestVM_Block_Label(t *testing.T) { t.Run("Block must have label if struct accepts label", func(t *testing.T) { type block struct { - Label string `river:",label"` + Label string `alloy:",label"` } input := `some_block {}` @@ -631,7 +631,7 @@ func TestVM_Block_Label(t *testing.T) { t.Run("Block must have non-empty label if struct accepts label", func(t *testing.T) { type block struct { - Label string `river:",label"` + Label string `alloy:",label"` } input := `some_block "" {}` @@ -644,8 +644,8 @@ func TestVM_Block_Label(t *testing.T) { func TestVM_Block_Unmarshaler(t *testing.T) { type OuterBlock struct { - FieldA string `river:"field_a,attr"` - Settings Setting `river:"some.settings,block"` + FieldA string `alloy:"field_a,attr"` + Settings Setting `alloy:"some.settings,block"` } input := ` @@ -670,7 +670,7 @@ func TestVM_Block_Unmarshaler(t *testing.T) { func TestVM_Block_UnmarshalToMap(t *testing.T) { type OuterBlock struct { - Settings map[string]interface{} `river:"some.settings,block"` + Settings map[string]interface{} `alloy:"some.settings,block"` } tt := []struct { @@ -739,7 +739,7 @@ func TestVM_Block_UnmarshalToMap(t *testing.T) { func TestVM_Block_UnmarshalToAny(t *testing.T) { type OuterBlock struct { - Settings any `river:"some.settings,block"` + Settings any `alloy:"some.settings,block"` } input := ` @@ -765,8 +765,8 @@ func TestVM_Block_UnmarshalToAny(t *testing.T) { } type Setting struct { - FieldA string `river:"field_a,attr"` - FieldB string `river:"field_b,attr"` + FieldA string `alloy:"field_a,attr"` + FieldB string `alloy:"field_b,attr"` UnmarshalCalled bool DefaultCalled bool diff --git a/syntax/vm/vm_errors_test.go b/syntax/vm/vm_errors_test.go index bec22de001..219d6d47c7 100644 --- a/syntax/vm/vm_errors_test.go +++ b/syntax/vm/vm_errors_test.go @@ -12,9 +12,9 @@ func TestVM_ExprErrors(t *testing.T) { type Target struct { Key struct { Object struct { - Field1 []int `river:"field1,attr"` - } `river:"object,attr"` - } `river:"key,attr"` + Field1 []int `alloy:"field1,attr"` + } `alloy:"object,attr"` + } `alloy:"key,attr"` } tt := []struct { @@ -61,7 +61,7 @@ func TestVM_ExprErrors(t *testing.T) { name: "complex expr", input: `key = [0, 1, 2]`, into: &struct { - Key string `river:"key,attr"` + Key string `alloy:"key,attr"` }{}, expect: `test:1:7: [0, 1, 2] should be string, got array`, }, diff --git a/syntax/vm/vm_stdlib_test.go b/syntax/vm/vm_stdlib_test.go index 591a7bdd27..0c91fb88a5 100644 --- a/syntax/vm/vm_stdlib_test.go +++ b/syntax/vm/vm_stdlib_test.go @@ -188,11 +188,11 @@ func BenchmarkConcat(b *testing.B) { // If the code path is fully optimized, there will be no intermediate // translations to interface{}. type Person struct { - Name string `river:"name,attr"` - Attrs map[string]string `river:"attrs,attr"` + Name string `alloy:"name,attr"` + Attrs map[string]string `alloy:"attrs,attr"` } type Body struct { - Values []Person `river:"values,attr"` + Values []Person `alloy:"values,attr"` } in := `values = concat(values_ref)` diff --git a/syntax/vm/vm_test.go b/syntax/vm/vm_test.go index f073b94d4b..877ac879b3 100644 --- a/syntax/vm/vm_test.go +++ b/syntax/vm/vm_test.go @@ -110,9 +110,9 @@ func TestVM_Evaluate(t *testing.T) { age = 42, }`, expect: struct { - Name string `river:"name,attr"` - Age int `river:"age,attr"` - Country string `river:"country,attr,optional"` + Name string `alloy:"name,attr"` + Age int `alloy:"age,attr"` + Country string `alloy:"country,attr,optional"` }{ Name: "John Doe", Age: 42, @@ -207,7 +207,7 @@ func TestVM_Evaluate_IdentifierExpr(t *testing.T) { func TestVM_Evaluate_AccessExpr(t *testing.T) { t.Run("Lookup optional field", func(t *testing.T) { type Person struct { - Name string `river:"name,attr,optional"` + Name string `alloy:"name,attr,optional"` } scope := &vm.Scope{