Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
lmbsog0 committed Sep 17, 2023
2 parents 1674839 + 3f8f945 commit e737c1c
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 1 deletion.
112 changes: 112 additions & 0 deletions cmd/a2l/a2l_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,115 @@ func Test_GetJSONFromTree(t *testing.T) {
})
}
}

func TestGrpcA2LImplType_GetA2LFromTree(t *testing.T) {
type testCaseType struct {
request *a2l.A2LFromTreeRequest
response *a2l.A2LResponse
}

for _, tc := range []testCaseType{
{
request: &a2l.A2LFromTreeRequest{
Tree: &a2l.RootNodeType{
PROJECT: &a2l.ProjectType{
Name: &a2l.IdentType{Value: "_"},
LongIdentifier: &a2l.StringType{Value: "_"},
MODULE: []*a2l.ModuleType{
{
Name: &a2l.IdentType{Value: "_"},
LongIdentifier: &a2l.StringType{Value: "_"},
CHARACTERISTIC: []*a2l.CharacteristicType{
{
Name: &a2l.IdentType{Value: "c[1]"},
LongIdentifier: &a2l.StringType{Value: "_"},
Type: "VALUE",
Address: &a2l.LongType{Value: 0x00000000},
Deposit: &a2l.IdentType{Value: "_"},
MaxDiff: &a2l.FloatType{Value: 0.0},
Conversion: &a2l.IdentType{Value: "_"},
LowerLimit: &a2l.FloatType{Value: 0.0},
UpperLimit: &a2l.FloatType{Value: 0.0},
},
{
Name: &a2l.IdentType{Value: "b[1]"},
LongIdentifier: &a2l.StringType{Value: "_"},
Type: "VALUE",
Address: &a2l.LongType{Value: 0x00000000},
Deposit: &a2l.IdentType{Value: "_"},
MaxDiff: &a2l.FloatType{Value: 0.0},
Conversion: &a2l.IdentType{Value: "_"},
LowerLimit: &a2l.FloatType{Value: 0.0},
UpperLimit: &a2l.FloatType{Value: 0.0},
},
{
Name: &a2l.IdentType{Value: "a[0]"},
LongIdentifier: &a2l.StringType{Value: "_"},
Type: "VALUE",
Address: &a2l.LongType{Value: 0x00000000},
Deposit: &a2l.IdentType{Value: "_"},
MaxDiff: &a2l.FloatType{Value: 0.0},
Conversion: &a2l.IdentType{Value: "_"},
LowerLimit: &a2l.FloatType{Value: 0.0},
UpperLimit: &a2l.FloatType{Value: 0.0},
},
{
Name: &a2l.IdentType{Value: "c[0]"},
LongIdentifier: &a2l.StringType{Value: "_"},
Type: "VALUE",
Address: &a2l.LongType{Value: 0x00000000},
Deposit: &a2l.IdentType{Value: "_"},
MaxDiff: &a2l.FloatType{Value: 0.0},
Conversion: &a2l.IdentType{Value: "_"},
LowerLimit: &a2l.FloatType{Value: 0.0},
UpperLimit: &a2l.FloatType{Value: 0.0},
},
{
Name: &a2l.IdentType{Value: "b[10]"},
LongIdentifier: &a2l.StringType{Value: "_"},
Type: "VALUE",
Address: &a2l.LongType{Value: 0x00000000},
Deposit: &a2l.IdentType{Value: "_"},
MaxDiff: &a2l.FloatType{Value: 0.0},
Conversion: &a2l.IdentType{Value: "_"},
LowerLimit: &a2l.FloatType{Value: 0.0},
UpperLimit: &a2l.FloatType{Value: 0.0},
},
},
},
},
},
},
Indent: baseTypeToPointer[uint32](1),
Sorted: baseTypeToPointer[bool](true),
},
response: &a2l.A2LResponse{
A2L: []byte(`/begin PROJECT _ "_"
/begin MODULE _ "_"
/begin CHARACTERISTIC a[0] "_" VALUE 0x0 _ 0 _ 0 0
/end CHARACTERISTIC
/begin CHARACTERISTIC b[1] "_" VALUE 0x0 _ 0 _ 0 0
/end CHARACTERISTIC
/begin CHARACTERISTIC b[10] "_" VALUE 0x0 _ 0 _ 0 0
/end CHARACTERISTIC
/begin CHARACTERISTIC c[0] "_" VALUE 0x0 _ 0 _ 0 0
/end CHARACTERISTIC
/begin CHARACTERISTIC c[1] "_" VALUE 0x0 _ 0 _ 0 0
/end CHARACTERISTIC
/end MODULE
/end PROJECT`),
Error: nil,
},
},
} {
t.Run("", func(t *testing.T) {
grpc := grpcA2LImplType{}

if response, err := grpc.GetA2LFromTree(nil, tc.request); err == nil {
assert.Equal(t, tc.response, response)
} else {
t.Fatal(err)
}
})
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/sauci/a2l-grpc
go 1.20

require (
facette.io/natsort v0.0.0-20181210072756-2cd4dd1e2dcb
github.com/antlr4-go/antlr/v4 v4.13.0
github.com/stretchr/testify v1.8.4
google.golang.org/grpc v1.55.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
facette.io/natsort v0.0.0-20181210072756-2cd4dd1e2dcb h1:1pSweJFeR3Pqx7uoelppkzeegfUBXL6I2FFAbfXw570=
facette.io/natsort v0.0.0-20181210072756-2cd4dd1e2dcb/go.mod h1:npRYmtaITVom7rcSo+pRURltHSG2r4TQM1cdqJ2dUB0=
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
5 changes: 4 additions & 1 deletion pkg/a2l/a2lextension.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package a2l

import (
"facette.io/natsort"
"fmt"
sort2 "sort"
"strings"
Expand All @@ -19,7 +20,9 @@ import (
//}

func sortSortableList[T SortableNode](list []T) {
sort2.Slice(list, func(i, j int) bool { return list[i].UniqueKey() < list[j].UniqueKey() })
sort2.Slice(list, func(i, j int) bool {
return natsort.Compare(list[i].UniqueKey(), list[j].UniqueKey())
})
}

func (t *A2MLVersionType) MapChildNodes(_ any) {
Expand Down

0 comments on commit e737c1c

Please sign in to comment.