summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Geyer <jensg@apache.org>2022-06-11 14:24:33 +0200
committerJens Geyer <jensg@apache.org>2022-06-13 23:05:02 +0200
commit7628392dff65d747a026fd5183466c4460047c92 (patch)
tree93bf9a9ee298720d608267034bf5d807ecc7b356
parente3eb9afb20a0535d44c203a4195db9822f8861fc (diff)
downloadthrift-7628392dff65d747a026fd5183466c4460047c92.tar.gz
THRIFT-5590 Haxe complex inits
Client: hx Patch: Jens Geyer This closes #2622
-rw-r--r--compiler/cpp/src/thrift/generate/t_haxe_generator.cc310
-rw-r--r--lib/haxe/test/HaxeTests.hxproj3
-rw-r--r--lib/haxe/test/cpp.hxml5
-rw-r--r--lib/haxe/test/csharp.hxml5
-rw-r--r--lib/haxe/test/flash.hxml5
-rw-r--r--lib/haxe/test/java.hxml5
-rw-r--r--lib/haxe/test/javascript.hxml5
-rw-r--r--lib/haxe/test/make_all.bat1
-rw-r--r--lib/haxe/test/neko.hxml5
-rw-r--r--lib/haxe/test/php.hxml5
-rw-r--r--lib/haxe/test/python.hxml5
-rw-r--r--lib/haxe/test/src/ConstantsTest.hx74
-rw-r--r--lib/haxe/test/src/Main.hx5
-rw-r--r--lib/haxe/test/src/MultiplexTest.hx4
-rw-r--r--lib/haxe/test/src/StreamTest.hx4
-rw-r--r--lib/haxe/test/src/TestBase.hx1
-rw-r--r--test/ConstantsDemo.thrift1
17 files changed, 294 insertions, 149 deletions
diff --git a/compiler/cpp/src/thrift/generate/t_haxe_generator.cc b/compiler/cpp/src/thrift/generate/t_haxe_generator.cc
index 42b41811d..757f207f0 100644
--- a/compiler/cpp/src/thrift/generate/t_haxe_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_haxe_generator.cc
@@ -91,12 +91,28 @@ public:
void print_const_value(std::ostream& out,
std::string name,
t_type* type,
- t_const_value* value,
- bool in_static,
- bool defval = false);
- std::string render_const_value(std::string name,
- t_type* type,
+ t_const_value* value);
+
+ void render_const_value(std::ostream& out,
+ t_type* type,
+ t_const_value* value);
+
+ void render_struct_initializer(std::ostream& out,
+ t_struct* type,
t_const_value* value);
+ void render_map_initializer(std::ostream& out,
+ t_map* type,
+ t_const_value* value);
+ void render_list_initializer(std::ostream& out,
+ t_list* type,
+ t_const_value* value);
+ void render_set_initializer(std::ostream& out,
+ t_set* type,
+ t_const_value* value);
+
+ // helper
+ std::string render_const_value_str( t_type* type, t_const_value* value);
+
/**
* Service-level generation functions
@@ -300,6 +316,7 @@ string t_haxe_generator::haxe_type_imports() {
+ "import haxe.ds.IntMap;\n"
+ "import haxe.ds.StringMap;\n"
+ "import haxe.ds.ObjectMap;\n"
+ + "import org.apache.thrift.helper.ObjectSet;\n"
+ "\n"
+ "#if flash\n"
+ "import flash.errors.ArgumentError;\n"
@@ -480,8 +497,7 @@ void t_haxe_generator::generate_consts(std::vector<t_const*> consts) {
print_const_value(f_consts,
(*c_iter)->get_name(),
(*c_iter)->get_type(),
- (*c_iter)->get_value(),
- false);
+ (*c_iter)->get_value());
}
indent_down();
indent(f_consts) << "}" << endl;
@@ -491,179 +507,185 @@ void t_haxe_generator::generate_consts(std::vector<t_const*> consts) {
void t_haxe_generator::print_const_value(std::ostream& out,
string name,
t_type* type,
- t_const_value* value,
- bool in_static,
- bool defval) {
+ t_const_value* value) {
type = get_true_type(type);
+ bool complex = type->is_struct() || type->is_xception() || type->is_map() || type->is_list() || type->is_set();
indent(out);
- if (!defval) {
- out << (in_static ? "var " : "public static inline var ");
+
+ out << "public static ";
+ if (!complex) {
+ out << "inline ";
}
- if (type->is_base_type()) {
- string v2 = render_const_value(name, type, value);
- out << name;
- if (!defval) {
- out << ":" << type_name(type);
- }
- out << " = " << v2 << ";" << endl << endl;
- } else if (type->is_enum()) {
- out << name;
- if (!defval) {
- out << ":" << type_name(type);
- }
- out << " = " << value->get_integer() << ";" << endl << endl;
- } else if (type->is_struct() || type->is_xception()) {
- const vector<t_field*>& fields = ((t_struct*)type)->get_members();
- vector<t_field*>::const_iterator f_iter;
- const map<t_const_value*, t_const_value*, t_const_value::value_compare>& val = value->get_map();
- map<t_const_value*, t_const_value*, t_const_value::value_compare>::const_iterator v_iter;
- out << name << ":" << type_name(type) << " = new " << type_name(type, false, true) << "();"
- << endl;
- if (!in_static) {
- indent(out) << "{" << endl;
- indent_up();
- indent(out) << "new function() : Void {" << endl;
- indent_up();
- }
- for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
- t_type* field_type = nullptr;
- for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- if ((*f_iter)->get_name() == v_iter->first->get_string()) {
- field_type = (*f_iter)->get_type();
- }
- }
- if (field_type == nullptr) {
- throw "type error: " + type->get_name() + " has no field " + v_iter->first->get_string();
- }
- string val = render_const_value(name, field_type, v_iter->second);
- indent(out) << name << ".";
- out << v_iter->first->get_string() << " = " << val << ";" << endl;
- }
- if (!in_static) {
- indent_down();
- indent(out) << "}();" << endl;
- indent_down();
- indent(out) << "}" << endl;
- }
- out << endl;
- } else if (type->is_map()) {
- out << name;
- if (!defval) {
- out << ":" << type_name(type);
- }
- out << " = new " << type_name(type, false, true) << "();" << endl;
- if (!in_static) {
- indent(out) << "{" << endl;
- indent_up();
- indent(out) << "new function() : Void {" << endl;
- indent_up();
- }
- t_type* ktype = ((t_map*)type)->get_key_type();
- t_type* vtype = ((t_map*)type)->get_val_type();
- const map<t_const_value*, t_const_value*, t_const_value::value_compare>& val = value->get_map();
- map<t_const_value*, t_const_value*, t_const_value::value_compare>::const_iterator v_iter;
- for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
- string key = render_const_value(name, ktype, v_iter->first);
- string val = render_const_value(name, vtype, v_iter->second);
- indent(out) << name << "[" << key << "] = " << val << ";" << endl;
- }
- if (!in_static) {
- indent_down();
- indent(out) << "}();" << endl;
- indent_down();
- indent(out) << "}" << endl;
- }
- out << endl;
- } else if (type->is_list() || type->is_set()) {
- out << name;
- if (!defval) {
- out << ":" << type_name(type);
- }
- out << " = new " << type_name(type, false, true) << "();" << endl;
- if (!in_static) {
- indent(out) << "{" << endl;
- indent_up();
- indent(out) << "new function() : Void {" << endl;
- indent_up();
- }
- t_type* etype;
- if (type->is_list()) {
- etype = ((t_list*)type)->get_elem_type();
- } else {
- etype = ((t_set*)type)->get_elem_type();
- }
- const vector<t_const_value*>& val = value->get_list();
- vector<t_const_value*>::const_iterator v_iter;
- for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
- string val = render_const_value(name, etype, *v_iter);
- indent(out) << name << "." << (type->is_list() ? "push" : "add") << "(" << val << ");"
- << endl;
- }
- if (!in_static) {
- indent_down();
- indent(out) << "}();" << endl;
- indent_down();
- indent(out) << "}" << endl;
- }
- out << endl;
- } else {
- throw "compiler error: no const of type " + type->get_name();
+ out << "var " << name;
+ if (complex) {
+ out << " (default,null)";
}
+ out << " : " << get_cap_name(type_name(type)) << " = ";
+ render_const_value(out, type, value);
+ out << ";" << endl << endl;
}
-string t_haxe_generator::render_const_value(string name,
- t_type* type,
- t_const_value* value) {
- (void)name;
- type = get_true_type(type);
+std::string t_haxe_generator::render_const_value_str( t_type* type, t_const_value* value) {
std::ostringstream render;
+ render_const_value(render, type, value);
+ return render.str();
+}
+
+
+void t_haxe_generator::render_const_value(std::ostream& out,
+ t_type* type,
+ t_const_value* value) {
+ type = get_true_type(type);
if (type->is_base_type()) {
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
switch (tbase) {
case t_base_type::TYPE_STRING:
- render << '"' << get_escaped_string(value) << '"';
+ out << '"' << get_escaped_string(value) << '"';
break;
case t_base_type::TYPE_BOOL:
- render << ((value->get_integer() > 0) ? "true" : "false");
+ out << ((value->get_integer() > 0) ? "true" : "false");
break;
case t_base_type::TYPE_I8:
- render << "(byte)" << value->get_integer();
+ out << "(byte)" << value->get_integer();
break;
case t_base_type::TYPE_I16:
- render << "(short)" << value->get_integer();
+ out << "(short)" << value->get_integer();
break;
case t_base_type::TYPE_I32:
- render << value->get_integer();
+ out << value->get_integer();
break;
case t_base_type::TYPE_I64:
- render << value->get_integer() << "L";
+ out << value->get_integer() << "L";
break;
case t_base_type::TYPE_DOUBLE:
if (value->get_type() == t_const_value::CV_INTEGER) {
- render << "(double)" << value->get_integer();
+ out << "(double)" << value->get_integer();
} else {
- render << value->get_double();
+ out << value->get_double();
}
break;
default:
throw "compiler error: no const of base type " + t_base_type::t_base_name(tbase);
}
} else if (type->is_enum()) {
- render << value->get_integer();
+ out << value->get_integer();
+ } else if (type->is_struct() || type->is_xception()) {
+ render_struct_initializer(out, (t_struct*)type, value);
+ } else if (type->is_map()) {
+ render_map_initializer(out, (t_map*)type, value);
+ } else if (type->is_list()) {
+ render_list_initializer(out, (t_list*)type, value);
+ } else if (type->is_set()) {
+ render_set_initializer(out, (t_set*)type, value);
} else {
- /* this is badly broken
- string t = tmp("tmp");
- print_const_value(out, t, type, value, true);
- render << t;
- */
- render << "null"; // we fix that later
+ throw "compiler error: no const of type " + type->get_name();
}
+}
- return render.str();
+void t_haxe_generator::render_struct_initializer(std::ostream& out,
+ t_struct* type,
+ t_const_value* value) {
+ out << "(function() : " << get_cap_name(type_name(type)) << " {" << endl;
+ indent_up();
+ indent(out) << "var tmp = new " << get_cap_name(type_name(type)) << "();" << endl;
+
+ const vector<t_field*>& fields = ((t_struct*)type)->get_members();
+ vector<t_field*>::const_iterator f_iter;
+ const map<t_const_value*, t_const_value*, t_const_value::value_compare>& values = value->get_map();
+ map<t_const_value*, t_const_value*, t_const_value::value_compare>::const_iterator v_iter;
+ for (v_iter = values.begin(); v_iter != values.end(); ++v_iter) {
+ t_type* field_type = nullptr;
+ for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
+ if ((*f_iter)->get_name() == v_iter->first->get_string()) {
+ field_type = (*f_iter)->get_type();
+ break;
+ }
+ }
+ if (field_type == nullptr) {
+ throw "type error: " + type->get_name() + " has no field " + v_iter->first->get_string();
+ }
+ indent(out) << "tmp." << v_iter->first->get_string() << " = ";
+ render_const_value(out, field_type, v_iter->second);
+ out << ";" << endl;
+ }
+
+ indent(out) << "return tmp;" << endl;
+ indent_down();
+ indent(out) << "})()"; // no endl
}
+void t_haxe_generator::render_map_initializer(std::ostream& out,
+ t_map* type,
+ t_const_value* value) {
+ out << "(function() : " << get_cap_name(type_name(type)) << " {" << endl;
+ indent_up();
+ indent(out) << "var tmp = new " << get_cap_name(type_name(type)) << "();" << endl;
+
+ t_type* key_type = ((t_map*)type)->get_key_type();
+ t_type* val_type = ((t_map*)type)->get_val_type();
+
+ const map<t_const_value*, t_const_value*, t_const_value::value_compare>& values = value->get_map();
+ map<t_const_value*, t_const_value*, t_const_value::value_compare>::const_iterator v_iter;
+ for (v_iter = values.begin(); v_iter != values.end(); ++v_iter) {
+ indent(out) << "tmp.set(";
+ render_const_value(out, key_type, v_iter->first);
+ out << ", ";
+ render_const_value(out, val_type, v_iter->second);
+ out << ");" << endl;
+ }
+
+ indent(out) << "return tmp;" << endl;
+ indent_down();
+ indent(out) << "})()"; // no endl
+}
+
+void t_haxe_generator::render_list_initializer(std::ostream& out,
+ t_list* type,
+ t_const_value* value) {
+ out << "(function() : " << get_cap_name(type_name(type)) << " {" << endl;
+ indent_up();
+ indent(out) << "var tmp = new " << get_cap_name(type_name(type)) << "();" << endl;
+
+ t_type* elm_type = type->get_elem_type();
+
+ const vector<t_const_value*>& values = value->get_list();
+ vector<t_const_value*>::const_iterator v_iter;
+ for (v_iter = values.begin(); v_iter != values.end(); ++v_iter) {
+ indent(out) << "tmp.add(";
+ render_const_value(out, elm_type, *v_iter);
+ out << ");" << endl;
+ }
+
+ indent(out) << "return tmp;" << endl;
+ indent_down();
+ indent(out) << "})()"; // no endl
+}
+
+void t_haxe_generator::render_set_initializer(std::ostream& out,
+ t_set* type,
+ t_const_value* value) {
+ out << "(function() : " << get_cap_name(type_name(type)) << " {" << endl;
+ indent_up();
+ indent(out) << "var tmp = new " << get_cap_name(type_name(type)) << "();" << endl;
+
+ t_type* elm_type = type->get_elem_type();
+
+ const vector<t_const_value*>& values = value->get_list();
+ vector<t_const_value*>::const_iterator v_iter;
+ for (v_iter = values.begin(); v_iter != values.end(); ++v_iter) {
+ indent(out) << "tmp.add(";
+ render_const_value(out, elm_type, *v_iter);
+ out << ");" << endl;
+ }
+
+ indent(out) << "return tmp;" << endl;
+ indent_down();
+ indent(out) << "})()"; // no endl
+}
+
+
/**
* Generates a struct definition for a thrift data type. This is a class
* with data members, read(), write(), and an inner Isset class.
@@ -803,7 +825,7 @@ void t_haxe_generator::generate_haxe_struct_definition(ostream& out,
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
if ((*m_iter)->get_value() != nullptr) {
indent(out) << "this." << (*m_iter)->get_name() << " = ";
- out << render_const_value((*m_iter)->get_name(), (*m_iter)->get_type(), (*m_iter)->get_value());
+ render_const_value( out, (*m_iter)->get_type(), (*m_iter)->get_value());
out << ";" << endl;
}
}
@@ -2655,7 +2677,7 @@ string t_haxe_generator::declare_field(t_field* tfield, bool init) {
if (init) {
t_type* ttype = get_true_type(tfield->get_type());
if (ttype->is_base_type() && tfield->get_value() != nullptr) {
- result += " = " + render_const_value(tfield->get_name(), ttype, tfield->get_value());
+ result += " = " + render_const_value_str( ttype, tfield->get_value());
} else if (ttype->is_base_type()) {
t_base_type::t_base tbase = ((t_base_type*)ttype)->get_base();
switch (tbase) {
diff --git a/lib/haxe/test/HaxeTests.hxproj b/lib/haxe/test/HaxeTests.hxproj
index 7ad23920d..839917b47 100644
--- a/lib/haxe/test/HaxeTests.hxproj
+++ b/lib/haxe/test/HaxeTests.hxproj
@@ -26,7 +26,7 @@
<option noInlineOnDebug="False" />
<option mainClass="Main" />
<option enabledebug="False" />
- <option additional="--macro include('org.apache.thrift', true)&#xA;--macro include('thrift', true)" />
+ <option additional="--macro include('org.apache.thrift', true)&#xA;--macro include('thrift', true)&#xA;--macro include('constantsDemo', true)" />
</build>
<!-- haxelib libraries -->
<haxelib>
@@ -54,6 +54,7 @@
</hiddenPaths>
<!-- Executed before build -->
<preBuildCommand>thrift -r -gen haxe ../../../test/ThriftTest.thrift
+thrift -r -gen haxe ../../../test/ConstantsDemo.thrift
thrift -r -gen haxe ../../../contrib/async-test/aggr.thrift
thrift -r -gen haxe ../../../lib/rb/benchmark/Benchmark.thrift</preBuildCommand>
<!-- Executed after build -->
diff --git a/lib/haxe/test/cpp.hxml b/lib/haxe/test/cpp.hxml
index 73848a8bc..28e1a017e 100644
--- a/lib/haxe/test/cpp.hxml
+++ b/lib/haxe/test/cpp.hxml
@@ -25,6 +25,11 @@
#this class wil be used as entry point for your app.
-main Main
+# forced compile of all source files
+--macro include('org.apache.thrift', true)
+--macro include('thrift', true)
+--macro include('constantsDemo', true)
+
#CPP target
-cpp bin
diff --git a/lib/haxe/test/csharp.hxml b/lib/haxe/test/csharp.hxml
index 4c34b0d94..6ddfd0767 100644
--- a/lib/haxe/test/csharp.hxml
+++ b/lib/haxe/test/csharp.hxml
@@ -25,6 +25,11 @@
#this class wil be used as entry point for your app.
-main Main
+# forced compile of all source files
+--macro include('org.apache.thrift', true)
+--macro include('thrift', true)
+--macro include('constantsDemo', true)
+
#CSHARP target
-cs bin/Test.exe
diff --git a/lib/haxe/test/flash.hxml b/lib/haxe/test/flash.hxml
index 8b1763190..130ab78d4 100644
--- a/lib/haxe/test/flash.hxml
+++ b/lib/haxe/test/flash.hxml
@@ -25,6 +25,11 @@
#this class wil be used as entry point for your app.
-main Main
+# forced compile of all source files
+--macro include('org.apache.thrift', true)
+--macro include('thrift', true)
+--macro include('constantsDemo', true)
+
#Flash target
-swf bin/Test.swf
diff --git a/lib/haxe/test/java.hxml b/lib/haxe/test/java.hxml
index c9471597c..b72d99fb9 100644
--- a/lib/haxe/test/java.hxml
+++ b/lib/haxe/test/java.hxml
@@ -25,6 +25,11 @@
#this class wil be used as entry point for your app.
-main Main
+# forced compile of all source files
+--macro include('org.apache.thrift', true)
+--macro include('thrift', true)
+--macro include('constantsDemo', true)
+
#Java target
-java bin/Test.jar
diff --git a/lib/haxe/test/javascript.hxml b/lib/haxe/test/javascript.hxml
index 18d9964c2..496e780ba 100644
--- a/lib/haxe/test/javascript.hxml
+++ b/lib/haxe/test/javascript.hxml
@@ -25,6 +25,11 @@
#this class wil be used as entry point for your app.
-main Main
+# forced compile of all source files
+--macro include('org.apache.thrift', true)
+--macro include('thrift', true)
+--macro include('constantsDemo', true)
+
#JavaScript target
-js bin/Test.js
diff --git a/lib/haxe/test/make_all.bat b/lib/haxe/test/make_all.bat
index 0314e18a3..8a063dd7c 100644
--- a/lib/haxe/test/make_all.bat
+++ b/lib/haxe/test/make_all.bat
@@ -27,6 +27,7 @@ set path=%HAXEPATH%;%HAXEPATH%\..\neko;%path%
rem # invoke Thrift comnpiler
thrift -r -gen haxe ..\..\..\test\ThriftTest.thrift
+thrift -r -gen haxe ..\..\..\test\ConstantsDemo.thrift
thrift -r -gen haxe ..\..\..\contrib\async-test\aggr.thrift
thrift -r -gen haxe ..\..\..\lib\rb\benchmark\Benchmark.thrift
if errorlevel 1 goto STOP
diff --git a/lib/haxe/test/neko.hxml b/lib/haxe/test/neko.hxml
index 2db70c8e6..eed22bd70 100644
--- a/lib/haxe/test/neko.hxml
+++ b/lib/haxe/test/neko.hxml
@@ -25,6 +25,11 @@
#this class wil be used as entry point for your app.
-main Main
+# forced compile of all source files
+--macro include('org.apache.thrift', true)
+--macro include('thrift', true)
+--macro include('constantsDemo', true)
+
#neko target
-neko bin/Test.n
diff --git a/lib/haxe/test/php.hxml b/lib/haxe/test/php.hxml
index 9fc23b6b0..3af54dab5 100644
--- a/lib/haxe/test/php.hxml
+++ b/lib/haxe/test/php.hxml
@@ -25,6 +25,11 @@
#this class wil be used as entry point for your app.
-main Main
+# forced compile of all source files
+--macro include('org.apache.thrift', true)
+--macro include('thrift', true)
+--macro include('constantsDemo', true)
+
#PHP target
-php bin/php/
#--php-front Main-debug.php
diff --git a/lib/haxe/test/python.hxml b/lib/haxe/test/python.hxml
index 4d6a133d6..58eb3cb71 100644
--- a/lib/haxe/test/python.hxml
+++ b/lib/haxe/test/python.hxml
@@ -25,6 +25,11 @@
#this class wil be used as entry point for your app.
-main Main
+# forced compile of all source files
+--macro include('org.apache.thrift', true)
+--macro include('thrift', true)
+--macro include('constantsDemo', true)
+
#Python target
-python bin/Test.py
diff --git a/lib/haxe/test/src/ConstantsTest.hx b/lib/haxe/test/src/ConstantsTest.hx
new file mode 100644
index 000000000..d0041e49f
--- /dev/null
+++ b/lib/haxe/test/src/ConstantsTest.hx
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package;
+
+import haxe.Int64;
+
+import org.apache.thrift.*;
+import org.apache.thrift.protocol.*;
+import org.apache.thrift.transport.*;
+import org.apache.thrift.server.*;
+import org.apache.thrift.meta_data.*;
+
+import constantsDemo.*; // generated code
+
+
+class ConstantsTest extends TestBase {
+
+ public static function Run(server : Bool) : Void
+ {
+ TestBase.Expect( ConstantsDemoConstants.myInt == 3, "myInt = 3");
+ TestBase.Expect( ConstantsDemoConstants.hex_const == 0x0001F, "hex_const = 31");
+ TestBase.Expect( ConstantsDemoConstants.negative_hex_constant == -0x0001F, "negative_hex_constant = -31");
+ TestBase.Expect( ConstantsDemoConstants.GEN_ME == -3523553, "GEN_ME = -3523553");
+ TestBase.Expect( ConstantsDemoConstants.GEn_DUB == 325.532, "GEn_DUB = 325.532");
+ TestBase.Expect( ConstantsDemoConstants.GEn_DU == 85.2355, "GEn_DU = 85.2355");
+ TestBase.Expect( ConstantsDemoConstants.GEN_STRING == "asldkjasfd", "GEN_STRING = \"asldkjasfd\"");
+ TestBase.Expect( ConstantsDemoConstants.e10 == 1e+10, "e10 = 1e+10");
+ TestBase.Expect( ConstantsDemoConstants.e11 == -1e+10, "e11 = -1e+10");
+ TestBase.Expect( ConstantsDemoConstants.GEN_UUID == "00000000-4444-CCCC-ffff-0123456789ab", "GEN_UUID = \"00000000-4444-CCCC-ffff-0123456789ab\"");
+
+ TestBase.Expect( ConstantsDemoConstants.GEN_MAP.get(35532) == 233, "GEN_MAP.get(35532) == 233");
+ TestBase.Expect( ConstantsDemoConstants.GEN_MAP.get(43523) == 853, "GEN_MAP.get(43523) == 853");
+
+ TestBase.Expect( ConstantsDemoConstants.GEN_LIST.length == 3, "GEN_LIST.size() == 3");
+ TestBase.Expect( ConstantsDemoConstants.GEN_LIST.join("/") == "235235/23598352/3253523", "GEN_LIST elements");
+
+ TestBase.Expect( ConstantsDemoConstants.GEN_MAPMAP.get(235).get(532) == 53255, "GEN_MAPMAP.get(235).get(532) == 53255");
+ TestBase.Expect( ConstantsDemoConstants.GEN_MAPMAP.get(235).get(235) == 235, "GEN_MAPMAP.get(235).get(235) == 235");
+
+ TestBase.Expect( ConstantsDemoConstants.GEN_MAP2.get("hello") == 233, "GEN_MAP2.get(\"hello\") == 233");
+ TestBase.Expect( ConstantsDemoConstants.GEN_MAP2.get("lkj98d") == 853, "GEN_MAP2.get(\"lkj98d\") == 853");
+ TestBase.Expect( ConstantsDemoConstants.GEN_MAP2.get('lkjsdf') == 98325, "GEN_MAP2.get('lkjsdf') == 98325");
+
+ TestBase.Expect( ConstantsDemoConstants.GEN_THING.hello == 325, "GEN_THING.hello == 325");
+ TestBase.Expect( ConstantsDemoConstants.GEN_THING.goodbye == 325352, "GEN_THING.goodbye == 325352");
+
+ TestBase.Expect( ConstantsDemoConstants.GEN_WHAT.get(35).hello == 325, "GEN_WHAT.get(35).hello == 325");
+ TestBase.Expect( ConstantsDemoConstants.GEN_WHAT.get(35).goodbye == 325352, "GEN_WHAT.get(35).goodbye == 325352");
+
+ TestBase.Expect( ConstantsDemoConstants.GEN_SET.size == 2, "GEN_SET.size() == 2");
+ TestBase.Expect( ConstantsDemoConstants.GEN_SET.contains(235), "GEN_SET.contains(235)"); // added twice, but this is a set
+ TestBase.Expect( ConstantsDemoConstants.GEN_SET.contains(53235), "GEN_SET.contains(53235)");
+ }
+
+}
+
+
diff --git a/lib/haxe/test/src/Main.hx b/lib/haxe/test/src/Main.hx
index 6c262d78f..e04af78b0 100644
--- a/lib/haxe/test/src/Main.hx
+++ b/lib/haxe/test/src/Main.hx
@@ -31,6 +31,7 @@ import thrift.test.*; // generated code
enum WhatTests {
Normal;
Multiplex;
+ Constants;
}
class Main
@@ -56,6 +57,8 @@ class Main
server = true;
case "multiplex" :
tests = Multiplex;
+ case "constants" :
+ tests = Constants;
default:
throw 'Invalid argument "$arg"\n'+CMDLINEHELP;
}
@@ -76,6 +79,8 @@ class Main
StreamTest.Run(server);
case Multiplex:
MultiplexTest.Run(server);
+ case Constants:
+ ConstantsTest.Run(server);
default:
throw "Unhandled test mode $tests";
}
diff --git a/lib/haxe/test/src/MultiplexTest.hx b/lib/haxe/test/src/MultiplexTest.hx
index 3e2786db5..74fa357fe 100644
--- a/lib/haxe/test/src/MultiplexTest.hx
+++ b/lib/haxe/test/src/MultiplexTest.hx
@@ -48,7 +48,7 @@ class BenchmarkServiceHandler implements BenchmarkService_service
public function new() {
}
- public function fibonacci(n : haxe.Int32) : haxe.Int32 {
+ public function fibonacci(n : haxe.Int32) : haxe.Int32 {
trace('Benchmark.fibonacci($n)');
var next : Int;
var prev = 0;
@@ -60,7 +60,7 @@ class BenchmarkServiceHandler implements BenchmarkService_service
result = next;
--n;
}
- return result;
+ return result;
}
}
diff --git a/lib/haxe/test/src/StreamTest.hx b/lib/haxe/test/src/StreamTest.hx
index 9b8706a57..4744272a5 100644
--- a/lib/haxe/test/src/StreamTest.hx
+++ b/lib/haxe/test/src/StreamTest.hx
@@ -48,7 +48,7 @@ class StreamTest extends TestBase {
public static function WriteData() : Xtruct
{
- var config : TConfiguration = new TConfiguration();
+ var config : TConfiguration = new TConfiguration();
var stream : TStream = new TFileStream( tmpfile, CreateNew);
var trans : TTransport = new TStreamTransport( null, stream, config);
var prot = new TJSONProtocol( trans);
@@ -62,7 +62,7 @@ class StreamTest extends TestBase {
public static function ReadData() : Xtruct
{
- var config : TConfiguration = new TConfiguration();
+ var config : TConfiguration = new TConfiguration();
var stream : TStream = new TFileStream( tmpfile, Read);
var trans : TTransport = new TStreamTransport( stream, null, config);
var prot = new TJSONProtocol( trans);
diff --git a/lib/haxe/test/src/TestBase.hx b/lib/haxe/test/src/TestBase.hx
index 12327737a..865a801a9 100644
--- a/lib/haxe/test/src/TestBase.hx
+++ b/lib/haxe/test/src/TestBase.hx
@@ -40,6 +40,7 @@ class TestBase {
if( ! expr) {
throw ('Test "$info" failed at '+pos.methodName+' in '+pos.fileName+':'+pos.lineNumber);
}
+ trace('Test "$info" - OK');
}
}
diff --git a/test/ConstantsDemo.thrift b/test/ConstantsDemo.thrift
index a54534d51..204e805b1 100644
--- a/test/ConstantsDemo.thrift
+++ b/test/ConstantsDemo.thrift
@@ -19,6 +19,7 @@
namespace cpp yozone
namespace erl consts_
+namespace haxe constantsDemo
struct thing {
1: i32 hello,