Move the seeded randomness and the {seq()} counters into internal/drawstate
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/larvit/fejkdata/internal/drawstate"
|
||||
)
|
||||
|
||||
// Column is one rendered column of a record. Value is the rendered text, which a
|
||||
@@ -133,7 +135,7 @@ func (f *Generator) FakeRecord(path string) (*Record, error) {
|
||||
var frames frameStack
|
||||
sc := renderScope{frames: &frames}
|
||||
if t, isTable := n.(*table); isTable {
|
||||
if n, sc.row, err = tableRecord(f.rand, t, tail); err != nil {
|
||||
if n, sc.row, err = tableRecord(f.draws, t, tail); err != nil {
|
||||
return nil, fmt.Errorf("fejkdata: %s: %w", path, err)
|
||||
}
|
||||
} else if len(tail) > 0 {
|
||||
@@ -147,12 +149,12 @@ func (f *Generator) FakeRecord(path string) (*Record, error) {
|
||||
if shape.err != nil {
|
||||
return nil, fmt.Errorf("fejkdata: %s %w", path, shape.err)
|
||||
}
|
||||
return renderRecord(f.rand, shape.template, shape.columns, sc), nil
|
||||
return renderRecord(f.draws, shape.template, shape.columns, sc), nil
|
||||
}
|
||||
|
||||
// tableRecord walks a path's tail from a table to the table whose row is the record, and that
|
||||
// row, selected or drawn.
|
||||
func tableRecord(s *generatorState, t *table, tail []string) (node, renderedRow, error) {
|
||||
func tableRecord(s *drawstate.State, t *table, tail []string) (node, renderedRow, error) {
|
||||
n, pins, err := descend(s, t, tail)
|
||||
if err != nil {
|
||||
return nil, renderedRow{}, err
|
||||
@@ -204,7 +206,7 @@ func (t *RecordTemplate) Fake() *Record {
|
||||
t.g.mu.Lock()
|
||||
defer t.g.mu.Unlock()
|
||||
var frames frameStack
|
||||
return renderRecord(t.g.rand, t.template, t.columns, renderScope{frames: &frames})
|
||||
return renderRecord(t.g.draws, t.template, t.columns, renderScope{frames: &frames})
|
||||
}
|
||||
|
||||
// NewRecordTemplate compiles an inline record — a JSON object with a format and
|
||||
@@ -260,7 +262,7 @@ func recordOf(n node) (*template, []Column, error) {
|
||||
|
||||
// renderRecord draws each column once, in the name order recordOf fixed, as one render, so the
|
||||
// columns read one pick of each name; a table's columns read sc's row.
|
||||
func renderRecord(s *generatorState, t *template, columns []Column, sc renderScope) *Record {
|
||||
func renderRecord(s *drawstate.State, t *template, columns []Column, sc renderScope) *Record {
|
||||
if mark := sc.renderFrame(t); mark >= 0 {
|
||||
defer sc.frames.pop(mark)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user