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/news.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/news.go')
| -rw-r--r-- | hotline/news.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/hotline/news.go b/hotline/news.go index c61a76f..1ddeebd 100644 --- a/hotline/news.go +++ b/hotline/news.go @@ -47,7 +47,7 @@ func (newscat *NewsCategoryListData15) GetNewsArtListData() (NewsArtListData, er for i, art := range newscat.Articles { id := make([]byte, 4) - binary.BigEndian.PutUint32(id, i) + binary.BigEndian.PutUint32(id, i) // The article's map key in the Articles map is its ID. newsArts = append(newsArts, NewsArtList{ ID: [4]byte(id), @@ -156,8 +156,8 @@ type NewsArtList struct { } var ( - NewsFlavorLen = []byte{0x0a} - NewsFlavor = []byte("text/plain") + NewsFlavor = []byte("text/plain") // NewsFlavor is always "text/plain" + NewsFlavorCount = []byte{0, 1} // NewsFlavorCount is always 1 ) func (nal *NewsArtList) Read(p []byte) (int, error) { @@ -166,12 +166,12 @@ func (nal *NewsArtList) Read(p []byte) (int, error) { nal.TimeStamp[:], nal.ParentID[:], nal.Flags[:], - []byte{0, 1}, // Flavor Count TODO: make this not hardcoded + NewsFlavorCount, []byte{uint8(len(nal.Title))}, nal.Title, []byte{uint8(len(nal.Poster))}, nal.Poster, - NewsFlavorLen, + []byte{uint8(len(NewsFlavor))}, NewsFlavor, nal.ArticleSize[:], ) @@ -183,7 +183,7 @@ func (nal *NewsArtList) Read(p []byte) (int, error) { n := copy(p, out[nal.readOffset:]) nal.readOffset += n - return n, io.EOF + return n, nil } type NewsFlavorList struct { |