diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2025-07-05 15:19:15 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2025-07-05 15:19:15 -0700 |
| commit | b6bca2b7fe943ca4fd8f62a44bcfcc0c9f5a6de1 (patch) | |
| tree | a689744f07dbd61e6e33e1b081dc335a43c1fb57 /hotline/field_test.go | |
| parent | 1f3e5ec139022c20be8ca61b467b96ae7e78a36a (diff) | |
Add comprehensive test coverage for news.go functions
- Add table-driven tests for GetNewsArtListData, DataSize, NewsArtListData.Read, NewsArtList.Read, and newsPathScanner
- Improve test coverage from 0% to 87.5%-100% for these functions
- Add test for Field.DecodeNewsPath function
- Fix NewsArtList.Read to return nil instead of io.EOF for proper io.Reader behavior
- Add constants for NewsFlavorCount and improve code documentation
Diffstat (limited to 'hotline/field_test.go')
| -rw-r--r-- | hotline/field_test.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/hotline/field_test.go b/hotline/field_test.go index 676098c..3440b0d 100644 --- a/hotline/field_test.go +++ b/hotline/field_test.go @@ -229,3 +229,70 @@ func TestField_DecodeInt(t *testing.T) { }) } } + +func TestField_DecodeNewsPath(t *testing.T) { + type fields struct { + Data []byte + } + tests := []struct { + name string + fields fields + want []string + wantErr assert.ErrorAssertionFunc + }{ + { + name: "empty field data", + fields: fields{Data: []byte{}}, + want: []string{}, + wantErr: assert.NoError, + }, + { + name: "single path", + fields: fields{Data: []byte{ + 0x00, 0x01, // path count = 1 + 0x00, 0x00, 0x05, // 2 bytes unused + 1 byte length (5) + 0x48, 0x65, 0x6c, 0x6c, 0x6f, // "Hello" + }}, + want: []string{"Hello"}, + wantErr: assert.NoError, + }, + { + name: "multiple paths", + fields: fields{Data: []byte{ + 0x00, 0x02, // path count = 2 + 0x00, 0x00, 0x05, // 2 bytes unused + 1 byte length (5) + 0x48, 0x65, 0x6c, 0x6c, 0x6f, // "Hello" + 0x00, 0x00, 0x05, // 2 bytes unused + 1 byte length (5) + 0x57, 0x6f, 0x72, 0x6c, 0x64, // "World" + }}, + want: []string{"Hello", "World"}, + wantErr: assert.NoError, + }, + { + name: "example from comments - nested categories", + fields: fields{Data: []byte{ + 0x00, 0x03, // path count = 3 + 0x00, 0x00, 0x10, // 2 bytes unused + 1 byte length (16) + 0x54, 0x6f, 0x70, 0x20, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x20, 0x42, 0x75, 0x6e, 0x64, 0x6c, 0x65, // "Top Level Bundle" + 0x00, 0x00, 0x13, // 2 bytes unused + 1 byte length (19) + 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x20, 0x42, 0x75, 0x6e, 0x64, 0x6c, 0x65, // "Second Level Bundle" + 0x00, 0x00, 0x0f, // 2 bytes unused + 1 byte length (15) + 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x20, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, // "Nested Category" + }}, + want: []string{"Top Level Bundle", "Second Level Bundle", "Nested Category"}, + wantErr: assert.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f := &Field{ + Data: tt.fields.Data, + } + got, err := f.DecodeNewsPath() + if !tt.wantErr(t, err, "DecodeNewsPath()") { + return + } + assert.Equalf(t, tt.want, got, "DecodeNewsPath()") + }) + } +} |