github.com/haraldrudell/parl@v0.4.176/pids/pid_test.go (about) 1 /* 2 © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 // Package pids provides a typed process identifier. 7 package pids 8 9 import ( 10 "strconv" 11 "testing" 12 13 "github.com/haraldrudell/parl/perrors" 14 ) 15 16 func TestPid(t *testing.T) { 17 var intPid = 5 18 var u32 = uint32(intPid) 19 var expS = strconv.Itoa(intPid) 20 var badInt = -1 21 22 var s string 23 var typedPid, zeroValue Pid 24 var isValid bool 25 var iAct int 26 var u32Act uint32 27 var err error 28 29 s = NewPid(u32).String() 30 if s != expS { 31 t.Errorf("String %q exp %q", s, expS) 32 } 33 34 isValid = zeroValue.IsNonZero() 35 if isValid { 36 t.Error("IsNonZero true") 37 } 38 39 iAct = NewPid(u32).Int() 40 if iAct != intPid { 41 t.Errorf("Int %d exp %d", iAct, intPid) 42 } 43 44 iAct = NewPid(u32).Int() 45 if iAct != intPid { 46 t.Errorf("Int %d exp %d", iAct, intPid) 47 } 48 49 u32Act = NewPid(u32).Uint32() 50 if u32Act != u32 { 51 t.Errorf("Uint32 %d exp %d", u32Act, u32) 52 } 53 54 typedPid, err = ConvertToPid(badInt) 55 if err == nil { 56 t.Error("ConvertToPid badInt missing err") 57 } 58 _ = typedPid 59 60 typedPid, err = ConvertToPid(intPid) 61 if err != nil { 62 t.Errorf("ConvertToPid err: %s", perrors.Short(err)) 63 } 64 65 if i := typedPid.Int(); i != intPid { 66 t.Errorf("ConvertToPid %d exp %d", i, intPid) 67 } 68 69 if i := NewPid1(intPid).Int(); i != intPid { 70 t.Errorf("NewPid1 %d exp %d", i, intPid) 71 } 72 }