-
Notifications
You must be signed in to change notification settings - Fork 20
fix: [Concept] String Functions - add exercise templates #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| slug: 03_string_functions | ||
| title: String Functions | ||
| test_regex: ".*" | ||
| hints: | ||
| - Use strings.ToLower() for lowercase | ||
| - Use strings.ToUpper() for uppercase | ||
| - Use strings.ReplaceAll() to replace substrings | ||
| - Use strings.Contains(), HasPrefix(), HasSuffix() for checks | ||
| - Use strings.Split() and strings.Join() for slicing/joining | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package strings_funcs | ||
|
|
||
| import "strings" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== file location and content =="
if [ -f internal/exercises/templates/03_string_functions/strings.go ]; then
cat -n internal/exercises/templates/03_string_functions/strings.go
else
echo "missing file"
fi
echo
echo "== go.mod files =="
fd -a 'go.mod$|go.sum$' . | sed 's#^\./##' | while read -r f; do
echo "--- ${f#"$PWD/"}"
sed -n '1,120p' "$f"
done
echo
echo "== lint/config files =="
fd -a 'golangci.*|\.golangci\.ya?ml|\.golangci\.yaml$' . | sed "s#^\./##" | sort | while read -r f; do
echo "--- ${f#"$PWD/"}"
sed -n '1,220p' "$f"
done
echo
echo "== package declarations and imports in templates =="
rg -n '^(package |import |import \()' internal/exercises/templates -g '*.go' | head -200
echo
echo "== typecheck/lint config references for templates =="
rg -n 'exercises/templates|templates|golangci|typecheck|unused|enable-all|enable:' . -g '*.json' -g '*.yaml' -g '*.yml' -g '*.toml' -g '*.md' -g '*.go' | head -300Repository: zhravan/golearn Length of output: 22132 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== docs verify/incomplete behavior mentions =="
cat -n docs/contributing.md | sed -n '50,75p'
echo "---"
cat -n docs/getting-started.md | sed -n '50,110p'
echo "---"
cat -n CONTRIBUTING.md | sed -n '45,65p'
echo
echo "== CLI verify implementation candidates =="
rg -n 'func .*verify|Verify|verify|template|go run|mod|build|lint|typecheck' internal -g '*.go' | head -250
echo
echo "== inspect relevant CLI file sections =="
ast-grep outline internal/cli/commands.go --match 'func .*Verify' --view expanded || true
sed -n '340,470p' internal/cli/commands.goRepository: zhravan/golearn Length of output: 14173 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== internal/cli/commands.go relevant implementation =="
sed -n '120,225p' internal/cli/commands.go
echo
echo "== internal/exercises/solutions.go relevant implementation =="
sed -n '20,85p' internal/exercises/solutions.go
echo
echo "== Go workspace/package references =="
fd -a 'go.work$|go.work.sum$' . | sed 's#^\./##' | while read -r f; do
echo "--- ${f#"$PWD/"}"
cat "$f"
doneRepository: zhravan/golearn Length of output: 5601 Fix the placeholder so it type checks without
🧰 Tools🪛 golangci-lint (2.12.2)[error] 3-3: : # github.com/zhravan/golearn/internal/exercises/templates/03_string_functions [github.com/zhravan/golearn/internal/exercises/templates/03_string_functions.test] (typecheck) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||
|
|
||
| // Lowercase returns the lowercased version of s. | ||
| func Lowercase(s string) string { | ||
| // Replace this with the correct implementation | ||
| return "" | ||
| } | ||
|
|
||
| // Uppercase returns the uppercased version of s. | ||
| func Uppercase(s string) string { | ||
| // Replace this with the correct implementation | ||
| return "" | ||
| } | ||
|
|
||
| // ReplaceAll replaces all occurrences of old with new in s. | ||
| func ReplaceAll(s, old, new string) string { | ||
| // Replace this with the correct implementation | ||
| return "" | ||
| } | ||
|
|
||
| // Contains checks if s contains substr. | ||
| func Contains(s, substr string) bool { | ||
| // Replace this with the correct implementation | ||
| return false | ||
| } | ||
|
|
||
| // HasPrefix checks if s starts with prefix. | ||
| func HasPrefix(s, prefix string) bool { | ||
| // Replace this with the correct implementation | ||
| return false | ||
| } | ||
|
|
||
| // HasSuffix checks if s ends with suffix. | ||
| func HasSuffix(s, suffix string) bool { | ||
| // Replace this with the correct implementation | ||
| return false | ||
| } | ||
|
|
||
| // Split splits s by sep. | ||
| func Split(s, sep string) []string { | ||
| // Replace this with the correct implementation | ||
| return nil | ||
| } | ||
|
|
||
| // Join joins elements of slices using sep. | ||
| func Join(slices []string, sep string) string { | ||
| // Replace this with the correct implementation | ||
| return "" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package strings_funcs | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestLowercase(t *testing.T) { | ||
| if Lowercase("Hello") != "hello" { | ||
| t.Errorf("expected 'hello', got '%s'", Lowercase("Hello")) | ||
| } | ||
| } | ||
|
|
||
| func TestUppercase(t *testing.T) { | ||
| if Uppercase("Hello") != "HELLO" { | ||
| t.Errorf("expected 'HELLO', got '%s'", Uppercase("Hello")) | ||
| } | ||
| } | ||
|
|
||
| func TestReplaceAll(t *testing.T) { | ||
| if ReplaceAll("hello world", "o", "a") != "hella warld" { | ||
| t.Errorf("expected 'hella warld', got '%s'", ReplaceAll("hello world", "o", "a")) | ||
| } | ||
| } | ||
|
|
||
| func TestContains(t *testing.T) { | ||
| if !Contains("hello", "ell") { | ||
| t.Error("expected true") | ||
| } | ||
| if Contains("hello", "xyz") { | ||
| t.Error("expected false") | ||
| } | ||
| } | ||
|
|
||
| func TestHasPrefix(t *testing.T) { | ||
| if !HasPrefix("hello", "hel") { | ||
| t.Error("expected true") | ||
| } | ||
| if HasPrefix("hello", "world") { | ||
| t.Error("expected false") | ||
| } | ||
| } | ||
|
|
||
| func TestHasSuffix(t *testing.T) { | ||
| if !HasSuffix("hello", "llo") { | ||
| t.Error("expected true") | ||
| } | ||
| if HasSuffix("hello", "xyz") { | ||
| t.Error("expected false") | ||
| } | ||
| } | ||
|
|
||
| func TestSplit(t *testing.T) { | ||
| expected := []string{"a", "b", "c"} | ||
| result := Split("a,b,c", ",") | ||
| if len(result) != len(expected) { | ||
| t.Errorf("expected %v, got %v", expected, result) | ||
| } | ||
| } | ||
|
Comment on lines
+52
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "Files:"
git ls-files | rg 'strings_test\.go|strings\.(go|md|txt)' || true
echo
echo "Test file excerpt:"
file=$(git ls-files | rg '(^|/)strings_test\.go$' | head -n 1 || true)
if [ -n "${file:-}" ]; then
wc -l "$file"
sed -n '1,110p' "$file" | cat -n
fi
echo
echo "Implementation candidates:"
for f in $(git ls-files | rg '(^|/)strings\..*$' | head -n 5); do
echo "--- $f"
wc -l "$f"
rg -n "func Split|Split\\(" "$f" || true
done
echo
echo "Behavior probe for current assertion shape:"
python3 - <<'PY'
expected = ["a", "b", "c"]
cases = [
["a", "b", "c"],
["c", "b", "a"],
["x", "y", "z"],
["a", "b"],
["a", "b", "c", "d"],
]
for result in cases:
print(result, "current_test_passes=", len(result) == len(expected), "deep_equal=", result == expected)
PYRepository: zhravan/golearn Length of output: 2716 Assert the split elements, not only the slice length. A length check lets any three-element slice pass. Use a full-slice comparison so malformed split results fail. 🤖 Prompt for AI Agents |
||
|
|
||
| func TestJoin(t *testing.T) { | ||
| if Join([]string{"a", "b", "c"}, "-") != "a-b-c" { | ||
| t.Errorf("expected 'a-b-c', got '%s'", Join([]string{"a", "b", "c"}, "-")) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: zhravan/golearn
Length of output: 18351
Qualify
HasPrefixandHasSuffixwithstrings.The template defines
HasPrefixandHasSuffixin the same package and tests them directly, so the unqualified names in the hint can resolve to these exercise functions. Usestrings.Contains(),strings.HasPrefix(), andstrings.HasSuffix()instead.🤖 Prompt for AI Agents