From 83fe4a4d3d793c7f54ed6903e58f82a506d2d10e Mon Sep 17 00:00:00 2001 From: connero <88785126+conneroisu@users.noreply.github.com> Date: Mon, 3 Jun 2024 13:04:40 -0500 Subject: [PATCH] latest --- parse.go | 8 ++-- parse_test.go | 85 +++++++++++--------------------------- structure.go => reflect.go | 0 specify.go | 1 - testdata/static.go | 3 -- tt.json | 1 - 6 files changed, 28 insertions(+), 70 deletions(-) rename structure.go => reflect.go (100%) delete mode 100644 specify.go delete mode 100644 tt.json diff --git a/parse.go b/parse.go index 5472488b4..20528dcb8 100644 --- a/parse.go +++ b/parse.go @@ -21,8 +21,8 @@ const ( // NewFromString parses a string into a slice of structs. // -// The struct must have a field with the tag `seltabl`, a header selector with -// the tag `hSel`, and a data selector with the tag `dSel`. +// The struct must have a field with the tag seltabl, a header selector with +// the tag hSel, and a data selector with the tag dSel. // // The selectors responsibilties: // @@ -92,7 +92,7 @@ func NewFromString[T any](htmlInput string) ([]T, error) { headSelector := field.Tag.Get(headerSelectorTag) if headSelector == "" { return nil, fmt.Errorf( - "no header selector (%s) for field %s", + "no header selector (%s) defined for field %s", headerSelectorTag, headName, ) @@ -100,7 +100,7 @@ func NewFromString[T any](htmlInput string) ([]T, error) { headerRow := doc.Find(headSelector) if headerRow.Length() == 0 { return nil, fmt.Errorf( - "no header for field %s with selector (%s)", + "selector (%s) found no header for field %s", headName, headSelector, ) diff --git a/parse_test.go b/parse_test.go index 25588ac21..123366c84 100644 --- a/parse_test.go +++ b/parse_test.go @@ -1,10 +1,8 @@ package seltabl import ( - "fmt" "testing" - "github.com/bytedance/sonic" "github.com/conneroisu/seltabl/testdata" "github.com/stretchr/testify/assert" ) @@ -13,9 +11,6 @@ import ( func TestFixtureTables(t *testing.T) { p, err := NewFromString[testdata.FixtureStruct](testdata.FixtureABNumTable) assert.Nil(t, err) - for _, pp := range p { - fmt.Printf("pp %+v\n", pp) - } assert.Equal(t, "1", p[0].A) assert.Equal(t, "2", p[0].B) assert.Equal(t, "3", p[1].A) @@ -31,7 +26,6 @@ func TestNumberedTable(t *testing.T) { p, err := NewFromString[testdata.NumberedStruct](testdata.NumberedTable) assert.Nil(t, err) assert.NoError(t, err) - assert.Equal(t, "Row 1, Cell 1", p[0].Header1) assert.Equal(t, "Row 1, Cell 2", p[0].Header2) assert.Equal(t, "Row 1, Cell 3", p[0].Header3) @@ -43,63 +37,32 @@ func TestNumberedTable(t *testing.T) { assert.Equal(t, "Row 3, Cell 3", p[2].Header3) } -//
Supernova | -//Year | -//Type | -//Distance (light-years) | -//Notes | -//
---|---|---|---|---|
SN 1006 | -//1006 | -//Type Ia | -//7,200 | -//Brightest recorded supernova in history | -//
SN 1054 (Crab Nebula) | -//1054 | -//Type II | -//6,500 | -//Formed the Crab Nebula and pulsar | -//
SN 1572 (Tycho's Supernova) | -//1572 | -//Type Ia | -//8,000-10,000 | -//Observed by Tycho Brahe | -//
SN 1604 (Kepler's Supernova) | -//1604 | -//Type Ia | -//20,000 | -//Last observed supernova in the Milky Way | -//
SN 1987A | -//1987 | -//Type II | -//168,000 | -//Closest observed supernova since 1604 | -//
SN 1993J | -//1993 | -//Type IIb | -//11,000,000 | -//In the galaxy M81 | -//