Index: test/snippets.js
===================================================================
--- a/test/snippets.js
+++ b/test/snippets.js
@@ -185,8 +185,71 @@
   checkParsedScript("Script containing Unicode composite characters",
                     "f\ud83d\ude42\ud83d\ude42 b\ud83d\ude02r",
                     [["f\ud83d\ude42\ud83d\ude42", "b\ud83d\ude02r"]]);
   checkParsedScript("Script with no-op commands", "foo; ;;; ;  ; bar 1",
                     [["foo"], ["bar", "1"]]);
 
   test.done();
 };
+
+exports.testScriptCompilation = function(test)
+{
+  let {compileScript, parseScript} = Snippets;
+
+  let library1 = function(exports)
+  {
+    exports.hello = function(message)
+    {
+      console.log(message);
+    };
+  };
+
+  let library2 = function(exports)
+  {
+    exports.hello = function(message)
+    {
+      console.log(message || "Hello.");
+    };
+  };
+
+  let libraries = [library1.toString(), library2.toString()];
+  let stringifiedLibraries = JSON.stringify(libraries);
+
+  let template = `
+      "use strict";
+      {
+        const libraries = {{{libraries}}};
+
+        const script = {{{script}}};
+
+        let imports = Object.create(null);
+        for (let library of libraries)
+          new Function("exports", library)(imports);
+
+        for (let [name, ...args] of script)
+        {
+          if (Object.prototype.hasOwnProperty.call(imports, name))
+          {
+            let value = imports[name];
+            if (typeof value == "function")
+              value(...args);
+          }
+        }
+      }
+  `;
+
+  function verifyExecutable(script)
+  {
+    let parsedScript = parseScript(script);
+
+    let actual = compileScript(script, libraries);
+    let expected = template.replace("{{{libraries}}}", stringifiedLibraries)
+                   .replace("{{{script}}}", JSON.stringify(parsedScript));
+
+    // Trim surrounding spaces because of possible difference in indentation.
+    test.equal(expected.trim(), actual.trim());
+  }
+
+  verifyExecutable("hello 'How are you?'");
+
+  test.done();
+};
