github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/ranges/range_test.go (about) 1 // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. 2 3 package rangeutils_test 4 5 import ( 6 rangeutils "github.com/TeaOSLab/EdgeNode/internal/utils/ranges" 7 "github.com/iwind/TeaGo/assert" 8 "testing" 9 ) 10 11 func TestRange(t *testing.T) { 12 var a = assert.NewAssertion(t) 13 14 var r = rangeutils.NewRange(1, 100) 15 a.IsTrue(r.Start() == 1) 16 a.IsTrue(r.End() == 100) 17 t.Log("start:", r.Start(), "end:", r.End()) 18 } 19 20 func TestRange_Convert(t *testing.T) { 21 var a = assert.NewAssertion(t) 22 23 { 24 var r = rangeutils.NewRange(1, 100) 25 newR, ok := r.Convert(200) 26 a.IsTrue(ok) 27 a.IsTrue(newR.Start() == 1) 28 a.IsTrue(newR.End() == 100) 29 } 30 31 { 32 var r = rangeutils.NewRange(1, 100) 33 newR, ok := r.Convert(50) 34 a.IsTrue(ok) 35 a.IsTrue(newR.Start() == 1) 36 a.IsTrue(newR.End() == 49) 37 } 38 39 { 40 var r = rangeutils.NewRange(1, 100) 41 _, ok := r.Convert(0) 42 a.IsFalse(ok) 43 } 44 45 { 46 var r = rangeutils.NewRange(-30, -1) 47 newR, ok := r.Convert(50) 48 a.IsTrue(ok) 49 a.IsTrue(newR.Start() == 50-30) 50 a.IsTrue(newR.End() == 49) 51 } 52 53 { 54 var r = rangeutils.NewRange(1000, 100) 55 _, ok := r.Convert(0) 56 a.IsFalse(ok) 57 } 58 59 { 60 var r = rangeutils.NewRange(50, 100) 61 _, ok := r.Convert(49) 62 a.IsFalse(ok) 63 } 64 } 65 66 func TestRange_ComposeContentRangeHeader(t *testing.T) { 67 var r = rangeutils.NewRange(1, 100) 68 t.Log(r.ComposeContentRangeHeader("1000")) 69 }