github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/libkbfs/flag_size_test.go (about)

     1  // Copyright 2016 Keybase Inc. All rights reserved.
     2  // Use of this source code is governed by a BSD
     3  // license that can be found in the LICENSE file.
     4  
     5  package libkbfs
     6  
     7  import "testing"
     8  
     9  func TestSizeFlag(t *testing.T) {
    10  	for _, v := range []int64{0, 1, 13, 100, 1000, 1024, 1333, 2000, 74000, 74001, 1000 * 1000, 1024 * 1000, 1025 * 1001, 1024 * 1024,
    11  		1000 * 1000 * 1000, 1024 * 1024 * 1024, 7 * 1000 * 1000 * 1000, 13 * 1024 * 1024 * 1024,
    12  		1000 * 1000 * 1000 * 1000, 1024 * 1024 * 1024 * 1024, 99999 * 1000 * 1000 * 1000 * 1000, 99999 * 1024 * 1024 * 1024 * 1024,
    13  	} {
    14  		var x int64
    15  		err := SizeFlag{&x}.Set(SizeFlag{&v}.String())
    16  		if v != x || err != nil {
    17  			t.Errorf("SizeFlag comparison error: v=%d x=%d err=%v", v, x, err)
    18  		}
    19  	}
    20  	mult := int64(1000)
    21  	for _, ch := range "kmgt" {
    22  		v := mult * 77
    23  		r := SizeFlag{&v}
    24  		if r.String() != "77"+string(ch) {
    25  			t.Errorf("SizeFlag to string error: got %v, expected %v", r.String(), "77"+string(ch))
    26  		}
    27  		mult *= 1000
    28  	}
    29  	mult = 1024
    30  	for _, ch := range "kmgt" {
    31  		v := mult * 77
    32  		r := SizeFlag{&v}
    33  		if r.String() != "77"+string(ch)+"i" {
    34  			t.Errorf("SizeFlag to string error: got %v, expected %v", r.String(), "77"+string(ch)+"i")
    35  		}
    36  		mult *= 1024
    37  	}
    38  }
    39  
    40  func TestSizeFlagZero(t *testing.T) {
    41  	var f SizeFlag
    42  	s := f.String()
    43  	if s != "0" {
    44  		t.Errorf("Expected 0, got %s", s)
    45  	}
    46  }