mirror of https://github.com/swig/swig
add more JS run tests
This commit is contained in:
parent
1c85c0c135
commit
3baa5c090f
|
@ -3,6 +3,11 @@
|
|||
#include <iostream>
|
||||
%}
|
||||
|
||||
#if defined(SWIG_JAVASCRIPT_V8)
|
||||
%rename(addTo) operator +=;
|
||||
%rename(subFrom) operator -=;
|
||||
%rename(mulTo) operator *=;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
struct A
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
if ($1) {
|
||||
$result = SWIG_From(int)(*$1);
|
||||
} else {
|
||||
$result = SWIG_Py_Void();
|
||||
$result = VOID_Object;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
|||
if ($1) {
|
||||
$result = SWIG_From(std::string)(*$1);
|
||||
} else {
|
||||
$result = SWIG_Py_Void();
|
||||
$result = VOID_Object;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
var default_arg_values = require("default_arg_values");
|
||||
|
||||
var d = new default_arg_values.Display();
|
||||
|
||||
if (d.draw1() != 0) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (d.draw1(12) != 12) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
p = default_arg_values.createPtr(123);
|
||||
if (d.draw2() != 0) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (d.draw2(p) != 123) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (d.bool0() != false || typeof d.bool0() != typeof false) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (d.bool1() != true || typeof d.bool1() != typeof true) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (d.mybool0() != false || typeof d.mybool0() != typeof false) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (d.mybool1() != true || typeof d.mybool1() != typeof false) {
|
||||
throw new Error;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
var enums = require("enums");
|
||||
|
||||
enums.bar2(1);
|
||||
enums.bar3(1);
|
||||
enums.bar1(1);
|
||||
|
||||
if (enums.enumInstance != 2) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (enums.Slap != 10) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (enums.Mine != 11) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (enums.Thigh != 12) {
|
||||
throw new Error;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
var exception_classname = require("exception_classname");
|
||||
|
||||
a = new exception_classname.Exception();
|
||||
if (a.testfunc() != 42) {
|
||||
throw new Error("Not 42!");
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
var extend_placement = require("extend_placement");
|
||||
|
||||
foo = new extend_placement.Foo();
|
||||
foo = new extend_placement.Foo(1);
|
||||
foo = new extend_placement.Foo(1, 1);
|
||||
foo.spam();
|
||||
foo.spam("hello");
|
||||
foo.spam(1);
|
||||
foo.spam(1, 1);
|
||||
foo.spam(1, 1, 1);
|
||||
foo.spam(new extend_placement.Foo());
|
||||
foo.spam(new extend_placement.Foo(), 1.0);
|
||||
|
||||
|
||||
bar = new extend_placement.Bar();
|
||||
bar = new extend_placement.Bar(1);
|
||||
bar.spam();
|
||||
bar.spam("hello");
|
||||
bar.spam(1);
|
||||
bar.spam(1, 1);
|
||||
bar.spam(1, 1, 1);
|
||||
bar.spam(new extend_placement.Bar());
|
||||
bar.spam(new extend_placement.Bar(), 1.0);
|
||||
|
||||
|
||||
foo = new extend_placement.FooTi();
|
||||
foo = new extend_placement.FooTi(1);
|
||||
foo = new extend_placement.FooTi(1, 1);
|
||||
foo.spam();
|
||||
foo.spam("hello");
|
||||
foo.spam(1);
|
||||
foo.spam(1, 1);
|
||||
foo.spam(1, 1, 1);
|
||||
foo.spam(new extend_placement.Foo());
|
||||
foo.spam(new extend_placement.Foo(), 1.0);
|
||||
|
||||
|
||||
bar = new extend_placement.BarTi();
|
||||
bar = new extend_placement.BarTi(1);
|
||||
bar.spam();
|
||||
bar.spam("hello");
|
||||
bar.spam(1);
|
||||
bar.spam(1, 1);
|
||||
bar.spam(1, 1, 1);
|
||||
bar.spam(new extend_placement.Bar());
|
||||
bar.spam(new extend_placement.Bar(), 1.0);
|
|
@ -0,0 +1,54 @@
|
|||
var extend_template_method = require("extend_template_method");
|
||||
|
||||
em = new extend_template_method.ExtendMe();
|
||||
|
||||
ret_double = em.do_stuff_double(1, 1.1);
|
||||
if (ret_double != 1.1) {
|
||||
throw new Error("double failed " + ret_double);
|
||||
}
|
||||
ret_string = em.do_stuff_string(1, "hello there");
|
||||
if (ret_string != "hello there") {
|
||||
throw new Error("string failed " + ret_string);
|
||||
}
|
||||
|
||||
ret_double = em.do_overloaded_stuff(1.1);
|
||||
if (ret_double != 1.1) {
|
||||
throw new Error("double failed " + ret_double);
|
||||
}
|
||||
ret_string = em.do_overloaded_stuff("hello there");
|
||||
if (ret_string != "hello there") {
|
||||
throw new Error("string failed " + ret_string);
|
||||
}
|
||||
|
||||
if (extend_template_method.ExtendMe.static_method(123) != 123) {
|
||||
throw new Error("static_method failed");
|
||||
}
|
||||
|
||||
em2 = new extend_template_method.ExtendMe(123);
|
||||
|
||||
em = new extend_template_method.TemplateExtend();
|
||||
|
||||
ret_double = em.do_template_stuff_double(1, 1.1);
|
||||
if (ret_double != 1.1) {
|
||||
throw new Error("double failed " + ret_double);
|
||||
}
|
||||
ret_string = em.do_template_stuff_string(1, "hello there");
|
||||
if (ret_string != "hello there") {
|
||||
throw new Error("string failed " + ret_string);
|
||||
}
|
||||
|
||||
|
||||
ret_double = em.do_template_overloaded_stuff(1.1);
|
||||
if (ret_double != 1.1) {
|
||||
throw new Error("double failed " + ret_double);
|
||||
}
|
||||
ret_string = em.do_template_overloaded_stuff("hello there");
|
||||
if (ret_string != "hello there") {
|
||||
throw new Error("string failed " + ret_string);
|
||||
}
|
||||
|
||||
if (extend_template_method.TemplateExtend.static_template_method(123) != 123) {
|
||||
throw new Error("static_template_method failed");
|
||||
}
|
||||
|
||||
em2 = new extend_template_method.TemplateExtend(123);
|
|
@ -0,0 +1,9 @@
|
|||
var extend_template_ns = require("extend_template_ns");
|
||||
f = new extend_template_ns.Foo_One();
|
||||
if (f.test1(37) != 37) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (f.test2(42) != 42) {
|
||||
throw new Error;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
var extend_template = require("extend_template");
|
||||
|
||||
f = new extend_template.Foo_0();
|
||||
if (f.test1(37) != 37) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (f.test2(42) != 42) {
|
||||
throw new Error;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
var extend_variable = require("extend_variable");
|
||||
|
||||
if (extend_variable.Foo.Bar != 42) {
|
||||
throw new Error;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
var extern_c = require("extern_c");
|
||||
|
||||
function check(flag) {
|
||||
if (!flag) {
|
||||
throw new Error("Test failed");
|
||||
}
|
||||
}
|
||||
|
||||
extern_c.RealFunction(2);
|
||||
check(extern_c.int2 == 123);
|
||||
check(extern_c.int3 == 456);
|
||||
check(extern_c.int4 == 789);
|
|
@ -0,0 +1,7 @@
|
|||
var final_c = require("final_c");
|
||||
|
||||
final_c.init();
|
||||
f = final_c.final;
|
||||
if ((f.yval != 123)) {
|
||||
throw new Error("f.yval fail");
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
var friends = require("friends");
|
||||
|
||||
a = new friends.A(2);
|
||||
|
||||
if (friends.get_val1(a) != 2) {
|
||||
throw new Error;
|
||||
}
|
||||
if (friends.get_val2(a) != 4) {
|
||||
throw new Error;
|
||||
}
|
||||
if (friends.get_val3(a) != 6) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
// nice overload working fine
|
||||
if (friends.get_val1(1, 2, 3) != 1) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
b = new friends.B(3);
|
||||
|
||||
// David's case
|
||||
if (friends.mix(a, b) != 5) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
di = new friends.D_i(2);
|
||||
dd = new friends.D_d(3.3);
|
||||
|
||||
// incredible template overloading working just fine
|
||||
if (friends.get_val1(di) != 2) {
|
||||
throw new Error;
|
||||
}
|
||||
if (friends.get_val1(dd) != 3.3) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
friends.set(di, 4);
|
||||
friends.set(dd, 1.3);
|
||||
|
||||
if (friends.get_val1(di) != 4) {
|
||||
throw new Error;
|
||||
}
|
||||
if (friends.get_val1(dd) != 1.3) {
|
||||
throw new Error;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
var funcptr_cpp = require("funcptr_cpp");
|
||||
|
||||
if (funcptr_cpp.call1(funcptr_cpp.ADD_BY_VALUE, 10, 11) != 21) {
|
||||
throw new Error;
|
||||
}
|
||||
if (funcptr_cpp.call2(funcptr_cpp.ADD_BY_POINTER, 12, 13) != 25) {
|
||||
throw new Error;
|
||||
}
|
||||
if (funcptr_cpp.call3(funcptr_cpp.ADD_BY_REFERENCE, 14, 15) != 29) {
|
||||
throw new Error;
|
||||
}
|
||||
if (funcptr_cpp.call1(funcptr_cpp.ADD_BY_VALUE_C, 2, 3) != 5) {
|
||||
throw new Error;
|
||||
}
|
||||
if (funcptr_cpp.callconst1(funcptr_cpp.ADD_BY_VALUE_C, 2, 3) != 5) {
|
||||
throw new Error;
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
var global_functions = require("global_functions");
|
||||
|
||||
|
||||
function check(a, b) {
|
||||
if (a != b) {
|
||||
throw new Error("Failed: " + str(a) + " != " + str(b));
|
||||
}
|
||||
}
|
||||
global_functions.global_void();
|
||||
check(global_functions.global_one(1), 1);
|
||||
check(global_functions.global_two(2, 2), 4);
|
||||
|
||||
fail = true;
|
||||
try {
|
||||
global_functions.global_void(1);
|
||||
} catch (e) {
|
||||
if (e instanceof TypeError) fail = false;
|
||||
}
|
||||
fail = false;
|
||||
if (fail) {
|
||||
throw new Error("argument count check failed");
|
||||
}
|
||||
|
||||
fail = true;
|
||||
try {
|
||||
global_functions.global_one();
|
||||
} catch (e) {
|
||||
if (e instanceof TypeError) fail = false;
|
||||
}
|
||||
fail = false;
|
||||
if (fail) {
|
||||
throw new Error("argument count check failed");
|
||||
}
|
||||
|
||||
fail = true;
|
||||
try {
|
||||
global_functions.global_one(2, 2);
|
||||
} catch (e) {
|
||||
if (e instanceof TypeError) fail = false;
|
||||
}
|
||||
fail = false;
|
||||
|
||||
if (fail) {
|
||||
throw new Error("argument count check failed");
|
||||
}
|
||||
|
||||
fail = true;
|
||||
try {
|
||||
global_functions.global_two(1);
|
||||
} catch (e) {
|
||||
if (e instanceof TypeError) fail = false;
|
||||
}
|
||||
fail = false;
|
||||
|
||||
if (fail) {
|
||||
throw new Error("argument count check failed");
|
||||
}
|
||||
|
||||
fail = true;
|
||||
try {
|
||||
global_functions.global_two(3, 3, 3);
|
||||
} catch (e) {
|
||||
if (e instanceof TypeError) fail = false;
|
||||
}
|
||||
fail = false;
|
||||
|
||||
if (fail) {
|
||||
throw new Error("argument count check failed");
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
var global_namespace = require("global_namespace");
|
||||
|
||||
|
||||
k1 = new global_namespace.Klass1();
|
||||
k2 = new global_namespace.Klass2();
|
||||
k3 = new global_namespace.Klass3();
|
||||
k4 = new global_namespace.Klass4();
|
||||
k5 = new global_namespace.Klass5();
|
||||
k6 = new global_namespace.Klass6();
|
||||
k7 = new global_namespace.Klass7();
|
||||
|
||||
global_namespace.KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7);
|
||||
global_namespace.KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7);
|
||||
|
||||
k1 = global_namespace.getKlass1A();
|
||||
k2 = global_namespace.getKlass2A();
|
||||
k3 = global_namespace.getKlass3A();
|
||||
k4 = global_namespace.getKlass4A();
|
||||
k5 = global_namespace.getKlass5A();
|
||||
k6 = global_namespace.getKlass6A();
|
||||
k7 = global_namespace.getKlass7A();
|
||||
|
||||
global_namespace.KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7);
|
||||
global_namespace.KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7);
|
||||
|
||||
k1 = global_namespace.getKlass1B();
|
||||
k2 = global_namespace.getKlass2B();
|
||||
k3 = global_namespace.getKlass3B();
|
||||
k4 = global_namespace.getKlass4B();
|
||||
k5 = global_namespace.getKlass5B();
|
||||
k6 = global_namespace.getKlass6B();
|
||||
k7 = global_namespace.getKlass7B();
|
||||
|
||||
global_namespace.KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7);
|
||||
global_namespace.KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7);
|
||||
|
||||
global_namespace.XYZMethods.methodA(new global_namespace.XYZ1(), new global_namespace.XYZ2(), new global_namespace.XYZ3(), new global_namespace.XYZ4(), new global_namespace.XYZ5(), new global_namespace.XYZ6(), new global_namespace.XYZ7());
|
||||
global_namespace.XYZMethods.methodB(new global_namespace.XYZ1(), new global_namespace.XYZ2(), new global_namespace.XYZ3(), new global_namespace.XYZ4(), new global_namespace.XYZ5(), new global_namespace.XYZ6(), new global_namespace.XYZ7());
|
||||
|
||||
global_namespace.TheEnumMethods.methodA(global_namespace.theenum1, global_namespace.theenum2, global_namespace.theenum3);
|
||||
global_namespace.TheEnumMethods.methodA(global_namespace.theenum1, global_namespace.theenum2, global_namespace.theenum3);
|
|
@ -0,0 +1,4 @@
|
|||
var global_ns_arg = require("global_ns_arg");
|
||||
|
||||
a = global_ns_arg.foo(1);
|
||||
b = global_ns_arg.bar_fn();
|
|
@ -0,0 +1,25 @@
|
|||
var global_vars = require("global_vars");
|
||||
|
||||
// In javascript, assigning to a non-existent variable is
|
||||
// not an error
|
||||
|
||||
global_vars.init();
|
||||
b = global_vars.b;
|
||||
if (b != "string b") {
|
||||
throw new Error("Unexpected string: " + b.toString());
|
||||
}
|
||||
global_vars.b = "a string value";
|
||||
b = global_vars.b;
|
||||
if (b != "a string value") {
|
||||
throw new Error("Unexpected string: " + b.toString());
|
||||
}
|
||||
|
||||
x = global_vars.x;
|
||||
if (x != 1234) {
|
||||
throw new Error("Unexpected x: " + x.toString());
|
||||
}
|
||||
global_vars.x = 9876;
|
||||
x = global_vars.x;
|
||||
if (x != 9876) {
|
||||
throw new Error("Unexpected string: " + x.toString());
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
var import_nomodule = require("import_nomodule");
|
||||
|
||||
f = import_nomodule.create_Foo();
|
||||
import_nomodule.test1(f, 42);
|
||||
import_nomodule.delete_Foo(f);
|
||||
|
||||
b = new import_nomodule.Bar();
|
||||
import_nomodule.test1(b, 37);
|
|
@ -0,0 +1,22 @@
|
|||
var inctest = require("inctest");
|
||||
|
||||
try {
|
||||
a = new inctest.A();
|
||||
} catch (e) {
|
||||
throw new Error("didn't find A, therefore, I didn't include 'testdir/subdir1/hello.i'");
|
||||
}
|
||||
|
||||
try {
|
||||
b = new inctest.B();
|
||||
} catch (e) {
|
||||
throw new Error("didn't find B, therefore, I didn't include 'testdir/subdir2/hello.i'");
|
||||
}
|
||||
|
||||
// Check the var in subdirectory worked = require("in subdirectory worked")
|
||||
if (inctest.importtest1(5) != 15) {
|
||||
throw new Error("var test 1 failed");
|
||||
}
|
||||
|
||||
if (inctest.importtest2("black") != "white") {
|
||||
throw new Error("var test 2 failed");
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
var inplaceadd = require("inplaceadd");
|
||||
a = new inplaceadd.A(7);
|
||||
|
||||
a.addTo(5);
|
||||
if (a.val != 12) {
|
||||
throw new Error(`a.val: ${a.val}`);
|
||||
}
|
||||
|
||||
a.subFrom(5);
|
||||
if (a.val != 7) {
|
||||
throw new Error(`a.val: ${a.val}`);
|
||||
}
|
||||
|
||||
a.mulTo(2);
|
||||
|
||||
if (a.val != 14) {
|
||||
throw new Error(`a.val: ${a.val}`);
|
||||
}
|
||||
|
||||
a.addTo(a);
|
||||
if (a.val != 28) {
|
||||
throw new Error(`a.val: ${a.val}`);
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
var input = require("input");
|
||||
|
||||
f = new input.Foo();
|
||||
if (f.foo(2) != 4) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (f.foo(null) != null) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (f.foo() != null) {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (input.sfoo("Hello") != "Hello world") {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
if (input.sfoo() != null) {
|
||||
throw new Error;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
var keyword_rename_c = require("keyword_rename_c");
|
||||
keyword_rename_c._instanceof(1);
|
||||
keyword_rename_c._typeof(1);
|
|
@ -0,0 +1,3 @@
|
|||
var keyword_rename = require("keyword_rename")
|
||||
keyword_rename._instanceof(1)
|
||||
keyword_rename._typeof(1)
|
|
@ -37,6 +37,9 @@ KW(chan, fallthrough)
|
|||
KW(end, function)
|
||||
KW(nil,local)
|
||||
|
||||
/* Javascript keywords */
|
||||
KW(instanceof, typeof)
|
||||
KW(typeof, instanceof)
|
||||
%}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue