Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ADIFRecord.DeleteField() #14

Merged
merged 1 commit into from
Oct 15, 2022
Merged

Conversation

jj1bdx
Copy link
Contributor

@jj1bdx jj1bdx commented Oct 12, 2022

Add a DeleteField("fieldname") method to ADIFRecord.
This is necessary to delete an unwanted ADIF data field completely in the map structure of an ADIF record.

I've also added the test code as follows to adifrecord_test.go:

func TestDeleteField(t *testing.T) {
        testData := map[string]string{
                "call":         "W1AW",
                "notes":        "This is a notice",
                "STATION_CALL": "KF4MDV"}
        expected := [2]string{"call", "station_call"}

        record := NewADIFRecord()
        for k, v := range testData {
                record.SetValue(k, v)
        }
        success, err := record.DeleteField("nothere")
        if err != ErrNoSuchField {
                t.Fatal(err)
        }
        success, err = record.DeleteField("notes")
        if !success || err != nil {
                t.Fatalf("success: %t, err: %v", success, err)
        }
        fieldNames := record.GetFields()

        if len(fieldNames) != len(expected) {
                t.Fatalf("Expected %d fields but got %d", len(expected), len(fieldNames))
        }

OUTER:
        for _, exp := range expected {
                for _, field := range fieldNames {
                        if exp == field {
                                continue OUTER
                        }
                }
                t.Fatalf("Expected field %v wasn't in the actual fields", exp)
        }
}

@Matir
Copy link
Owner

Matir commented Oct 15, 2022

Thanks for the contribution!

@Matir Matir merged commit 17fdadc into Matir:master Oct 15, 2022
@xylo04
Copy link
Contributor

xylo04 commented Oct 28, 2022

This does not build.

./adifrecord.go:118:16: undefined: ErrNoSuchField

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants