Skip to content

Commit

Permalink
Resolve #1657: Migrate loader/jrunscript JSAPI -> Fifty
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpcaldwell committed Sep 12, 2024
1 parent 273f183 commit b3b342a
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 246 deletions.
1 change: 1 addition & 0 deletions contributor/jrunscript.fifty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
fifty.load("../loader/jrunscript/expression.fifty.ts");
fifty.load("../loader/api/old/unit.fifty.ts");
fifty.load("../rhino/system/test/Packages.inonit.system.fifty.ts");
fifty.load("../rhino/system/java/inonit/script/runtime/io/Streams.fifty.ts");
fifty.load("../rhino/jrunscript/api.fifty.ts");
if (hasJsoup) fifty.load("../loader/document/module.fifty.ts");
fifty.load("../js/web/module.fifty.ts");
Expand Down
7 changes: 0 additions & 7 deletions contributor/jrunscript.jsh.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,9 @@
pathname: SRC.getRelativePath("loader/api.html")
}));

suite.add("internal/jrunscript/main", new jsh.unit.html.Part({
// Test cases of loader implementation
// TODO redundant; now tested per-engine in contributor/suite.jsh.js
pathname: SRC.getRelativePath("loader/jrunscript/api.html")
}));

suite.add("internal/other", new jsh.unit.html.Part({
// Test cases involving the HTML test runner itself
pathname: SRC.getRelativePath("loader/api/test/data/1/api.html")
// TODO loader/jrunscript/java has some tests
// TODO loader/jrunscript/test/data/2/ has some tests but they require some classes in classpath
}));

Expand Down
2 changes: 1 addition & 1 deletion jrunscript/io/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h1>Context</h1>
<div>
<h1>Exports</h1>
<ul>
<li class="constructor" jsapi:reference="getApi('../../loader/jrunscript/api.html').getElement('Loader')">
<li class="constructor">
</li>
<li class="object">
<div class="name">java</div>
Expand Down
1 change: 0 additions & 1 deletion jrunscript/jsh/etc/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
components.add("js/debug/", { jsh: { module: true }});

components.add("loader/jrunscript/", { jsh: { api: true }});
// TODO loader/jrunscript/java has some tests
// TODO loader/jrunscript/test/data/2/ has some tests but they require some classes in classpath
// TODO jrunscript/io/mime.api.html has some tests

Expand Down
163 changes: 0 additions & 163 deletions loader/jrunscript/api.html

This file was deleted.

21 changes: 18 additions & 3 deletions loader/jrunscript/expression.fifty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,29 @@ namespace slime.jrunscript.runtime {
}

export interface JavaCodeLoaderSource {
/**
* An object representing resources that can be loaded by this Loader.
*/
_source: slime.jrunscript.native.inonit.script.engine.Code.Loader
}

/** @deprecated */
/**
* @deprecated
*
* An object that can return resources given paths.
*/
export interface DeprecatedResourcesSource {
child?: any
resources: any
Loader?: any

resources: {
/**
* Returns an implementation for a resource at the given path.
* @param path A path.
* @returns An argument for the `Resource` constructor that implements the resource at the given path, or `null` if
* no resource is located at the given path.
*/
get: (path: string) => slime.jrunscript.runtime.old.resource.Descriptor & { string?: string }
}
}

export type CustomSource = ZipFileSource | ZipResourceSource | JavaFileSource | JavaCodeLoaderSource | DeprecatedResourcesSource
Expand Down
68 changes: 0 additions & 68 deletions loader/jrunscript/java/api.html

This file was deleted.

3 changes: 0 additions & 3 deletions loader/jrunscript/test/suite.jsh.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
suite.add("slime", new jsh.unit.html.Part({
pathname: SRC.getRelativePath("loader/api.html")
}));
suite.add("jrunscript/main", new jsh.unit.html.Part({
pathname: SRC.getRelativePath("loader/jrunscript/api.html")
}));

/**
*
Expand Down
70 changes: 70 additions & 0 deletions rhino/system/java/inonit/script/runtime/io/Streams.fifty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,74 @@ namespace slime.jrunscript.native.inonit.script.runtime.io {

readLine: (r: java.io.Reader, terminator: string) => java.lang.String
}

(
function(
Packages: slime.jrunscript.Packages,
fifty: slime.fifty.test.Kit
) {
const { Streams } = Packages.inonit.script.runtime.io;

const test = function(f: () => boolean) {
var b = f();
fifty.verify(b).is(true);
};

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

fifty.tests.jsapi._1 = function() {
var buffer = new Packages.inonit.script.runtime.io.Streams.Bytes.Buffer();
var data = [ -3, 2, 5, -7 ];
var write = buffer.getOutputStream();
write.write(-3);
write.write(2);
write.write(5);
write.write(-7);
write.close();

var read = buffer.getInputStream();
var from = [];
var b;
while( (b = read.read()) != -1) {
if (b > 127) {
b -= 256;
}
from.push(b);
}

test( function() { return data.join(",") == from.join(","); } );
}

fifty.tests.jsapi._2 = function() {
var tokenizer = new Streams();

var s1 = "fff\nggg\nhhh";

var split = function(s1,eol) {
var r1 = new Packages.java.io.StringReader(s1);
var lines = [];
var line;
while( (line = String(tokenizer.readLine(r1, eol)) ) ) {
fifty.global.jsh.shell.console("[" + line + "]");
lines.push(line);
}
return lines;
}

var lines = split(s1,"\n");
// TODO WTF? trailing newlines?
test( function() { return lines[0] == "fff\n"; } );
test( function() { return lines[1] == "ggg\n"; } );
test( function() { return lines[2] == "hhh"; } );

var lines2 = split(s1, "\r\n");
test( function() { return lines2[0] == s1; } );
}

fifty.tests.suite = function() {
fifty.run(fifty.tests.jsapi);
}
}
//@ts-ignore
)(Packages,fifty);
}
Loading

0 comments on commit b3b342a

Please sign in to comment.