Permalink
Browse files

Packfile: helper function to add oplibs

  • Loading branch information...
1 parent e062fa1 commit 1e2beb978d4559caf3cfeb628b4c067a5ba9efaf @Benabik Benabik committed Jul 27, 2012
Showing with 32 additions and 0 deletions.
  1. +11 −0 src/PACT/Packfile.winxed
  2. +21 −0 t/01-packfile/01-packfile.t
View
@@ -39,6 +39,17 @@ class PACT.Packfile {
self.uuid = uuid;
}
+ function add_oplib(var name) {
+ if (exists self.oplibs[name])
+ return;
+
+ var oplib = new 'OpLib'(name);
+ if (oplib == null)
+ die("Couldn't get oplib '"+name+"'");
+
+ self.oplibs[name] = oplib;
+ }
+
function __dump(var dumper, string label) {
:(string indent, string subindent) = dumper.newIndent();
say('{');
@@ -39,6 +39,27 @@ class PackfileTest {
assert.equal(1, pf.uuid_type);
assert.equal(md5, pf.uuid);
}
+
+ // Test that core_ops is loaded by default
+ function test_oplibs_core() {
+ var assert = self.assert;
+ :PACT.Packfile pf();
+ assert.exists_keyed_str(pf.oplibs, 'core_ops');
+ assert.instance_of(pf.oplibs['core_ops'], 'OpLib');
+ }
+
+ function test_oplibs_math() {
+ var assert = self.assert;
+ string math = 'math_ops';
+ loadlib(math);
+ :PACT.Packfile pf();
+ assert.not_exists_keyed_str(pf.oplibs, math);
+ assert.throws_nothing(function () {
+ pf.add_oplib(math);
+ });
+ assert.exists_keyed_str(pf.oplibs, math);
+ assert.instance_of(pf.oplibs[math], 'OpLib');
+ }
}
# vim: ft=winxed

0 comments on commit 1e2beb9

Please sign in to comment.