diff --git a/exercises/practice/allergies/lib/test_runner.gd b/exercises/practice/allergies/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/allergies/lib/test_runner.gd +++ b/exercises/practice/allergies/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/anagram/lib/test_runner.gd b/exercises/practice/anagram/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/anagram/lib/test_runner.gd +++ b/exercises/practice/anagram/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/armstrong-numbers/lib/test_runner.gd b/exercises/practice/armstrong-numbers/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/armstrong-numbers/lib/test_runner.gd +++ b/exercises/practice/armstrong-numbers/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/atbash-cipher/lib/test_runner.gd b/exercises/practice/atbash-cipher/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/atbash-cipher/lib/test_runner.gd +++ b/exercises/practice/atbash-cipher/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/binary-search/lib/test_runner.gd b/exercises/practice/binary-search/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/binary-search/lib/test_runner.gd +++ b/exercises/practice/binary-search/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/bob/lib/test_runner.gd b/exercises/practice/bob/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/bob/lib/test_runner.gd +++ b/exercises/practice/bob/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/camicia/lib/test_runner.gd b/exercises/practice/camicia/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/camicia/lib/test_runner.gd +++ b/exercises/practice/camicia/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/collatz-conjecture/lib/test_runner.gd b/exercises/practice/collatz-conjecture/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/collatz-conjecture/lib/test_runner.gd +++ b/exercises/practice/collatz-conjecture/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/darts/lib/test_runner.gd b/exercises/practice/darts/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/darts/lib/test_runner.gd +++ b/exercises/practice/darts/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/difference-of-squares/lib/test_runner.gd b/exercises/practice/difference-of-squares/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/difference-of-squares/lib/test_runner.gd +++ b/exercises/practice/difference-of-squares/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/eliuds-eggs/lib/test_runner.gd b/exercises/practice/eliuds-eggs/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/eliuds-eggs/lib/test_runner.gd +++ b/exercises/practice/eliuds-eggs/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/etl/lib/test_runner.gd b/exercises/practice/etl/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/etl/lib/test_runner.gd +++ b/exercises/practice/etl/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/flatten-array/lib/test_runner.gd b/exercises/practice/flatten-array/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/flatten-array/lib/test_runner.gd +++ b/exercises/practice/flatten-array/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/food-chain/lib/test_runner.gd b/exercises/practice/food-chain/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/food-chain/lib/test_runner.gd +++ b/exercises/practice/food-chain/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/hamming/lib/test_runner.gd b/exercises/practice/hamming/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/hamming/lib/test_runner.gd +++ b/exercises/practice/hamming/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/hello-world/lib/test_runner.gd b/exercises/practice/hello-world/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/hello-world/lib/test_runner.gd +++ b/exercises/practice/hello-world/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/isogram/lib/test_runner.gd b/exercises/practice/isogram/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/isogram/lib/test_runner.gd +++ b/exercises/practice/isogram/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/leap/lib/test_runner.gd b/exercises/practice/leap/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/leap/lib/test_runner.gd +++ b/exercises/practice/leap/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/luhn/lib/test_runner.gd b/exercises/practice/luhn/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/luhn/lib/test_runner.gd +++ b/exercises/practice/luhn/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/matching-brackets/lib/test_runner.gd b/exercises/practice/matching-brackets/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/matching-brackets/lib/test_runner.gd +++ b/exercises/practice/matching-brackets/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/pangram/lib/test_runner.gd b/exercises/practice/pangram/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/pangram/lib/test_runner.gd +++ b/exercises/practice/pangram/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/perfect-numbers/lib/test_runner.gd b/exercises/practice/perfect-numbers/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/perfect-numbers/lib/test_runner.gd +++ b/exercises/practice/perfect-numbers/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/phone-number/lib/test_runner.gd b/exercises/practice/phone-number/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/phone-number/lib/test_runner.gd +++ b/exercises/practice/phone-number/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/prime-factors/lib/test_runner.gd b/exercises/practice/prime-factors/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/prime-factors/lib/test_runner.gd +++ b/exercises/practice/prime-factors/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/prism/lib/test_runner.gd b/exercises/practice/prism/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/prism/lib/test_runner.gd +++ b/exercises/practice/prism/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/raindrops/lib/test_runner.gd b/exercises/practice/raindrops/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/raindrops/lib/test_runner.gd +++ b/exercises/practice/raindrops/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/rational-numbers/lib/test_runner.gd b/exercises/practice/rational-numbers/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/rational-numbers/lib/test_runner.gd +++ b/exercises/practice/rational-numbers/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/resistor-color-duo/lib/test_runner.gd b/exercises/practice/resistor-color-duo/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/resistor-color-duo/lib/test_runner.gd +++ b/exercises/practice/resistor-color-duo/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/resistor-color-expert/lib/test_runner.gd b/exercises/practice/resistor-color-expert/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/resistor-color-expert/lib/test_runner.gd +++ b/exercises/practice/resistor-color-expert/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/resistor-color-trio/lib/test_runner.gd b/exercises/practice/resistor-color-trio/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/resistor-color-trio/lib/test_runner.gd +++ b/exercises/practice/resistor-color-trio/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/resistor-color/lib/test_runner.gd b/exercises/practice/resistor-color/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/resistor-color/lib/test_runner.gd +++ b/exercises/practice/resistor-color/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/reverse-string/lib/test_runner.gd b/exercises/practice/reverse-string/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/reverse-string/lib/test_runner.gd +++ b/exercises/practice/reverse-string/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/robot-simulator/lib/test_runner.gd b/exercises/practice/robot-simulator/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/robot-simulator/lib/test_runner.gd +++ b/exercises/practice/robot-simulator/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/scrabble-score/lib/test_runner.gd b/exercises/practice/scrabble-score/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/scrabble-score/lib/test_runner.gd +++ b/exercises/practice/scrabble-score/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/secret-handshake/lib/test_runner.gd b/exercises/practice/secret-handshake/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/secret-handshake/lib/test_runner.gd +++ b/exercises/practice/secret-handshake/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/series/lib/test_runner.gd b/exercises/practice/series/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/series/lib/test_runner.gd +++ b/exercises/practice/series/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/sieve/lib/test_runner.gd b/exercises/practice/sieve/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/sieve/lib/test_runner.gd +++ b/exercises/practice/sieve/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/space-age/lib/test_runner.gd b/exercises/practice/space-age/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/space-age/lib/test_runner.gd +++ b/exercises/practice/space-age/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/spiral-matrix/lib/test_runner.gd b/exercises/practice/spiral-matrix/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/spiral-matrix/lib/test_runner.gd +++ b/exercises/practice/spiral-matrix/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/sublist/lib/test_runner.gd b/exercises/practice/sublist/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/sublist/lib/test_runner.gd +++ b/exercises/practice/sublist/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/sum-of-multiples/lib/test_runner.gd b/exercises/practice/sum-of-multiples/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/sum-of-multiples/lib/test_runner.gd +++ b/exercises/practice/sum-of-multiples/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/swift-scheduling/lib/test_runner.gd b/exercises/practice/swift-scheduling/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/swift-scheduling/lib/test_runner.gd +++ b/exercises/practice/swift-scheduling/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/triangle/lib/test_runner.gd b/exercises/practice/triangle/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/triangle/lib/test_runner.gd +++ b/exercises/practice/triangle/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/two-bucket/lib/test_runner.gd b/exercises/practice/two-bucket/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/two-bucket/lib/test_runner.gd +++ b/exercises/practice/two-bucket/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/two-fer/lib/test_runner.gd b/exercises/practice/two-fer/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/two-fer/lib/test_runner.gd +++ b/exercises/practice/two-fer/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/variable-length-quantity/lib/test_runner.gd b/exercises/practice/variable-length-quantity/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/variable-length-quantity/lib/test_runner.gd +++ b/exercises/practice/variable-length-quantity/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed." diff --git a/exercises/practice/word-count/lib/test_runner.gd b/exercises/practice/word-count/lib/test_runner.gd index 9274583..08b5709 100644 --- a/exercises/practice/word-count/lib/test_runner.gd +++ b/exercises/practice/word-count/lib/test_runner.gd @@ -397,9 +397,33 @@ class Runner: self.result_writer.write(results) -func load_script(solution_script_path: String) -> Object: +func load_solution(path: String) -> Object: """Load a script. This helper is needed to catch failures without aborting the error handling.""" - return load(solution_script_path).new() + if not FileAccess.file_exists(path): + return null + var re = RegEx.create_from_string("^( )+") + var replace = RegEx.create_from_string("( )+") + var changed = false + var lines = [] + for line in FileAccess.open(path, FileAccess.READ).get_as_text().split("\n"): + var m = re.search(line) + if m == null: + lines.append(line) + else: + changed = true + var new = [] + for i in range(m.get_end() / 4): + new.append("\t") + new.append(line.substr(m.get_end())) + lines.append("".join(new)) + if not changed: + return load(path).new() + + path = OS.get_temp_dir() + "/solution.gd" + FileAccess.open(path, FileAccess.WRITE).store_string("\n".join(lines)) + var solution = load(path).new() + DirAccess.remove_absolute(path) + return solution func load_solution_script(solution_script_path: String, result_writer: ResultWriter, stderr: ErrorReader) -> Array: @@ -409,7 +433,7 @@ func load_solution_script(solution_script_path: String, result_writer: ResultWri """ # Make sure the STDERR file is empty. stderr.get_error_message() - var solution_script = load_script(solution_script_path) + var solution_script = load_solution(solution_script_path) if solution_script == null: var message: String = "The solution file could not be parsed."