From fd8c1b58e32d80ee524c77729d72fd29eaeefe88 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Tue, 13 Oct 2026 22:25:04 -0700 Subject: [PATCH] Update the test runner This pulls in https://github.com/exercism/gdscript-test-runner/pull/84 --- .../practice/allergies/lib/test_runner.gd | 30 +++++++++++++++++-- exercises/practice/anagram/lib/test_runner.gd | 30 +++++++++++++++++-- .../armstrong-numbers/lib/test_runner.gd | 30 +++++++++++++++++-- .../practice/atbash-cipher/lib/test_runner.gd | 30 +++++++++++++++++-- .../practice/binary-search/lib/test_runner.gd | 30 +++++++++++++++++-- exercises/practice/bob/lib/test_runner.gd | 30 +++++++++++++++++-- exercises/practice/camicia/lib/test_runner.gd | 30 +++++++++++++++++-- .../collatz-conjecture/lib/test_runner.gd | 30 +++++++++++++++++-- exercises/practice/darts/lib/test_runner.gd | 30 +++++++++++++++++-- .../difference-of-squares/lib/test_runner.gd | 30 +++++++++++++++++-- .../practice/eliuds-eggs/lib/test_runner.gd | 30 +++++++++++++++++-- exercises/practice/etl/lib/test_runner.gd | 30 +++++++++++++++++-- .../practice/flatten-array/lib/test_runner.gd | 30 +++++++++++++++++-- .../practice/food-chain/lib/test_runner.gd | 30 +++++++++++++++++-- exercises/practice/hamming/lib/test_runner.gd | 30 +++++++++++++++++-- .../practice/hello-world/lib/test_runner.gd | 30 +++++++++++++++++-- exercises/practice/isogram/lib/test_runner.gd | 30 +++++++++++++++++-- exercises/practice/leap/lib/test_runner.gd | 30 +++++++++++++++++-- exercises/practice/luhn/lib/test_runner.gd | 30 +++++++++++++++++-- .../matching-brackets/lib/test_runner.gd | 30 +++++++++++++++++-- exercises/practice/pangram/lib/test_runner.gd | 30 +++++++++++++++++-- .../perfect-numbers/lib/test_runner.gd | 30 +++++++++++++++++-- .../practice/phone-number/lib/test_runner.gd | 30 +++++++++++++++++-- .../practice/prime-factors/lib/test_runner.gd | 30 +++++++++++++++++-- exercises/practice/prism/lib/test_runner.gd | 30 +++++++++++++++++-- .../practice/raindrops/lib/test_runner.gd | 30 +++++++++++++++++-- .../rational-numbers/lib/test_runner.gd | 30 +++++++++++++++++-- .../resistor-color-duo/lib/test_runner.gd | 30 +++++++++++++++++-- .../resistor-color-expert/lib/test_runner.gd | 30 +++++++++++++++++-- .../resistor-color-trio/lib/test_runner.gd | 30 +++++++++++++++++-- .../resistor-color/lib/test_runner.gd | 30 +++++++++++++++++-- .../reverse-string/lib/test_runner.gd | 30 +++++++++++++++++-- .../robot-simulator/lib/test_runner.gd | 30 +++++++++++++++++-- .../scrabble-score/lib/test_runner.gd | 30 +++++++++++++++++-- .../secret-handshake/lib/test_runner.gd | 30 +++++++++++++++++-- exercises/practice/series/lib/test_runner.gd | 30 +++++++++++++++++-- exercises/practice/sieve/lib/test_runner.gd | 30 +++++++++++++++++-- .../practice/space-age/lib/test_runner.gd | 30 +++++++++++++++++-- .../practice/spiral-matrix/lib/test_runner.gd | 30 +++++++++++++++++-- exercises/practice/sublist/lib/test_runner.gd | 30 +++++++++++++++++-- .../sum-of-multiples/lib/test_runner.gd | 30 +++++++++++++++++-- .../swift-scheduling/lib/test_runner.gd | 30 +++++++++++++++++-- .../practice/triangle/lib/test_runner.gd | 30 +++++++++++++++++-- .../practice/two-bucket/lib/test_runner.gd | 30 +++++++++++++++++-- exercises/practice/two-fer/lib/test_runner.gd | 30 +++++++++++++++++-- .../lib/test_runner.gd | 30 +++++++++++++++++-- .../practice/word-count/lib/test_runner.gd | 30 +++++++++++++++++-- 47 files changed, 1269 insertions(+), 141 deletions(-) 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."