github.com/richardwilkes/toolbox@v1.121.0/formats/xlsx/ref_test.go (about) 1 // Copyright (c) 2016-2024 by Richard A. Wilkes. All rights reserved. 2 // 3 // This Source Code Form is subject to the terms of the Mozilla Public 4 // License, version 2.0. If a copy of the MPL was not distributed with 5 // this file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 // 7 // This Source Code Form is "Incompatible With Secondary Licenses", as 8 // defined by the Mozilla Public License, version 2.0. 9 10 package xlsx_test 11 12 import ( 13 "testing" 14 15 "github.com/richardwilkes/toolbox/check" 16 "github.com/richardwilkes/toolbox/formats/xlsx" 17 ) 18 19 func TestRef(t *testing.T) { 20 for i, d := range []struct { 21 Text string 22 Col int 23 Row int 24 }{ 25 {"A1", 0, 0}, 26 {"Z9", 25, 8}, 27 {"AA1", 26, 0}, 28 {"AA99", 26, 98}, 29 {"ZZ100", 701, 99}, 30 } { 31 ref := xlsx.ParseRef(d.Text) 32 check.Equal(t, d.Col, ref.Col, "column for index %d: %s", i, d.Text) 33 check.Equal(t, d.Row, ref.Row, "row for index %d: %s", i, d.Text) 34 check.Equal(t, d.Text, ref.String(), "String() for index %d: %s", i, d.Text) 35 } 36 37 for r := 0; r < 100; r++ { 38 for c := 0; c < 10000; c++ { 39 in := xlsx.Ref{Row: r, Col: c} 40 out := xlsx.ParseRef(in.String()) 41 check.Equal(t, in, out) 42 } 43 } 44 }