MCPcopy
hub / github.com/qax-os/excelize / TestSetCellFloat

Function TestSetCellFloat

cell_test.go:160–193  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

158}
159
160func TestSetCellFloat(t *testing.T) {
161 sheet := "Sheet1"
162 t.Run("with no decimal", func(t *testing.T) {
163 f := NewFile()
164 assert.NoError(t, f.SetCellFloat(sheet, "A1", 123.0, -1, 64))
165 assert.NoError(t, f.SetCellFloat(sheet, "A2", 123.0, 1, 64))
166 val, err := f.GetCellValue(sheet, "A1")
167 assert.NoError(t, err)
168 assert.Equal(t, "123", val, "A1 should be 123")
169 val, err = f.GetCellValue(sheet, "A2")
170 assert.NoError(t, err)
171 assert.Equal(t, "123", val, "A2 should be 123")
172 })
173
174 t.Run("with a decimal and precision limit", func(t *testing.T) {
175 f := NewFile()
176 assert.NoError(t, f.SetCellFloat(sheet, "A1", 123.42, 1, 64))
177 val, err := f.GetCellValue(sheet, "A1")
178 assert.NoError(t, err)
179 assert.Equal(t, "123.4", val, "A1 should be 123.4")
180 })
181
182 t.Run("with a decimal and no limit", func(t *testing.T) {
183 f := NewFile()
184 assert.NoError(t, f.SetCellFloat(sheet, "A1", 123.42, -1, 64))
185 val, err := f.GetCellValue(sheet, "A1")
186 assert.NoError(t, err)
187 assert.Equal(t, "123.42", val, "A1 should be 123.42")
188 })
189 f := NewFile()
190 assert.Equal(t, newCellNameToCoordinatesError("A", newInvalidCellNameError("A")), f.SetCellFloat(sheet, "A", 123.42, -1, 64))
191 // Test set cell float data type value with invalid sheet name
192 assert.Equal(t, ErrSheetNameInvalid, f.SetCellFloat("Sheet:1", "A1", 123.42, -1, 64))
193}
194
195func TestSetCellUint(t *testing.T) {
196 f := NewFile()

Callers

nothing calls this directly

Calls 5

SetCellFloatMethod · 0.95
GetCellValueMethod · 0.95
NewFileFunction · 0.85
newInvalidCellNameErrorFunction · 0.85

Tested by

no test coverage detected