Permalink
Browse files

builtin module Test.More

  • Loading branch information...
1 parent 622f3db commit 1f0df6622d0b60ff493b8dd5af59c1505d4179da @NotFound committed Jun 3, 2012
Showing with 248 additions and 2 deletions.
  1. +9 −2 Makefile
  2. +31 −0 t/base/00test.t
  3. +3 −0 t/base/features.t
  4. +30 −0 winxedxx.winxed
  5. +147 −0 winxedxx_builtin_test_more.cxx
  6. +28 −0 winxedxx_builtin_test_more.h
View
@@ -25,6 +25,7 @@ OBJS = \
winxedxx_nci.o \
winxedxx_ptr.o \
winxedxx_bytebuffer.o \
+ winxedxx_builtin_test_more.o \
winxedxx_util.o
LIB = winxedxx.so
@@ -90,6 +91,9 @@ winxedxx_nci.o: winxedxx_nci.cxx winxedxx.h
winxedxx_util.o: winxedxx_util.cxx winxedxx_types.h winxedxx_object.h winxedxx_default.h winxedxx_integer.h winxedxx_handle.h
$(CXX) $(CXXOPTS) -c winxedxx_util.cxx
+winxedxx_builtin_test_more.o: winxedxx_builtin_test_more.cxx winxedxx_types.h winxedxx_object.h winxedxx_default.h winxedxx_integer.h winxedxx_handle.h
+ $(CXX) $(CXXOPTS) -c winxedxx_builtin_test_more.cxx
+
#-----------------------------------------------------------------------
winxedxc.pir: winxedxc.winxed winxedxx.winxhead
@@ -101,12 +105,12 @@ winxedxc.pbc: winxedxc.pir
#-----------------------------------------------------------------------
test: winxedxx.pbc $(FRONTEND) winxedxx.h $(LIB)
- prove -v -e "$(WINXED) t/runtests.winxed" t/base/features.t
+ prove -v -e "$(WINXED) t/runtests.winxed" t/base/00test.t t/base/features.t
#-----------------------------------------------------------------------
exetest: t/runtests
- prove -v -e t/runtests t/base/features.t
+ prove -v -e t/runtests t/base/00test.t t/base/features.t
t/runtests: winxedxx.pbc $(FRONTEND) winxedxx.h $(LIB) t/runtests.winxed
$(PARROT) $(FRONTEND) --target=exe -o t/runtests t/runtests.winxed
@@ -127,6 +131,9 @@ clean:
t/runtests \
t/runtests.o \
t/runtests.cxx \
+ t/base/00test \
+ t/base/00test.o \
+ t/base/00test.cxx \
t/base/features \
t/base/features.o \
t/base/features.cxx
View
@@ -0,0 +1,31 @@
+#! winxed
+
+// winxedxx base tests
+// Verify the builtin module Test.More
+
+using extern Test.More plan, ok, nok, is, isnt;
+
+function main [main] (var args)
+{
+ plan(10);
+
+ ok(1, "ok is ok");
+ nok(0, "nok is ok");
+
+ is(1, 1, "is is ok");
+ isnt(1, 0, "isnt is ok");
+
+ float n = 1.1;
+ is(n, 1.1, "is with float");
+ isnt(n, 1, "isnt with float - int");
+
+ string s = "hello";
+ string hi = "he";
+ is(s, "hello", "is with string - string literal");
+ isnt(s, "other", "isnt with string - string literal");
+ isnt(s, hi, "isnt with string - string");
+ hi = hi + "llo";
+ is(s, hi, "is with string - string");
+}
+
+// End
View
@@ -222,6 +222,9 @@ function bar()
return "Foo.bar";
}
+// This is to avoid a C++ compiler warning.
+class Unused { }
+
} // namespace Foo
function bar()
View
@@ -2243,6 +2243,7 @@ function get_main(ns)
#include "winxedxx.h"
#include "winxedxx_namespace.h"
+#include "winxedxx_builtin_test_more.h"
namespace WinxedXX
{
@@ -2325,6 +2326,8 @@ INITIALIZER:>>
self.emit_initialize_namespace(rootns, "rootns");
self.emit_initialize_child_namespaces(rootns, "rootns");
+ self.emit_initialize_modules(rootns);
+
self.print(<<:INITIALIZEREND
return 1;
}
@@ -2381,6 +2384,33 @@ INITIALIZEREND:>>
self.print("// End\n");
}
+ function emit_initialize_modules(var ns)
+ {
+ var loads = ns.loads;
+ for (string module in loads)
+ self.emit_load_module(module);
+
+ }
+ function emit_load_module(string modulename)
+ {
+ // Harcoded for a now, don't even check functions to import
+ if (modulename = "Test/More.pbc") {
+ self.print(" // Initialize builtin module ", modulename, "\n");
+ self.print(" WinxedXX::Builtin::Test::More::initialize();\n");
+ self.print(" WxxNamespace &modTestMode = rootns.childNamespace(\"Test\").childNamespace(\"More\");\n");
+ self.print(" WxxObjectPtr fun;\n");
+ for (string objname in [ "plan", "ok", "nok", "is", "isnt" ] ) {
+ objname = "\"" + objname + "\"";
+ self.print(" fun = modTestMode.get(",
+ objname, ");\n");
+ self.print(" if (fun.is_null()) fun = new WxxInteger(42);\n");
+ self.print(" rootns.set(", objname, ", fun);\n");
+ }
+ return;
+ }
+ cry("LOAD: ", modulename);
+ }
+
function print(args[slurpy])
{
var handle = self.handle;
@@ -0,0 +1,147 @@
+// winxedxx_builtin_test_more.h
+// (C) 2012 Julián Albo "NotFound"
+
+#include "winxedxx_types.h"
+#include "winxedxx_object.h"
+#include "winxedxx_default.h"
+#include "winxedxx_integer.h"
+#include "winxedxx_namespace.h"
+
+#include <iostream>
+
+namespace WinxedXX
+{
+
+namespace Builtin
+{
+
+namespace Test
+{
+
+namespace More
+{
+
+static int counter;
+
+WxxObjectPtr plan(const WxxObjectArray &args)
+{
+ counter = 0;
+ int numtests = args.get_pmc_keyed(0).get_integer();
+ std::cout << "1.." << numtests << "\n";
+ return winxedxxnull;
+}
+
+static int numNewTest()
+{
+ return ++counter;
+}
+
+WxxObjectPtr ok(const WxxObjectArray &args)
+{
+ int numargs = args.elements();
+ int value = args.get_pmc_keyed(0).get_integer();
+ if (! value)
+ std::cout << "n";
+ std::cout << "ok " << numNewTest();
+ if (numargs > 1)
+ std::cout << " - " << args.get_pmc_keyed(1).get_string();
+ std::cout << "\n";
+
+ return winxedxxnull;
+}
+
+WxxObjectPtr nok(const WxxObjectArray &args)
+{
+ int numargs = args.elements();
+ int value = args.get_pmc_keyed(0).get_integer();
+ if (value)
+ std::cout << "n";
+ std::cout << "ok " << numNewTest();
+ if (numargs > 1)
+ std::cout << " - " << args.get_pmc_keyed(1).get_string();
+ std::cout << "\n";
+
+ return winxedxxnull;
+}
+
+static bool args_equal(WxxObjectPtr &value, WxxObjectPtr &expected)
+{
+ bool result;
+ // Poor man's "multi" dispatch
+ bool is_integer =
+ value.instanceof("Integer") && expected.instanceof("Integer");
+ bool is_number = is_integer || (
+ (value.instanceof("Float") || value.instanceof("Integer")) &&
+ (expected.instanceof("Float") ||expected.instanceof("Integer") ));
+ bool is_string = (! is_number) &&
+ (value.instanceof("String") && expected.instanceof("String"));
+ if (is_integer)
+ result = value.get_integer() == expected.get_integer();
+ else if (is_number)
+ result = value.get_number() == expected.get_number();
+ else if (is_string)
+ result = value.get_string() == expected.get_string();
+ else
+ result = value.is_equal(expected);
+ return result;
+}
+
+WxxObjectPtr is(const WxxObjectArray &args)
+{
+ int numargs = args.elements();
+ WxxObjectPtr value = args.get_pmc_keyed(0);
+ WxxObjectPtr expected = args.get_pmc_keyed(1);
+ std::string msg = numargs > 2 ? args.get_pmc_keyed(2).get_string() : "";
+
+ bool result = args_equal(value, expected);
+
+ if (! result)
+ std::cout << "n";
+ std::cout << "ok " << numNewTest();
+ if (msg != "")
+ std::cout << " - " << msg;
+ std::cout << "\n";
+
+ return winxedxxnull;
+}
+
+WxxObjectPtr isnt(const WxxObjectArray &args)
+{
+ int numargs = args.elements();
+ WxxObjectPtr value = args.get_pmc_keyed(0);
+ WxxObjectPtr expected = args.get_pmc_keyed(1);
+ std::string msg = numargs > 2 ? args.get_pmc_keyed(2).get_string() : "";
+
+ bool result = args_equal(value, expected);
+
+ if (result)
+ std::cout << "n";
+ std::cout << "ok " << numNewTest();
+ if (msg != "")
+ std::cout << " - " << msg;
+ std::cout << "\n";
+
+ return winxedxxnull;
+}
+
+//******************************************************
+
+void initialize()
+{
+ counter = 0;
+ WxxNamespace &ns = getRootNamespace().
+ childNamespace("Test").childNamespace("More");
+ ns.set("plan", new WxxSub(&plan));
+ ns.set("ok", new WxxSub(&ok));
+ ns.set("nok", new WxxSub(&nok));
+ ns.set("is", new WxxSub(&is));
+ ns.set("isnt", new WxxSub(&isnt));
+}
+
+} // namespace Test
+} // namespace More
+} // namespace Builtin
+} // namespace WinxedXX
+
+
+// End of winxedxx_builtin_test_more.h
@@ -0,0 +1,28 @@
+#ifndef INCLUDE_WINXEDXX_BUILTIN_TEST_MORE_H
+#define INCLUDE_WINXEDXX_BUILTIN_TEST_MORE_H
+
+// winxedxx_builtin_test_more.h
+// (C) 2012 Julián Albo "NotFound"
+
+namespace WinxedXX
+{
+
+namespace Builtin
+{
+
+namespace Test
+{
+
+namespace More
+{
+
+void initialize();
+
+} // namespace Test
+} // namespace More
+} // namespace Builtin
+} // namespace WinxedXX
+
+#endif
+
+// End of winxedxx_builtin_test_more.h

0 comments on commit 1f0df66

Please sign in to comment.