Skip to content

Commit

Permalink
Fix TranslatorSpec tests (#273)
Browse files Browse the repository at this point in the history
This PR fixes TranslatorSpec tests by changing expected values to the actually used.

Most commits fixes errors that was introduced during refactorings which did not update tests. This is understandable -- if the tests are already constantly falling, then few people think that they need to see if their changes break some of them.

Many tests related to that that each expression was wrapped in parenthesis even when this is not necessary. I know, the resulting code because of this can look ugly, and probably you want to remove those extra parenthesis instead of baking them into tests... but implementing such translation is a long story and I think, it is better to fix tests now just so you can use normal workflow where other PRs will be accepted based on passed tests instead of blindly trust to the PR author and maintainers' reviews. I think everyone will agree that this has already led to a bunch of errors that have been hidden for years. If you want to remove those extra parenthesis, then open a separate issue / PR, where the changes in the code and in the tests will be made simultaneously.

As a result, after this PR is only 21 failed tests (61 before) and only 9 in TranslatorSpec due to missing implementations of various features. I recommend disable those tests until features would be implemented, but I don't know how to do that. Anyway, this is better to do in another PR.
  • Loading branch information
Mingun authored Mar 8, 2024
1 parent 8aeb79a commit d071323
Showing 1 changed file with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class TranslatorSpec extends AnyFunSpec {
everybody("1 == 2", "1 == 2", CalcBooleanType)

full("2 < 3 ? \"foo\" : \"bar\"", CalcIntType, CalcStrType, Map[LanguageCompilerStatic, String](
CppCompiler -> "(2 < 3) ? (std::string(\"foo\")) : (std::string(\"bar\"))",
CSharpCompiler -> "2 < 3 ? \"foo\" : \"bar\"",
CppCompiler -> "((2 < 3) ? (std::string(\"foo\")) : (std::string(\"bar\")))",
CSharpCompiler -> "(2 < 3 ? \"foo\" : \"bar\")",
GoCompiler ->
"""var tmp1 string;
|if (2 < 3) {
Expand All @@ -145,13 +145,13 @@ class TranslatorSpec extends AnyFunSpec {
| tmp1 = "bar"
|}
|tmp1""".stripMargin,
JavaCompiler -> "2 < 3 ? \"foo\" : \"bar\"",
JavaScriptCompiler -> "2 < 3 ? \"foo\" : \"bar\"",
LuaCompiler -> "utils.box_unwrap(2 < 3 and utils.box_wrap(\"foo\") or \"bar\")",
PerlCompiler -> "2 < 3 ? \"foo\" : \"bar\"",
PHPCompiler -> "2 < 3 ? \"foo\" : \"bar\"",
PythonCompiler -> "u\"foo\" if 2 < 3 else u\"bar\"",
RubyCompiler -> "2 < 3 ? \"foo\" : \"bar\""
JavaCompiler -> "(2 < 3 ? \"foo\" : \"bar\")",
JavaScriptCompiler -> "(2 < 3 ? \"foo\" : \"bar\")",
LuaCompiler -> "utils.box_unwrap((2 < 3) and utils.box_wrap(\"foo\") or (\"bar\"))",
PerlCompiler -> "(2 < 3 ? \"foo\" : \"bar\")",
PHPCompiler -> "(2 < 3 ? \"foo\" : \"bar\")",
PythonCompiler -> "(u\"foo\" if 2 < 3 else u\"bar\")",
RubyCompiler -> "(2 < 3 ? \"foo\" : \"bar\")"
))

everybodyExcept("~777", "~777", Map[LanguageCompilerStatic, String](
Expand Down Expand Up @@ -203,7 +203,7 @@ class TranslatorSpec extends AnyFunSpec {
}

full("some_bool.to_i", CalcBooleanType, CalcIntType, Map[LanguageCompilerStatic, String](
CppCompiler -> "some_bool()",
CppCompiler -> "((some_bool()) ? 1 : 0)",
CSharpCompiler -> "(SomeBool ? 1 : 0)",
GoCompiler -> """tmp1 := 0
|if this.SomeBool {
Expand All @@ -212,7 +212,7 @@ class TranslatorSpec extends AnyFunSpec {
|tmp1""".stripMargin,
JavaCompiler -> "(someBool() ? 1 : 0)",
JavaScriptCompiler -> "(this.someBool | 0)",
LuaCompiler -> "self.some_bool and 1 or 0",
LuaCompiler -> "(self.some_bool and 1 or 0)",
PerlCompiler -> "$self->some_bool()",
PHPCompiler -> "intval($this->someBool())",
PythonCompiler -> "int(self.some_bool)",
Expand Down Expand Up @@ -286,16 +286,16 @@ class TranslatorSpec extends AnyFunSpec {
))

full("a != 2 and a != 5", CalcIntType, CalcBooleanType, Map[LanguageCompilerStatic, String](
CppCompiler -> "a() != 2 && a() != 5",
CSharpCompiler -> "A != 2 && A != 5",
GoCompiler -> "a != 2 && a != 5",
JavaCompiler -> "a() != 2 && a() != 5",
JavaScriptCompiler -> "this.a != 2 && this.a != 5",
LuaCompiler -> "self.a ~= 2 and self.a ~= 5",
PerlCompiler -> "$self->a() != 2 && $self->a() != 5",
PHPCompiler -> "$this->a() != 2 && $this->a() != 5",
PythonCompiler -> "self.a != 2 and self.a != 5",
RubyCompiler -> "a != 2 && a != 5"
CppCompiler -> " ((a() != 2) && (a() != 5)) ",
CSharpCompiler -> " ((A != 2) && (A != 5)) ",
GoCompiler -> " ((this.A != 2) && (this.A != 5)) ",
JavaCompiler -> " ((a() != 2) && (a() != 5)) ",
JavaScriptCompiler -> " ((this.a != 2) && (this.a != 5)) ",
LuaCompiler -> " ((self.a ~= 2) and (self.a ~= 5)) ",
PerlCompiler -> " (($self->a() != 2) && ($self->a() != 5)) ",
PHPCompiler -> " (($this->a() != 2) && ($this->a() != 5)) ",
PythonCompiler -> " ((self.a != 2) and (self.a != 5)) ",
RubyCompiler -> " ((a != 2) && (a != 5)) "
))
}

Expand Down Expand Up @@ -536,7 +536,7 @@ class TranslatorSpec extends AnyFunSpec {
LuaCompiler -> "string.reverse(\"str\")",
PerlCompiler -> "scalar(reverse(\"str\"))",
PHPCompiler -> "strrev(\"str\")",
PythonCompiler -> "u\"str\"[::-1]",
PythonCompiler -> "(u\"str\")[::-1]",
RubyCompiler -> "\"str\".reverse"
))

Expand Down

0 comments on commit d071323

Please sign in to comment.