github.com/blueinnovationsgroup/can-go@v0.0.0-20230518195432-d0567cda0028/pkg/dbc/analysis/passes/nodereferences/analyzer_test.go (about)

     1  package nodereferences
     2  
     3  import (
     4  	"testing"
     5  	"text/scanner"
     6  
     7  	"github.com/blueinnovationsgroup/can-go/pkg/dbc/analysis"
     8  	"github.com/blueinnovationsgroup/can-go/pkg/dbc/analysis/analysistest"
     9  )
    10  
    11  func TestAnalyzer(t *testing.T) {
    12  	analysistest.Run(t, Analyzer(), []*analysistest.Case{
    13  		{
    14  			Name: "valid",
    15  			Data: `
    16  BU_: ECU1 ECU2
    17  BO_ 42 TestMessage: 8 ECU2
    18   SG_ CellTempLowest : 32|8@0+ (1,-40) [-40|215] "C" ECU1
    19  			`,
    20  		},
    21  
    22  		{
    23  			Name: "undeclared transmitter",
    24  			Data: `
    25  BU_: ECU1 ECU2
    26  BO_ 42 TestMessage: 8 ECU3
    27   SG_ CellTempLowest : 32|8@0+ (1,-40) [-40|215] "C" ECU1
    28  			`,
    29  			Diagnostics: []*analysis.Diagnostic{
    30  				{
    31  					Pos:     scanner.Position{Line: 2, Column: 1},
    32  					Message: "undeclared transmitter node: ECU3",
    33  				},
    34  			},
    35  		},
    36  
    37  		{
    38  			Name: "undeclared receiver",
    39  			Data: `
    40  BU_: ECU1 ECU2
    41  BO_ 42 TestMessage: 8 ECU2
    42   SG_ CellTempLowest : 32|8@0+ (1,-40) [-40|215] "C" ECU2,ECU3
    43  			`,
    44  			Diagnostics: []*analysis.Diagnostic{
    45  				{
    46  					Pos:     scanner.Position{Line: 3, Column: 2},
    47  					Message: "undeclared receiver node: ECU3",
    48  				},
    49  			},
    50  		},
    51  	})
    52  }