From e1c82b02803a7cd81e9e65b8678b581aca9dd06f Mon Sep 17 00:00:00 2001 From: August Lautt Date: Tue, 19 May 2026 11:25:00 -0400 Subject: [PATCH 1/2] Add Golang --- .../01-example-unit/04-challenges.md | 2 +- app/cmd/markdown/questions/golang.go | 112 ++++++++++++++++++ app/cmd/markdown/questions/questions_test.go | 1 + app/cmd/markdown/root.go | 1 + app/cmd/root.go | 2 +- 5 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 app/cmd/markdown/questions/golang.go diff --git a/app/cmd/embeds/walkthrough/01-example-unit/04-challenges.md b/app/cmd/embeds/walkthrough/01-example-unit/04-challenges.md index e4674a4..83b5ea0 100644 --- a/app/cmd/embeds/walkthrough/01-example-unit/04-challenges.md +++ b/app/cmd/embeds/walkthrough/01-example-unit/04-challenges.md @@ -31,7 +31,7 @@ When generating challenges with the `learn md` command, you can see explanations * short answer * number * paragraph -* code snippet--js, py, java, sql (code directly in Learn) +* code snippet--js, py, java, go, sql (code directly in Learn) * custom-snippet--write your own `Dockerfile` and `test.sh` to allow student code to run in a customized container * project, testable project (code locally, submit a repo) diff --git a/app/cmd/markdown/questions/golang.go b/app/cmd/markdown/questions/golang.go new file mode 100644 index 0000000..0b9ece4 --- /dev/null +++ b/app/cmd/markdown/questions/golang.go @@ -0,0 +1,112 @@ +package questions + +import ( + "github.com/spf13/cobra" +) + +func NewGoCommand(params NewQuestionCommandParams) *cobra.Command { + params.name = "Go" + params.abbr = "go" + params.maxTemplate = goTemplate + params.minTemplate = goTemplateMin + params.long = goLongDescription + + return createQuestionCommand(params) +} + +const goLongDescription = `Go Code Snippet Challenges allow a student to write Go code directly in +Learn. The submission is evaluated against unit tests that are set up as part +of the Challenge. The student then sees the standard output from the test +runner in Learn. + +The test runner automatically wraps the submission in ` + "`package main`" + `, so the +placeholder and tests blocks should not declare a package — just write the +function, any imports, and the tests.` + +const goTemplate = ` + + +### !challenge + +* type: code-snippet +* language: golang +* id: %s +* title: [text, a short question title] + + + + + +##### !question + +[markdown, your question] + +##### !end-question + +##### !placeholder + +[the code below is the starting code in the web editor] +~~~go +// DoSomething returns true +func DoSomething() bool { + // return true + return false +} +~~~ + +##### !end-placeholder + +##### !tests + +[the go tests below will run against the student submission] +~~~go +import ( + "strings" + "testing" +) + +func TestDoSomething(t *testing.T) { + if !DoSomething() { + t.Errorf("%s should return true", strings.ToLower("DoSomething")) + } +} +~~~ + +##### !end-tests + + + +### !end-challenge + +` + +const goTemplateMin = ` + +### !challenge + +* type: code-snippet +* language: golang +* id: %s +* title: + +##### !question + + + +##### !end-question + +##### !placeholder + + + +##### !end-placeholder + +##### !tests + + + +##### !end-tests + +### !end-challenge + +` diff --git a/app/cmd/markdown/questions/questions_test.go b/app/cmd/markdown/questions/questions_test.go index 1b07079..670c5a2 100644 --- a/app/cmd/markdown/questions/questions_test.go +++ b/app/cmd/markdown/questions/questions_test.go @@ -21,6 +21,7 @@ func getTestCases() []testCase { return []testCase{ {"checkbox", "cb", NewCheckBoxCommand, checkboxTemplate, checkboxTemplateMin}, {"customsnippet", "cs", NewCustomSnippetCommand, customSnippetTemplate, customSnippetTemplateMin}, + {"go", "go", NewGoCommand, goTemplate, goTemplateMin}, {"java", "ja", NewJavaCommand, javaTemplate, javaTemplateMin}, {"javascript", "js", NewJavaScriptCommand, javascriptTemplate, javascriptTemplateMin}, {"multiplechoice", "mc", NewMultipleChoiceCommand, multipleChoiceTemplate, multipleChoiceTemplateMin}, diff --git a/app/cmd/markdown/root.go b/app/cmd/markdown/root.go index f73b6ce..6831e87 100644 --- a/app/cmd/markdown/root.go +++ b/app/cmd/markdown/root.go @@ -57,6 +57,7 @@ func addQuestionCommands(c *cobra.Command) { questions.NewPythonCommand, questions.NewSqlCommand, questions.NewRubyCommand, + questions.NewGoCommand, questions.NewUploadCommand, questions.NewCustomSnippetCommand, questions.NewProjectCommand, diff --git a/app/cmd/root.go b/app/cmd/root.go index 9fa8249..5e456b9 100644 --- a/app/cmd/root.go +++ b/app/cmd/root.go @@ -22,7 +22,7 @@ Please set your API token with this command: learn set --api_token= Date: Tue, 19 May 2026 12:03:04 -0400 Subject: [PATCH 2/2] Remove setup reference --- app/cmd/markdown/questions/golang.go | 1 - 1 file changed, 1 deletion(-) diff --git a/app/cmd/markdown/questions/golang.go b/app/cmd/markdown/questions/golang.go index 0b9ece4..5cacdfb 100644 --- a/app/cmd/markdown/questions/golang.go +++ b/app/cmd/markdown/questions/golang.go @@ -35,7 +35,6 @@ const goTemplate = ` - ##### !question