Skip to content

Commit ccfad1d

Browse files
committed
gen: add vars
1 parent a81f28a commit ccfad1d

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

test/gen/gen.go

+25-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ func node(depth int) string {
149149
})(depth - 1)
150150
}
151151
return oneOf(list[fn]{
152-
{arrayNode, 1},
153-
{mapNode, 1},
152+
{sequenceNode, 1},
153+
{variableNode, 1},
154+
{arrayNode, 10},
155+
{mapNode, 10},
154156
{identifierNode, 1000},
155157
{memberNode, 1500},
156158
{unaryNode, 100},
@@ -189,6 +191,9 @@ func booleanNode(_ int) string {
189191
}
190192

191193
func identifierNode(_ int) string {
194+
if maybe() {
195+
return "x"
196+
}
192197
return random(dict)
193198
}
194199

@@ -338,3 +343,21 @@ func conditionalNode(depth int) string {
338343
{fmt.Sprintf("%v ?: %v", node(depth-1), node(depth-1)), 20},
339344
})
340345
}
346+
347+
func sequenceNode(depth int) string {
348+
var items []string
349+
for i := 0; i < oneOf(list[int]{
350+
{2, 50},
351+
{3, 25},
352+
}); i++ {
353+
items = append(items, node(depth-1))
354+
}
355+
if maybe() {
356+
return strings.Join(items, "; ")
357+
}
358+
return fmt.Sprintf("(%v)", strings.Join(items, ", "))
359+
}
360+
361+
func variableNode(depth int) string {
362+
return fmt.Sprintf("let x = %v; %v", node(depth-1), node(depth-1))
363+
}

0 commit comments

Comments
 (0)