Skip to content

Commit 82f16c9

Browse files
committed
wordle work
1 parent b26d42f commit 82f16c9

File tree

7 files changed

+324
-117
lines changed

7 files changed

+324
-117
lines changed

cli/clidisplay/resources.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func Parameters(writer io.Writer, params []types.Parameter, files map[string]*hc
7272
//}
7373

7474
tableWriter.AppendRow(table.Row{
75-
fmt.Sprintf("%s: %s\n%s", p.Name, p.Description, formatOptions(strVal, p.Options)),
75+
fmt.Sprintf("(%s) %s: %s\n%s", p.DisplayName, p.Name, p.Description, formatOptions(strVal, p.Options)),
7676
})
7777

7878
if hcl.Diagnostics(p.Diagnostics).HasErrors() {

preview_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,22 @@ func Test_Extract(t *testing.T) {
371371
"beta": ap().unknown(),
372372
},
373373
},
374+
{
375+
name: "wordle",
376+
dir: "wordle",
377+
expTags: map[string]string{},
378+
input: preview.Input{
379+
PlanJSONPath: "",
380+
ParameterValues: map[string]string{
381+
"first": "curse",
382+
},
383+
Owner: types.WorkspaceOwner{},
384+
},
385+
unknownTags: []string{},
386+
params: map[string]assertParam{
387+
"first": ap().value("curse"),
388+
},
389+
},
374390
} {
375391
t.Run(tc.name, func(t *testing.T) {
376392
t.Parallel()

testdata/wordle/checker/main.tf

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@ variable "correct" {
66
type = string
77
}
88

9-
output "result" {
10-
value = join("", [
9+
locals {
10+
valid = length(var.input) == 5
11+
result = join("", [
1112
for i in range(0, length(var.correct)) : (
1213
substr(var.input, i, 1) == substr(var.correct, i, 1) ? "#" : "_"
1314
)
1415
])
16+
}
17+
18+
output "result" {
19+
value = local.result
20+
}
21+
22+
output "valid" {
23+
value = local.valid
1524
}

testdata/wordle/main.tf

Lines changed: 141 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -14,130 +14,157 @@ locals {
1414
}
1515
}
1616

17-
module "word_one" {
18-
source = "./checker"
19-
input = data.coder_parameter.first.value
17+
module "one" {
18+
source = "./word"
19+
index = 0
2020
correct = local.correct
21+
pattern = "."
2122
}
2223

23-
data "coder_parameter" "first" {
24-
name = "first"
25-
display_name = "First word"
26-
description = "Enter a 5 letter word"
27-
type = "string"
28-
order = 1
29-
30-
validation {
31-
regex = local.validation.regex
32-
error = local.validation.error
33-
}
34-
}
35-
36-
// ---
37-
module "word_two" {
38-
source = "./checker"
39-
input = data.coder_parameter.second[0].value
40-
correct = local.correct
41-
}
42-
43-
data "coder_parameter" "second" {
44-
count = 1
45-
# count = length(data.coder_parameter.first.value) == 5 ? 1 : 0
46-
47-
name = "second"
48-
display_name = "Second word"
49-
description = "Previous word matches: ${module.word_one.result}"
50-
type = "string"
51-
order = 2
52-
53-
validation {
54-
regex = local.validation.regex
55-
error = local.validation.error
56-
}
57-
}
58-
59-
// ---
60-
module "word_three" {
61-
source = "./checker"
62-
input = data.coder_parameter.third[0].value
24+
module "two" {
25+
count = module.one.valid ? 1 : 0
26+
source = "./word"
27+
index = 1
6328
correct = local.correct
29+
pattern = module.one.result
6430
}
6531

66-
data "coder_parameter" "third" {
67-
count = 1
68-
# count = try(length(data.coder_parameter.second[0].value) == 5, false) ? 1 : 0
69-
70-
name = "third"
71-
display_name = "Third word"
72-
description = "Previous word matches: ${module.word_two.result}"
73-
type = "string"
74-
order = 3
75-
76-
validation {
77-
regex = local.validation.regex
78-
error = local.validation.error
79-
}
80-
}
81-
82-
// ---
83-
module "word_four" {
84-
source = "./checker"
85-
input = data.coder_parameter.fourth[0].value
86-
correct = local.correct
32+
data "coder_parameter" "dump" {
33+
name = "dump"
34+
display_name = "${module.one.valid}"
35+
description = "Dump the state"
36+
type = "string"
37+
order = 100
38+
default = ""
8739
}
8840

89-
data "coder_parameter" "fourth" {
90-
count = 1
91-
name = "fourth"
92-
display_name = "Fourth word"
93-
description = "Previous word matches: ${module.word_three.result}"
94-
type = "string"
95-
order = 4
96-
97-
validation {
98-
regex = local.validation.regex
99-
error = local.validation.error
100-
}
101-
}
102-
103-
// ---
104-
module "word_five" {
105-
source = "./checker"
106-
input = data.coder_parameter.fifth[0].value
107-
correct = local.correct
108-
}
10941

110-
data "coder_parameter" "fifth" {
111-
count = 1
112-
name = "fifth"
113-
display_name = "Fifth word"
114-
description = "Previous word matches: ${module.word_four.result}"
115-
type = "string"
116-
order = 5
11742

118-
validation {
119-
regex = local.validation.regex
120-
error = local.validation.error
121-
}
122-
}
123-
124-
// ---
125-
# module "word_six" {
43+
#
44+
# module "word_one" {
12645
# source = "./checker"
127-
# input = data.coder_parameter.fifth.value
46+
# input = data.coder_parameter.first.value
12847
# correct = local.correct
12948
# }
130-
131-
data "coder_parameter" "six" {
132-
count = 1
133-
name = "sixth"
134-
display_name = "Sixth word"
135-
description = "Previous word matches: ${module.word_five.result}"
136-
type = "string"
137-
order = 6
138-
139-
validation {
140-
regex = local.validation.regex
141-
error = local.validation.error
142-
}
143-
}
49+
#
50+
# data "coder_parameter" "first" {
51+
# name = "first"
52+
# display_name = "First word"
53+
# description = "Enter a 5 letter word"
54+
# type = "string"
55+
# order = 1
56+
#
57+
# validation {
58+
# regex = local.validation.regex
59+
# error = local.validation.error
60+
# }
61+
# }
62+
#
63+
# // ---
64+
# module "word_two" {
65+
# source = "./checker"
66+
# input = data.coder_parameter.second[0].value
67+
# correct = local.correct
68+
# }
69+
#
70+
# data "coder_parameter" "second" {
71+
# count = 1
72+
# # count = length(data.coder_parameter.first.value) == 5 ? 1 : 0
73+
#
74+
# name = "second"
75+
# display_name = "Second word"
76+
# description = "Previous word matches: ${module.word_one.result}"
77+
# type = "string"
78+
# order = 2
79+
#
80+
# validation {
81+
# regex = local.validation.regex
82+
# error = local.validation.error
83+
# }
84+
# }
85+
#
86+
# // ---
87+
# module "word_three" {
88+
# source = "./checker"
89+
# input = data.coder_parameter.third[0].value
90+
# correct = local.correct
91+
# }
92+
#
93+
# data "coder_parameter" "third" {
94+
# count = 1
95+
# # count = try(length(data.coder_parameter.second[0].value) == 5, false) ? 1 : 0
96+
#
97+
# name = "third"
98+
# display_name = "Third word"
99+
# description = "Previous word matches: ${module.word_two.result}"
100+
# type = "string"
101+
# order = 3
102+
#
103+
# validation {
104+
# regex = local.validation.regex
105+
# error = local.validation.error
106+
# }
107+
# }
108+
#
109+
# // ---
110+
# module "word_four" {
111+
# source = "./checker"
112+
# input = data.coder_parameter.fourth[0].value
113+
# correct = local.correct
114+
# }
115+
#
116+
# data "coder_parameter" "fourth" {
117+
# count = 1
118+
# name = "fourth"
119+
# display_name = "Fourth word"
120+
# description = "Previous word matches: ${module.word_three.result}"
121+
# type = "string"
122+
# order = 4
123+
#
124+
# validation {
125+
# regex = local.validation.regex
126+
# error = local.validation.error
127+
# }
128+
# }
129+
#
130+
# // ---
131+
# module "word_five" {
132+
# source = "./checker"
133+
# input = data.coder_parameter.fifth[0].value
134+
# correct = local.correct
135+
# }
136+
#
137+
# data "coder_parameter" "fifth" {
138+
# count = 1
139+
# name = "fifth"
140+
# display_name = "Fifth word"
141+
# description = "Previous word matches: ${module.word_four.result}"
142+
# type = "string"
143+
# order = 5
144+
#
145+
# validation {
146+
# regex = local.validation.regex
147+
# error = local.validation.error
148+
# }
149+
# }
150+
#
151+
# // ---
152+
# # module "word_six" {
153+
# # source = "./checker"
154+
# # input = data.coder_parameter.fifth.value
155+
# # correct = local.correct
156+
# # }
157+
#
158+
# data "coder_parameter" "six" {
159+
# count = 1
160+
# name = "sixth"
161+
# display_name = "Sixth word"
162+
# description = "Previous word matches: ${module.word_five.result}"
163+
# type = "string"
164+
# order = 6
165+
#
166+
# validation {
167+
# regex = local.validation.regex
168+
# error = local.validation.error
169+
# }
170+
# }

testdata/wordle/word/main.tf

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
}
6+
}
7+
}
8+
9+
locals {
10+
names = ["first", "second", "third", "fourth", "fifth", "sixth"]
11+
capitalized = "${upper(substr(local.names[var.index], 0, 1))}${substr(local.names[var.index], 1, length(local.names[var.index]) - 1)}"
12+
}
13+
14+
// what word is this?
15+
variable "index" {
16+
type = number
17+
}
18+
19+
// the correct word the player is trying to guess
20+
variable "correct" {
21+
type = string
22+
}
23+
24+
// The pattern for showing the previous correct letters.
25+
variable "pattern" {
26+
type = string
27+
}
28+
29+
// optional for debugging
30+
variable "default" {
31+
type = string
32+
default = ""
33+
}
34+
35+
data "coder_parameter" "word" {
36+
name = local.names[var.index]
37+
display_name = "${local.capitalized} word ${module.checker.valid}"
38+
description = var.pattern
39+
type = "string"
40+
order = var.index + 10
41+
default = var.default
42+
43+
validation {
44+
regex = "^[a-zA-Z]{5}$"
45+
error = "You must enter a 5 letter word."
46+
}
47+
}
48+
49+
module "checker" {
50+
source = "../checker"
51+
input = data.coder_parameter.word.value
52+
correct = var.correct
53+
}
54+
55+
output "result" {
56+
value = module.checker.result
57+
}
58+
59+
output "valid" {
60+
value = module.checker.valid
61+
# value = length(data.coder_parameter.word.value) == 5
62+
}

0 commit comments

Comments
 (0)