@@ -15,15 +15,15 @@ func TestMagValueMoney(t *testing.T) {
1515 value string
1616 want string
1717 }{
18- {"thousands" , "$5,234.23" , "$\U0001F821 3 " },
19- {"hundreds" , "$500.00" , "$\U0001F821 2 " },
20- {"millions" , "$1,000,000.00" , "$\U0001F821 6 " },
21- {"tens" , "$42.00" , "$\U0001F821 1 " },
22- {"single digit" , "$7.50" , "$\U0001F821 0 " },
23- {"sub-dollar" , "$0.50" , "$\U0001F821 -1" },
24- {"zero" , "$0.00" , "$\U0001F821 0 " },
25- {"negative" , "-$5.00" , "-$\U0001F821 0 " },
26- {"negative large" , "-$12,345.00" , "-$\U0001F821 4 " },
18+ {"thousands" , "$5,234.23" , "$ \U0001F821 3 " },
19+ {"hundreds" , "$500.00" , "$ \U0001F821 2 " },
20+ {"millions" , "$1,000,000.00" , "$ \U0001F821 6 " },
21+ {"tens" , "$42.00" , "$ \U0001F821 1 " },
22+ {"single digit" , "$7.50" , "$ \U0001F821 0 " },
23+ {"sub-dollar" , "$0.50" , "$ \U0001F821 -1" },
24+ {"zero" , "$0.00" , "$ \U0001F821 0 " },
25+ {"negative" , "-$5.00" , "-$ \U0001F821 0 " },
26+ {"negative large" , "-$12,345.00" , "-$ \U0001F821 4 " },
2727 }
2828 for _ , tt := range tests {
2929 t .Run (tt .name , func (t * testing.T ) {
@@ -33,25 +33,30 @@ func TestMagValueMoney(t *testing.T) {
3333 }
3434}
3535
36- func TestMagValuePlainNumbers (t * testing.T ) {
36+ func TestMagValueDrilldown (t * testing.T ) {
3737 tests := []struct {
3838 name string
3939 value string
4040 want string
4141 }{
42- {"integer" , "42" , "\U0001F821 1" },
43- {"zero" , "0" , "\U0001F821 0" },
44- {"large" , "1000000" , "\U0001F821 6" },
45- {"decimal" , "3.14" , "\U0001F821 0" },
42+ {"count" , "42" , "\U0001F821 1" },
43+ {"zero" , "0" , "\U0001F821 0" },
44+ {"large" , "1000" , "\U0001F821 3" },
4645 }
4746 for _ , tt := range tests {
4847 t .Run (tt .name , func (t * testing.T ) {
49- c := cell {Value : tt .value , Kind : cellReadonly }
48+ c := cell {Value : tt .value , Kind : cellDrilldown }
5049 assert .Equal (t , tt .want , magValue (c ))
5150 })
5251 }
5352}
5453
54+ func TestMagValueSkipsReadonly (t * testing.T ) {
55+ // IDs and other readonly cells should not be transformed.
56+ c := cell {Value : "42" , Kind : cellReadonly }
57+ assert .Equal (t , "42" , magValue (c ))
58+ }
59+
5560func TestMagValueSkipsNonNumeric (t * testing.T ) {
5661 tests := []struct {
5762 name string
@@ -66,44 +71,51 @@ func TestMagValueSkipsNonNumeric(t *testing.T) {
6671 {"notes" , "Some long note" , cellNotes },
6772 {"empty" , "" , cellText },
6873 {"dash" , "\u2014 " , cellMoney },
74+ {"readonly id" , "7" , cellReadonly },
6975 }
7076 for _ , tt := range tests {
7177 t .Run (tt .name , func (t * testing.T ) {
7278 c := cell {Value : tt .value , Kind : tt .kind }
73- assert .Equal (t , tt .value , magValue (c ), "non-numeric value should be unchanged" )
79+ assert .Equal (t , tt .value , magValue (c ), "value should be unchanged" )
7480 })
7581 }
7682}
7783
7884func TestMagTransformCells (t * testing.T ) {
7985 rows := [][]cell {
8086 {
87+ {Value : "1" , Kind : cellReadonly },
8188 {Value : "Kitchen Remodel" , Kind : cellText },
8289 {Value : "$5,234.23" , Kind : cellMoney },
8390 {Value : "3" , Kind : cellDrilldown },
8491 },
8592 {
93+ {Value : "2" , Kind : cellReadonly },
8694 {Value : "Deck" , Kind : cellText },
8795 {Value : "$100.00" , Kind : cellMoney },
8896 {Value : "0" , Kind : cellDrilldown },
8997 },
9098 }
9199 out := magTransformCells (rows )
92100
101+ // ID cells unchanged.
102+ assert .Equal (t , "1" , out [0 ][0 ].Value )
103+ assert .Equal (t , "2" , out [1 ][0 ].Value )
104+
93105 // Text cells unchanged.
94- assert .Equal (t , "Kitchen Remodel" , out [0 ][0 ].Value )
95- assert .Equal (t , "Deck" , out [1 ][0 ].Value )
106+ assert .Equal (t , "Kitchen Remodel" , out [0 ][1 ].Value )
107+ assert .Equal (t , "Deck" , out [1 ][1 ].Value )
96108
97109 // Money cells transformed.
98- assert .Equal (t , "$\U0001F821 3 " , out [0 ][1 ].Value )
99- assert .Equal (t , "$\U0001F821 2 " , out [1 ][1 ].Value )
110+ assert .Equal (t , "$ \U0001F821 3 " , out [0 ][2 ].Value )
111+ assert .Equal (t , "$ \U0001F821 2 " , out [1 ][2 ].Value )
100112
101113 // Drilldown counts transformed.
102- assert .Equal (t , "\U0001F821 0 " , out [0 ][2 ].Value )
103- assert .Equal (t , "\U0001F821 0 " , out [1 ][2 ].Value )
114+ assert .Equal (t , "\U0001F821 0 " , out [0 ][3 ].Value )
115+ assert .Equal (t , "\U0001F821 0 " , out [1 ][3 ].Value )
104116
105117 // Original rows are not modified.
106- assert .Equal (t , "$5,234.23" , rows [0 ][1 ].Value )
118+ assert .Equal (t , "$5,234.23" , rows [0 ][2 ].Value )
107119}
108120
109121func TestMagModeToggle (t * testing.T ) {
@@ -124,9 +136,9 @@ func TestMagModeWorksInEditMode(t *testing.T) {
124136}
125137
126138func TestMagCents (t * testing.T ) {
127- assert .Equal (t , "$\U0001F821 3 " , magCents (523423 ))
128- assert .Equal (t , "$\U0001F821 2 " , magCents (50000 ))
129- assert .Equal (t , "$\U0001F821 0 " , magCents (100 ))
139+ assert .Equal (t , "$ \U0001F821 3 " , magCents (523423 ))
140+ assert .Equal (t , "$ \U0001F821 2 " , magCents (50000 ))
141+ assert .Equal (t , "$ \U0001F821 0 " , magCents (100 ))
130142}
131143
132144func TestMagOptionalCentsNil (t * testing.T ) {
@@ -135,5 +147,5 @@ func TestMagOptionalCentsNil(t *testing.T) {
135147
136148func TestMagOptionalCentsPresent (t * testing.T ) {
137149 cents := int64 (100000 )
138- assert .Equal (t , "$\U0001F821 3 " , magOptionalCents (& cents ))
150+ assert .Equal (t , "$ \U0001F821 3 " , magOptionalCents (& cents ))
139151}
0 commit comments