parent
e42d3b5722
commit
6521b707dd
@ -0,0 +1,59 @@ |
|||||||
|
package can |
||||||
|
|
||||||
|
import ( |
||||||
|
"reflect" |
||||||
|
"testing" |
||||||
|
"time" |
||||||
|
) |
||||||
|
|
||||||
|
const ( |
||||||
|
frame_hr = "(2022-07-08 16:54:15.587099) can0 100 [8] 00 00 00 00 00 00 64 00" |
||||||
|
frame_m = "(1670578900.771868) can0 00004021#00000000FCFFFFFF" |
||||||
|
) |
||||||
|
|
||||||
|
func Test_fromString(t *testing.T) { |
||||||
|
var time_m, err1 = time.ParseInLocation("2006-01-02T15:04:05.000000", "2022-12-09T09:41:40.771868", time.Local) |
||||||
|
var time_p, err2 = time.ParseInLocation("2006-01-02 15:04:05.000000", "2022-07-08 16:54:15.587099", time.Local) |
||||||
|
|
||||||
|
if err1 != nil || err2 != nil { |
||||||
|
t.Error() |
||||||
|
} |
||||||
|
|
||||||
|
//time_m = time_m.In(time.Local)
|
||||||
|
//time_p = time_p.In(time.Local)
|
||||||
|
|
||||||
|
type args struct { |
||||||
|
text string |
||||||
|
} |
||||||
|
tests := []struct { |
||||||
|
name string |
||||||
|
args args |
||||||
|
want *CanFrame |
||||||
|
}{ |
||||||
|
{ |
||||||
|
name: "Machine readable time", |
||||||
|
args: args{text: frame_m}, |
||||||
|
want: &CanFrame{ |
||||||
|
Date: &time_m, |
||||||
|
CanId: 0x4021, |
||||||
|
Payload: []uint8{00, 00, 00, 00, 0xFC, 0xFF, 0xFF, 0xFF}, |
||||||
|
}, |
||||||
|
}, |
||||||
|
{ |
||||||
|
name: "Human readable time", |
||||||
|
args: args{text: frame_hr}, |
||||||
|
want: &CanFrame{ |
||||||
|
Date: &time_p, |
||||||
|
CanId: 0x100, |
||||||
|
Payload: []uint8{00, 00, 00, 00, 00, 00, 0x64, 00}, |
||||||
|
}, |
||||||
|
}, |
||||||
|
} |
||||||
|
for _, tt := range tests { |
||||||
|
t.Run(tt.name, func(t *testing.T) { |
||||||
|
if got := fromString(tt.args.text); !reflect.DeepEqual(got, tt.want) { |
||||||
|
t.Errorf("fromString() = %v, want %v", got, tt.want) |
||||||
|
} |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue