[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.
[tester::#NI6] Running tests for Stage #NI6 (Quoting - Single quotes)
[tester::#NI6] Running ./your_program.sh
[your-program] $ echo 'example shell'
[your-program] example shell
[tester::#NI6] ✓ Received expected response
[your-program] $ echo shell hello
[your-program] shell hello
[tester::#NI6] ✓ Received expected response
[your-program] $ echo 'world test' 'hello''example'
[your-program] world test hello example
[tester::#NI6] Output does not match expected value.
[tester::#NI6] Expected: "world test helloexample"
[tester::#NI6] Received: "world test hello example"
[your-program] $
[tester::#NI6] Assertion failed.
[tester::#NI6] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)
And I’m completely out of ideas. I even checked out code examples and copied one of the solutions (currently on my repository) but that also failed. I’m open to any ideas. Here is my repo: GitHub - danilovict2/go-shell
I’m sorry I only just realized the repo was private. I’ve changed it to public, so you can go check out the code there, it’s in internal/reader/reader.go
@danilovict2 To be honest, I’m also a beginner in Go, so I might not be able to help you effectively just by reviewing code that’s not working yet.
How about we try some rubber duck debugging? If you could briefly explain your current approach for parsing quoted strings, we can work together to brainstorm potential solutions.
Or let me know if you need help understanding this error message:
[tester::#NI6] Output does not match expected value.
[tester::#NI6] Expected: "world test helloexample"
[tester::#NI6] Received: "world test hello example"
I’m don’t know Go well, but as far as I see, you treat each quoted as separate token:
for {
start := strings.Index(s, "'")
if start == -1 {
tokens = append(tokens, strings.Fields(s)...)
break
}
tokens = append(tokens, strings.Fields(s[:start])...)
s = s[start+1:]
end := strings.Index(s, "'")
token := s[:end]
tokens = append(tokens, token)
s = s[end+1:]
}
but in the case of shell, it’s one token since no whitespace between, so you need to track state somehow and add token when you in proper state, but your code adds part before opening ' and text between quotes every time it finds quote
As I’ve mentioned before, this is a passing solution in code examples. Specifically the solution of a guy called ProjectElon. Still, thanks for the suggestion and I’ll make sure to try parsing tokens that aren’t separated with space as one