github.com/ethereum/go-ethereum@v1.16.1/cmd/geth/chaincmd_test.go (about) 1 // Copyright 2025 The go-ethereum Authors 2 // This file is part of go-ethereum. 3 // 4 // go-ethereum is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // go-ethereum is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 import "testing" 20 21 func TestParseRange(t *testing.T) { 22 var cases = []struct { 23 input string 24 valid bool 25 expStart uint64 26 expEnd uint64 27 }{ 28 { 29 input: "0", 30 valid: true, 31 expStart: 0, 32 expEnd: 0, 33 }, 34 { 35 input: "500", 36 valid: true, 37 expStart: 500, 38 expEnd: 500, 39 }, 40 { 41 input: "-1", 42 valid: false, 43 expStart: 0, 44 expEnd: 0, 45 }, 46 { 47 input: "1-1", 48 valid: true, 49 expStart: 1, 50 expEnd: 1, 51 }, 52 { 53 input: "0-1", 54 valid: true, 55 expStart: 0, 56 expEnd: 1, 57 }, 58 { 59 input: "1-0", 60 valid: false, 61 expStart: 0, 62 expEnd: 0, 63 }, 64 { 65 input: "1-1000", 66 valid: true, 67 expStart: 1, 68 expEnd: 1000, 69 }, 70 { 71 input: "1-1-", 72 valid: false, 73 expStart: 0, 74 expEnd: 0, 75 }, 76 { 77 input: "-1-1", 78 valid: false, 79 expStart: 0, 80 expEnd: 0, 81 }, 82 } 83 for _, c := range cases { 84 start, end, valid := parseRange(c.input) 85 if valid != c.valid { 86 t.Errorf("Unexpected result, want: %t, got: %t", c.valid, valid) 87 continue 88 } 89 if valid { 90 if c.expStart != start { 91 t.Errorf("Unexpected start, want: %d, got: %d", c.expStart, start) 92 } 93 if c.expEnd != end { 94 t.Errorf("Unexpected end, want: %d, got: %d", c.expEnd, end) 95 } 96 } 97 } 98 }