Skip to content

Commit

Permalink
TranslatorSpec: Expressions gets translated in parenthesis so correct…
Browse files Browse the repository at this point in the history
… all tests accordingly

Fixes

[info] - cpp_stl:2 < 3 ? "foo" : "bar" *** FAILED ***
[info]   "([(2 < 3) ? (std::string("foo")) : (std::string("bar")]))" was not equal to "([2 < 3) ? (std::string("foo")) : (std::string("bar"]))" (TranslatorSpec.scala:133)
[info]   Analysis:
[info]   "([(2 < 3) ? (std::string("foo")) : (std::string("bar")]))" -> "([2 < 3) ? (std::string("foo")) : (std::string("bar"]))"
[info] - csharp:2 < 3 ? "foo" : "bar" *** FAILED ***
[info]   "[(2 < 3 ? "foo" : "bar")]" was not equal to "[2 < 3 ? "foo" : "bar"]" (TranslatorSpec.scala:133)
[info]   Analysis:
[info]   "[(2 < 3 ? "foo" : "bar")]" -> "[2 < 3 ? "foo" : "bar"]"
[info] - java:2 < 3 ? "foo" : "bar" *** FAILED ***
[info]   "[(2 < 3 ? "foo" : "bar")]" was not equal to "[2 < 3 ? "foo" : "bar"]" (TranslatorSpec.scala:133)
[info]   Analysis:
[info]   "[(2 < 3 ? "foo" : "bar")]" -> "[2 < 3 ? "foo" : "bar"]"
[info] - javascript:2 < 3 ? "foo" : "bar" *** FAILED ***
[info]   "[(2 < 3 ? "foo" : "bar")]" was not equal to "[2 < 3 ? "foo" : "bar"]" (TranslatorSpec.scala:133)
[info]   Analysis:
[info]   "[(2 < 3 ? "foo" : "bar")]" -> "[2 < 3 ? "foo" : "bar"]"
[info] - lua:2 < 3 ? "foo" : "bar" *** FAILED ***
[info]   "utils.box_unwrap([(2 < 3) and utils.box_wrap("foo") or ("bar")])" was not equal to "utils.box_unwrap([2 < 3 and utils.box_wrap("foo") or "bar"])" (TranslatorSpec.scala:133)
[info]   Analysis:
[info]   "utils.box_unwrap([(2 < 3) and utils.box_wrap("foo") or ("bar")])" -> "utils.box_unwrap([2 < 3 and utils.box_wrap("foo") or "bar"])"
[info] - perl:2 < 3 ? "foo" : "bar" *** FAILED ***
[info]   "[(2 < 3 ? "foo" : "bar")]" was not equal to "[2 < 3 ? "foo" : "bar"]" (TranslatorSpec.scala:133)
[info]   Analysis:
[info]   "[(2 < 3 ? "foo" : "bar")]" -> "[2 < 3 ? "foo" : "bar"]"
[info] - php:2 < 3 ? "foo" : "bar" *** FAILED ***
[info]   "[(2 < 3 ? "foo" : "bar")]" was not equal to "[2 < 3 ? "foo" : "bar"]" (TranslatorSpec.scala:133)
[info]   Analysis:
[info]   "[(2 < 3 ? "foo" : "bar")]" -> "[2 < 3 ? "foo" : "bar"]"
[info] - python:2 < 3 ? "foo" : "bar" *** FAILED ***
[info]   "[(u"foo" if 2 < 3 else u"bar")]" was not equal to "[u"foo" if 2 < 3 else u"bar"]" (TranslatorSpec.scala:133)
[info]   Analysis:
[info]   "[(u"foo" if 2 < 3 else u"bar")]" -> "[u"foo" if 2 < 3 else u"bar"]"
[info] - ruby:2 < 3 ? "foo" : "bar" *** FAILED ***
[info]   "[(2 < 3 ? "foo" : "bar")]" was not equal to "[2 < 3 ? "foo" : "bar"]" (TranslatorSpec.scala:133)
[info]   Analysis:
[info]   "[(2 < 3 ? "foo" : "bar")]" -> "[2 < 3 ? "foo" : "bar"]"

