github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/testutils/sqlutils/table_gen_test.go (about) 1 // Copyright 2016 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package sqlutils 12 13 import ( 14 "bytes" 15 "testing" 16 17 "github.com/cockroachdb/cockroach/pkg/util/leaktest" 18 ) 19 20 func TestIntToEnglish(t *testing.T) { 21 defer leaktest.AfterTest(t)() 22 testCases := []struct { 23 val int 24 exp string 25 }{ 26 {0, "zero"}, 27 {1, "one"}, 28 {2, "two"}, 29 {3, "three"}, 30 {456, "four-five-six"}, 31 {70, "seven-zero"}, 32 {108, "one-zero-eight"}, 33 {9901, "nine-nine-zero-one"}, 34 } 35 for _, c := range testCases { 36 if res := IntToEnglish(c.val); res != c.exp { 37 t.Errorf("expected %s, got %s", c.exp, res) 38 } 39 } 40 } 41 42 func TestGenValues(t *testing.T) { 43 defer leaktest.AfterTest(t)() 44 var buf bytes.Buffer 45 genValues(&buf, 7, 11, ToRowFn(RowIdxFn, RowModuloFn(3), RowEnglishFn), false /* shouldPrint */) 46 expected := `(7:::INT8,1:::INT8,'seven':::STRING),(8:::INT8,2:::INT8,'eight':::STRING),(9:::INT8,0:::INT8,'nine':::STRING),(10:::INT8,1:::INT8,'one-zero':::STRING),(11:::INT8,2:::INT8,'one-one':::STRING)` 47 if buf.String() != expected { 48 t.Errorf("expected '%s', got '%s'", expected, buf.String()) 49 } 50 }