I’m stuck on Stage #NI6.
I’ve tried … every possible way of do it manually and logically for me (with addition of ai support).
Here are my logs:
remote: [tester::#NI6] Running tests for Stage #NI6 (Quoting - Single quotes)
remote: [tester::#NI6] [setup] export PATH=/tmp/raspberry/pineapple/raspberry:$PATH
remote: [tester::#NI6] Running ./your_program.sh
remote: [tester::#NI6] [setup] echo -n "grape banana." > "/tmp/quz/f 14"
remote: [tester::#NI6] [setup] echo -n "apple blueberry." > "/tmp/quz/f 94"
remote: [tester::#NI6] [setup] echo -n "blueberry pear." > "/tmp/quz/f 63"
remote: [your-program] $ echo 'world example'
remote: [your-program] world example
remote: [tester::#NI6] ✓ Received expected response
remote: [your-program] $ echo example test
remote: [your-program] example test
remote: [tester::#NI6] ✓ Received expected response
remote: [your-program] $ echo 'hello shell' 'test''world'
remote: [your-program] hello shell testworld
remote: [tester::#NI6] ✓ Received expected response
remote: [your-program] $ cat '/tmp/quz/f 14' '/tmp/quz/f 94' '/tmp/quz/f 63'
remote: [your-program] cat: '/tmp/quz/f: No such file or directory
remote: [tester::#NI6] Output does not match expected value.
remote: [tester::#NI6] Expected: "grape banana.apple blueberry.blueberry pear."
remote: [tester::#NI6] Received: "cat: '/tmp/quz/f: No such file or directory"
remote: [your-program] cat: : No such file or directory
remote: [your-program] cat: : No such file or directory
remote: [your-program] cat: 14': No such file or directory
remote: [your-program] cat: '/tmp/quz/f: No such file or directory
remote: [your-program] cat: : No such file or directory
remote: [your-program] cat: : No such file or directory
remote: [your-program] cat: 94': No such file or directory
remote: [your-program] cat: '/tmp/quz/f: No such file or directory
remote: [your-program] cat: : No such file or directory
remote: [your-program] cat: : No such file or directory
remote: [your-program] cat: 63': No such file or directory
remote: [your-program] cat: command not found
remote: [your-program] $
remote: [tester::#NI6] Assertion failed.
remote: [tester::#NI6] Test failed
remote:
remote: Try our CLI to run tests faster without Git: https://codecrafters.io/cli
remote:
remote: View our article on debugging test failures: https://codecrafters.io/debug
remote:
And here’s a snippet of my code:
func handleEchoCommand(args []string) {
if len(args) == 1 {
// prints current (last) exit code when argument is $?
if args[0] == "$?" {
return
}
}
// initialized result array for the quoted arguments
var res []string
isClosedDoubleQuote := true
isClosedSingleQuote := true
for _, arg := range args {
if strings.Contains(arg, "'") || strings.Contains(arg, "\"") {
totalDoubleQuote := strings.Count(arg, "\"")
totalSingleQuote := strings.Count(arg, "'")
// check if the argument is quoted
arg = strings.Trim(arg, "'\"")
arg = strings.ReplaceAll(arg, "'", "")
if totalDoubleQuote%2 == 1 {
isClosedDoubleQuote = false
}
if totalSingleQuote%2 == 1 {
isClosedSingleQuote = false
}
res = append(res, arg)
continue
}
if !isClosedDoubleQuote || !isClosedSingleQuote && len(arg) == 0 {
res = append(res, "")
continue
}
// check if the argument is quoted
arg = strings.ReplaceAll(arg, "\\", "")
// collecting all the the quoted arguments
if len(arg) > 0 {
res = append(res, arg)
}
}
// join the array into a string
join_res := strings.Join(res, " ")
fmt.Fprintf(os.Stdout, join_res+"\n")
}