[info] - cpp_stl:some_bool.to_i *** FAILED ***
[info]   "[((some_bool()) ? 1 : 0])" was not equal to "[some_bool(])" (TranslatorSpec.scala:197)
[info]   Analysis:
[info]   "[((some_bool()) ? 1 : 0])" -> "[some_bool(])"
[info] - lua:some_bool.to_i *** FAILED ***
[info]   "[(self.some_bool and 1 or 0)]" was not equal to "[self.some_bool and 1 or 0]" (TranslatorSpec.scala:197)
[info]   Analysis:
[info]   "[(self.some_bool and 1 or 0)]" -> "[self.some_bool and 1 or 0]"

[info] - cpp_stl:a != 2 and a != 5 *** FAILED ***
[info]   "[ ((a() != 2) && (a() != 5)) ]" was not equal to "[a() != 2 && a() != 5]" (TranslatorSpec.scala:280)
[info]   Analysis:
[info]   "[ ((a() != 2) && (a() != 5)) ]" -> "[a() != 2 && a() != 5]"
[info] - csharp:a != 2 and a != 5 *** FAILED ***
[info]   "[ ((A != 2) && (A != 5)) ]" was not equal to "[A != 2 && A != 5]" (TranslatorSpec.scala:280)
[info]   Analysis:
[info]   "[ ((A != 2) && (A != 5)) ]" -> "[A != 2 && A != 5]"
[info] - java:a != 2 and a != 5 *** FAILED ***
[info]   "[ ((a() != 2) && (a() != 5)) ]" was not equal to "[a() != 2 && a() != 5]" (TranslatorSpec.scala:280)
[info]   Analysis:
[info]   "[ ((a() != 2) && (a() != 5)) ]" -> "[a() != 2 && a() != 5]"
[info] - javascript:a != 2 and a != 5 *** FAILED ***
[info]   "[ ((this.a != 2) && (this.a != 5)) ]" was not equal to "[this.a != 2 && this.a != 5]" (TranslatorSpec.scala:280)
[info]   Analysis:
[info]   "[ ((this.a != 2) && (this.a != 5)) ]" -> "[this.a != 2 && this.a != 5]"
[info] - lua:a != 2 and a != 5 *** FAILED ***
[info]   "[ ((self.a ~= 2) and (self.a ~= 5)) ]" was not equal to "[self.a ~= 2 and self.a ~= 5]" (TranslatorSpec.scala:280)
[info]   Analysis:
[info]   "[ ((self.a ~= 2) and (self.a ~= 5)) ]" -> "[self.a ~= 2 and self.a ~= 5]"
[info] - perl:a != 2 and a != 5 *** FAILED ***
[info]   "[ (($self->a() != 2) && ($self->a() != 5)) ]" was not equal to "[$self->a() != 2 && $self->a() != 5]" (TranslatorSpec.scala:280)
[info]   Analysis:
[info]   "[ (($self->a() != 2) && ($self->a() != 5)) ]" -> "[$self->a() != 2 && $self->a() != 5]"
[info] - php:a != 2 and a != 5 *** FAILED ***
[info]   "[ (($this->a() != 2) && ($this->a() != 5)) ]" was not equal to "[$this->a() != 2 && $this->a() != 5]" (TranslatorSpec.scala:280)
[info]   Analysis:
[info]   "[ (($this->a() != 2) && ($this->a() != 5)) ]" -> "[$this->a() != 2 && $this->a() != 5]"
[info] - python:a != 2 and a != 5 *** FAILED ***
[info]   "[ ((self.a != 2) and (self.a != 5)) ]" was not equal to "[self.a != 2 and self.a != 5]" (TranslatorSpec.scala:280)
[info]   Analysis:
[info]   "[ ((self.a != 2) and (self.a != 5)) ]" -> "[self.a != 2 and self.a != 5]"
[info] - ruby:a != 2 and a != 5 *** FAILED ***
[info]   "[ ((a != 2) && (a != 5)) ]" was not equal to "[a != 2 && a != 5]" (TranslatorSpec.scala:280)
[info]   Analysis:
[info]   "[ ((a != 2) && (a != 5)) ]" -> "[a != 2 && a != 5]"

[info] - python:"str".reverse *** FAILED ***
[info]   "[(u"str")][::-1]" was not equal to "[u"str"][::-1]" (TranslatorSpec.scala:507)
[info]   Analysis:
[info]   "[(u"str")][::-1]" -> "[u"str"][::-1]"
  • Loading branch information
Mingun committed Mar 8, 2024
1 parent b15324d commit 30c0201
Showing 1 changed file with 20 additions and 20 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 @@ -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",
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"
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 @@ -535,7 +535,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 30c0201

Please sign in to comment.