Skip to content

Commit

Permalink
add assert for AddDataValidation and DeleteDataValidation in test file
Browse files Browse the repository at this point in the history
  • Loading branch information
chenwang committed Mar 1, 2024
1 parent 2a54818 commit 277df9f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ func TestConcurrency(t *testing.T) {
dv.Sqref = fmt.Sprintf("A%d:B%d", val, val)
dv.SetRange(10, 20, DataValidationTypeWhole, DataValidationOperatorGreaterThan)
dv.SetInput(fmt.Sprintf("title:%d", val), strconv.Itoa(val))
f.AddDataValidation("Sheet1", dv)
assert.NoError(t, f.AddDataValidation("Sheet1", dv))
// Concurrency delete data validation with reference sequence
f.DeleteDataValidation("Sheet1", dv.Sqref)
assert.NoError(t, f.DeleteDataValidation("Sheet1", dv.Sqref))
wg.Done()
}(i, t)
}
Expand Down
49 changes: 22 additions & 27 deletions datavalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,31 +114,6 @@ func NewDataValidation(allowBlank bool) *DataValidation {
}
}

// newXlsxDataValidation is a internal function to create xlsxDataValidation by given data validation object.
func newXlsxDataValidation(dv *DataValidation) *xlsxDataValidation {
dataValidation := &xlsxDataValidation{
AllowBlank: dv.AllowBlank,
Error: dv.Error,
ErrorStyle: dv.ErrorStyle,
ErrorTitle: dv.ErrorTitle,
Operator: dv.Operator,
Prompt: dv.Prompt,
PromptTitle: dv.PromptTitle,
ShowDropDown: dv.ShowDropDown,
ShowErrorMessage: dv.ShowErrorMessage,
ShowInputMessage: dv.ShowInputMessage,
Sqref: dv.Sqref,
Type: dv.Type,
}
if dv.Formula1 != "" {
dataValidation.Formula1 = &xlsxInnerXML{Content: dv.Formula1}
}
if dv.Formula2 != "" {
dataValidation.Formula2 = &xlsxInnerXML{Content: dv.Formula2}
}
return dataValidation
}

// SetError set error notice.
func (dv *DataValidation) SetError(style DataValidationErrorStyle, title, msg string) {
dv.Error = &msg
Expand Down Expand Up @@ -287,7 +262,26 @@ func (f *File) AddDataValidation(sheet string, dv *DataValidation) error {
if nil == ws.DataValidations {
ws.DataValidations = new(xlsxDataValidations)
}
dataValidation := newXlsxDataValidation(dv)
dataValidation := &xlsxDataValidation{
AllowBlank: dv.AllowBlank,
Error: dv.Error,
ErrorStyle: dv.ErrorStyle,
ErrorTitle: dv.ErrorTitle,
Operator: dv.Operator,
Prompt: dv.Prompt,
PromptTitle: dv.PromptTitle,
ShowDropDown: dv.ShowDropDown,
ShowErrorMessage: dv.ShowErrorMessage,
ShowInputMessage: dv.ShowInputMessage,
Sqref: dv.Sqref,
Type: dv.Type,
}
if dv.Formula1 != "" {
dataValidation.Formula1 = &xlsxInnerXML{Content: dv.Formula1}
}
if dv.Formula2 != "" {
dataValidation.Formula2 = &xlsxInnerXML{Content: dv.Formula2}
}
ws.DataValidations.DataValidation = append(ws.DataValidations.DataValidation, dataValidation)
ws.DataValidations.Count = len(ws.DataValidations.DataValidation)
return err
Expand Down Expand Up @@ -332,7 +326,8 @@ func (f *File) GetDataValidations(sheet string) ([]*DataValidation, error) {
}

// DeleteDataValidation delete data validation by given worksheet name and
// reference sequence. This function is concurrency safe. All data validations in the worksheet will be deleted
// reference sequence. This function is concurrency safe.
// All data validations in the worksheet will be deleted
// if not specify reference sequence parameter.
func (f *File) DeleteDataValidation(sheet string, sqref ...string) error {
ws, err := f.workSheetReader(sheet)
Expand Down

0 comments on commit 277df9f

Please sign in to comment.