github.com/cockroachdb/pebble@v1.1.1-0.20240513155919-3622ade60459/internal/humanize/humanize_test.go (about)

     1  // Copyright 2023 The LevelDB-Go and Pebble Authors. All rights reserved. Use
     2  // of this source code is governed by a BSD-style license that can be found in
     3  // the LICENSE file.
     4  
     5  package humanize
     6  
     7  import (
     8  	"bytes"
     9  	"fmt"
    10  	"strconv"
    11  	"strings"
    12  	"testing"
    13  
    14  	"github.com/cockroachdb/datadriven"
    15  )
    16  
    17  func TestHumanize(t *testing.T) {
    18  	datadriven.RunTest(t, "testdata/humanize", func(t *testing.T, td *datadriven.TestData) string {
    19  		var c config
    20  		switch td.Cmd {
    21  		case "bytes":
    22  			c = Bytes
    23  		case "count":
    24  			c = Count
    25  		default:
    26  			td.Fatalf(t, "invalid command %q", td.Cmd)
    27  		}
    28  		var buf bytes.Buffer
    29  		for _, row := range strings.Split(td.Input, "\n") {
    30  			val, err := strconv.ParseInt(row, 10, 64)
    31  			if err != nil {
    32  				td.Fatalf(t, "error parsing %q: %v", row, err)
    33  			}
    34  			fmt.Fprintf(&buf, "%s\n", c.Int64(val))
    35  		}
    36  		return buf.String()
    37  	})
    38  }