Skip to content

Commit

Permalink
Merge pull request #1662 from davidpcaldwell/davidpcaldwell/issue/#1657
Browse files Browse the repository at this point in the history
#1657: Migrate loader/jrunscript tests JSAPI -> Fifty
  • Loading branch information
davidpcaldwell authored Sep 10, 2024
2 parents 0f9d99f + ec21b6f commit a3265e3
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 79 deletions.
74 changes: 0 additions & 74 deletions loader/jrunscript/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ <h2>Embedding</h2>
-->
</div>
<div>
<script type="application/x.jsapi#initialize">
scope.module = jsh.unit.$slime;
</script>
<h1>Properties</h1>
<p>
The embedding for either engine creates an object which consists of the <a href="../api.html">SLIME runtime</a>
Expand Down Expand Up @@ -429,77 +426,6 @@ <h1>Properties</h1>
<span class="type">SLIME <a href="#types.Loader">Loader</a></span>
</span>
</div>
<script type="application/x.jsapi#initialize">
scope.loadTestModule = function(path,context) {
return $jsapi.loader.module("../" + path, context);
}
</script>
<script type="application/x.jsapi#initialize">
scope.api = jsh.unit.$slime;
</script>
<script type="application/x.jsapi#tests">
// TODO: Moved from jrunscript/io, complete with if (false); what is this for?
if (false) {
var loader = new module.Loader({
resources: {
get: function(path) {
var file = $jsapi.loader.getRelativePath(path).file;
if (!file) return null;
var type = (function() {
if (/\.jsh\.js$/.test(path)) {
return new module.mime.Type("application", "x.jsh");
} else if (/\.js$/.test(path)) {
return new module.mime.Type("application", "javascript");
} else if (/\.html$/.test(path)) {
return new module.mime.Type("text", "html");
} else {
return new module.mime.Type("application", "octet-stream");
}
})();
return {
type: type,
read: {
binary: function() {
return file.read(jsh.io.Streams.binary);
}
}
};
}
}
});
var api = loader.get("api.html");
test(api.type.toString() == "text/html");

var loaderModule = loader.module("test/Loader.js");
test(loaderModule.file.foo == "bar");
test(loaderModule.resource("Loader.js") != null);
test(loaderModule.resource("test/Loader.js") == null);
test(loaderModule.grandchildResource("file.js") != null);
test(loaderModule.grandchildResource("Loader/file.js") == null);
test(loaderModule.grandchildResource("test/Loader/file.js") == null);
}
</script>
<script type="application/x.jsapi#tests">
var sources = new function() {
var code = {

};

this.get = function(path) {
return null;
};

this.Loader = function(prefix) {
this.list = function() {
return [];
}
}
}
var loader = new module.Loader(sources);
verify(loader).evaluate(function() { return this.run; }).is.not.equalTo(null);
var child = new loader.Child("prefix/");
verify(child).evaluate(function() { return this.run; }).is.not.equalTo(null);
</script>
</li>
</ul>
</div>
Expand Down
93 changes: 89 additions & 4 deletions loader/jrunscript/expression.fifty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,6 @@ namespace slime.jrunscript.runtime {
*/
mime: slime.runtime.Exports["mime"]

Loader: slime.runtime.Exports["old"]["Loader"] & {
new (p: internal.CustomSource): Loader
}

Resource: slime.runtime.Exports["Resource"] & {
new (p: old.resource.HistoricSupportedDescriptor): slime.jrunscript.runtime.old.Resource
}
Expand Down Expand Up @@ -407,6 +403,95 @@ namespace slime.jrunscript.runtime {
//@ts-ignore
)(fifty);

export interface Exports extends slime.runtime.Exports {
Loader: slime.runtime.Exports["old"]["Loader"] & {
new (p: internal.CustomSource): Loader
}
}

(
function(
fifty: slime.fifty.test.Kit
) {
const { verify } = fifty;
const { jsh } = fifty.global;

const module = test.subject;

fifty.tests.jsapi.Loader = fifty.test.Parent();

fifty.tests.jsapi.Loader._1 = function() {
const test = function(b) {
fifty.verify(b).is(true);
};

var loader = new module.Loader({
resources: {
get: function(path) {
var file = fifty.jsh.file.object.getRelativePath(path).file;
if (!file) return null;
var type = (function() {
if (/\.jsh\.js$/.test(path)) {
return module.mime.Type("application", "x.jsh");
} else if (/\.js$/.test(path)) {
return module.mime.Type("application", "javascript");
} else if (/\.html$/.test(path)) {
return module.mime.Type("text", "html");
} else {
return module.mime.Type("application", "octet-stream");
}
})();
return {
type: type,
read: {
binary: function() {
return file.read(jsh.io.Streams.binary);
}
}
};
}
}
});

var api = loader.get("api.html");
test(api.type.toString() == "text/html");

jsh.shell.console("Loading module ...");
var loaderModule = loader.module("../../jrunscript/io/test/Loader.js");
jsh.shell.console("Read module.");
test(loaderModule.file.foo == "bar");
test(loaderModule.resource("Loader.js") != null);
test(loaderModule.resource("test/Loader.js") == null);
test(loaderModule.grandchildResource("file.js") != null);
test(loaderModule.grandchildResource("Loader/file.js") == null);
test(loaderModule.grandchildResource("test/Loader/file.js") == null);
};

fifty.tests.jsapi.Loader._2 = function() {
var sources = new function() {
var code = {

};

this.get = function(path) {
return null;
};

this.Loader = function(prefix) {
this.list = function() {
return [];
}
}
}
var loader = new module.Loader(sources);
verify(loader).evaluate(function() { return this.run; }).is.not.equalTo(null);
var child = loader.Child("prefix/");
verify(child).evaluate(function() { return this.run; }).is.not.equalTo(null);
}
}
//@ts-ignore
)(fifty);

/**
* A standardized interface for resources that eases interoperability between various kinds of Java-based loaders.
*/
Expand Down
7 changes: 6 additions & 1 deletion loader/jrunscript/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@
* @constructor
*/
function(p) {
if (Object.keys(p).length == 2 && p.type && p.name) {
debugger;
}

if (isStreamDescriptor(p)) {
return new Resource(fromStreamDescriptor(p));
}
Expand Down Expand Up @@ -477,6 +481,7 @@
if (typeof(p) == "object") return String(p) + " with keys: " + Object.keys(p);
return String(p);
})();
debugger;
throw new TypeError("No compatible read() mode specified: parameters = " + parameters + " binary=" + binary + " text=" + text + " argument was " + mode
+ " Streams.binary " + (mode == $exports_io.Streams.binary)
+ " Streams.text " + (mode == $exports_io.Streams.text)
Expand Down Expand Up @@ -820,7 +825,7 @@
if (typeof(resource.name) != "undefined") rv.name = resource.name;
if (typeof(resource.string) != "undefined") rv.string = resource.string;
if (typeof(resource.type) != "undefined") rv.type = resource.type;
if (typeof(resource.read) == "function") {
if (typeof(resource.read) == "function" || (typeof(resource.read) == "object" && resource.read && typeof(resource.read.binary) == "function")) {
rv.read = {
binary: resource.read.binary,
string: void(0)
Expand Down

0 comments on commit a3265e3

Please sign in to comment.