Home | History | Annotate | Download | only in dwarf
      1 // Copyright 2017 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 package dwarf
      6 
      7 import (
      8 	"reflect"
      9 	"testing"
     10 )
     11 
     12 func TestSevenBitEnc128(t *testing.T) {
     13 	t.Run("unsigned", func(t *testing.T) {
     14 		for v := int64(-255); v < 255; v++ {
     15 			s := sevenBitU(v)
     16 			if s == nil {
     17 				continue
     18 			}
     19 			b := AppendUleb128(nil, uint64(v))
     20 			if !reflect.DeepEqual(b, s) {
     21 				t.Errorf("sevenBitU(%d) = %v but AppendUleb128(%d) = %v", v, s, v, b)
     22 			}
     23 		}
     24 	})
     25 
     26 	t.Run("signed", func(t *testing.T) {
     27 		for v := int64(-255); v < 255; v++ {
     28 			s := sevenBitS(v)
     29 			if s == nil {
     30 				continue
     31 			}
     32 			b := AppendSleb128(nil, v)
     33 			if !reflect.DeepEqual(b, s) {
     34 				t.Errorf("sevenBitS(%d) = %v but AppendSleb128(%d) = %v", v, s, v, b)
     35 			}
     36 		}
     37 	})
     38 }
     39