Skip to content

Commit

Permalink
Format test plan adoc after generation
Browse files Browse the repository at this point in the history
Former-commit-id: cfdab55
  • Loading branch information
hasty committed Jun 25, 2024
1 parent 2a6a3ef commit ab03e61
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
7 changes: 7 additions & 0 deletions asciidoc/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ func parseColumnAttribute(a *NamedAttribute) (*TableColumnsAttribute, error) {
}
col.Width = One(TableColumnWidth(width))
}
case columnMatchPercentage:
percentage, err := strconv.Atoi(s)
if err != nil {
return nil, fmt.Errorf("invalid width %s: %w", s, err)

}
col.Percentage = One(int(percentage))
case columnMatchStyle:
switch s {
case "a":
Expand Down
2 changes: 2 additions & 0 deletions asciidoc/render/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ func Elements(cxt *Context, prefix string, elementList ...asciidoc.Element) (err
cxt.WriteString("+")
case *asciidoc.Counter:
renderCounter(cxt, el)
case *asciidoc.ThematicBreak:
cxt.WriteString("'''\n")
case nil:
default:
err = fmt.Errorf("unknown render element type: %T", el)
Expand Down
2 changes: 1 addition & 1 deletion cmd/format/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func format(cmd *cobra.Command, args []string) (err error) {
}

ids := pipeline.NewConcurrentMapPresized[string, *pipeline.Data[render.InputDocument]](docs.Size())
err = pipeline.Cast[*spec.Doc, render.InputDocument](docs, ids)
err = pipeline.Cast(docs, ids)
if err != nil {
return err
}
Expand Down
27 changes: 21 additions & 6 deletions cmd/testplan/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"log/slog"

"github.com/hasty/alchemy/asciidoc/render"
"github.com/hasty/alchemy/cmd/common"
"github.com/hasty/alchemy/internal/files"
"github.com/hasty/alchemy/internal/parse"
Expand All @@ -24,6 +25,7 @@ var Command = &cobra.Command{
func init() {
Command.Flags().String("specRoot", "connectedhomeip-spec", "the src root of your clone of CHIP-Specifications/connectedhomeip-spec")
Command.Flags().String("sdkRoot", "connectedhomeip", "the root of your clone of project-chip/connectedhomeip")
Command.Flags().String("testRoot", "chip-test-plans", "the root of your clone of CHIP-Specifications/chip-test-plans")
Command.Flags().Bool("overwrite", false, "overwrite existing test plans")
}

Expand Down Expand Up @@ -84,21 +86,34 @@ func tp(cmd *cobra.Command, args []string) (err error) {
}
}

var clusters pipeline.Map[string, *pipeline.Data[*matter.Cluster]]
clusters, err = pipeline.Process[*spec.Doc, *matter.Cluster](cxt, pipelineOptions, &common.EntityFilter[*spec.Doc, *matter.Cluster]{}, specDocs)
generator := testplan.NewGenerator(testRoot, overwrite)
var testplans pipeline.Map[string, *pipeline.Data[string]]
testplans, err = pipeline.Process[*spec.Doc, string](cxt, pipelineOptions, generator, specDocs)
if err != nil {
return err
}

generator := testplan.NewGenerator(testRoot, overwrite)
var testplans pipeline.Map[string, *pipeline.Data[string]]
testplans, err = pipeline.Process[*matter.Cluster, string](cxt, pipelineOptions, generator, clusters)
docReader := spec.NewStringReader("Reading test plans")
testplanDocs, err := pipeline.Process[string, *spec.Doc](cxt, pipelineOptions, docReader, testplans)
if err != nil {
return err
}

ids := pipeline.NewConcurrentMapPresized[string, *pipeline.Data[render.InputDocument]](testplanDocs.Size())
err = pipeline.Cast(testplanDocs, ids)
if err != nil {
return err
}

renderer := render.NewRenderer()
var renders pipeline.Map[string, *pipeline.Data[string]]
renders, err = pipeline.Process[render.InputDocument, string](cxt, pipelineOptions, renderer, ids)
if err != nil {
return err
}

writer := files.NewWriter[string]("Writing test plans", fileOptions)
_, err = pipeline.Process[string, struct{}](cxt, pipelineOptions, writer, testplans)
_, err = pipeline.Process[string, struct{}](cxt, pipelineOptions, writer, renders)
if err != nil {
return err
}
Expand Down
26 changes: 26 additions & 0 deletions matter/spec/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,29 @@ func (r Reader) Process(cxt context.Context, input *pipeline.Data[struct{}], ind
outputs = append(outputs, &pipeline.Data[*Doc]{Path: input.Path, Content: doc})
return
}

type StringReader struct {
name string
}

func NewStringReader(name string) StringReader {
return StringReader{name: name}
}

func (r StringReader) Name() string {
return r.name
}

func (r StringReader) Type() pipeline.ProcessorType {
return pipeline.ProcessorTypeIndividual
}

func (r StringReader) Process(cxt context.Context, input *pipeline.Data[string], index int32, total int32) (outputs []*pipeline.Data[*Doc], extras []*pipeline.Data[string], err error) {
var doc *Doc
doc, err = Read(input.Content, input.Path)
if err != nil {
return
}
outputs = append(outputs, &pipeline.Data[*Doc]{Path: input.Path, Content: doc})
return
}

0 comments on commit ab03e61

Please sign in to comment.