All tests are passing for Python

This commit is contained in:
Radon Rosborough 2020-12-27 13:12:29 -08:00
parent 2dd3e31f1a
commit accc4da201
6 changed files with 33 additions and 27 deletions

View File

@ -304,7 +304,7 @@ export class Session {
cmdline = `echo '${name} has no REPL, press Run to see it in action'`; cmdline = `echo '${name} has no REPL, press Run to see it in action'`;
} }
if (code === undefined) { if (code === undefined) {
code = createEmpty !== undefined ? createEmpty : template; code = createEmpty !== undefined ? createEmpty : template + "\n";
} }
if (code && suffix) { if (code && suffix) {
code += suffix; code += suffix;

View File

@ -9,6 +9,22 @@ import { log } from "./util.js";
// populated at runtime and updated asynchronously. // populated at runtime and updated asynchronously.
export let langs = {}; export let langs = {};
// Correct whitespace problems in a language configuration,
// destructively. Return the fixed configuration.
//
// This basically removes leading and trailing whitespace from all
// values in the configuration recursively.
function fixupLangConfig(langConfig) {
if (typeof langConfig === "string") {
return langConfig.trim();
} else if (typeof langConfig === "object") {
for (const key in langConfig) {
langConfig[key] = fixupLangConfig(langConfig[key]);
}
}
return langConfig;
}
// Read languages from JSON files in /opt/riju/langs, and update the // Read languages from JSON files in /opt/riju/langs, and update the
// global langs variable in this module. Never throw an error. If // global langs variable in this module. Never throw an error. If
// there is a problem then just leave the languages as they previously // there is a problem then just leave the languages as they previously
@ -21,8 +37,8 @@ async function readLangsFromDisk() {
continue; continue;
} }
const id = path.parse(filename).name; const id = path.parse(filename).name;
const langConfig = JSON.parse( const langConfig = fixupLangConfig(
await fs.readFile(`/opt/riju/langs/${filename}`, "utf-8") JSON.parse(await fs.readFile(`/opt/riju/langs/${filename}`, "utf-8"))
); );
if (langConfig.id !== id) { if (langConfig.id !== id) {
log.error( log.error(

View File

@ -214,7 +214,7 @@ class Test {
}; };
testRun = async () => { testRun = async () => {
const pattern = this.config.hello || "Hello, world!"; const pattern = this.config.hello || "Hello, world!";
this.send({ event: "runCode", code: this.config.template }); this.send({ event: "runCode", code: this.config.template + "\n" });
if (this.config.helloInput !== undefined) { if (this.config.helloInput !== undefined) {
sendInput(this.send, this.config.helloInput); sendInput(this.send, this.config.helloInput);
} }
@ -229,7 +229,7 @@ class Test {
testRunRepl = async () => { testRunRepl = async () => {
const input = this.config.runReplInput || this.config.input || "123 * 234"; const input = this.config.runReplInput || this.config.input || "123 * 234";
const output = this.config.runReplOutput || this.config.output || "28782"; const output = this.config.runReplOutput || this.config.output || "28782";
this.send({ event: "runCode", code: this.config.template }); this.send({ event: "runCode", code: this.config.template + "\n" });
sendInput(this.send, input); sendInput(this.send, input);
await this.waitForOutput(output); await this.waitForOutput(output);
}; };
@ -238,10 +238,7 @@ class Test {
const after = this.config.scope.after; const after = this.config.scope.after;
const input = this.config.scope.input || "x"; const input = this.config.scope.input || "x";
const output = this.config.scope.output || "28782"; const output = this.config.scope.output || "28782";
let allCode = this.config.template; let allCode = this.config.template + "\n";
if (!allCode.endsWith("\n")) {
allCode += "\n";
}
if (after) { if (after) {
allCode = allCode.replace(after + "\n", after + "\n" + code + "\n"); allCode = allCode.replace(after + "\n", after + "\n" + code + "\n");
} else { } else {
@ -253,7 +250,7 @@ class Test {
}; };
testFormat = async () => { testFormat = async () => {
const input = this.config.format.input; const input = this.config.format.input;
const output = this.config.format.output || this.config.template; const output = (this.config.format.output || this.config.template) + "\n";
this.send({ event: "formatCode", code: input }); this.send({ event: "formatCode", code: input });
const result = await this.wait("formatter response", (msg) => { const result = await this.wait("formatter response", (msg) => {
if (msg.event === "formattedCode") { if (msg.event === "formattedCode") {
@ -265,16 +262,14 @@ class Test {
} }
}; };
testLsp = async () => { testLsp = async () => {
const template = this.config.template + "\n";
const insertedCode = this.config.lsp.code; const insertedCode = this.config.lsp.code;
const after = this.config.lsp.after; const after = this.config.lsp.after;
const item = this.config.lsp.item; const item = this.config.lsp.item;
const idx = after const idx = after
? this.config.template.indexOf(after) + after.length ? template.indexOf(after) + after.length
: this.config.template.length; : template.length;
const code = const code = template.slice(0, idx) + insertedCode + template.slice(idx);
this.config.template.slice(0, idx) +
insertedCode +
this.config.template.slice(idx);
const root = await this.wait("lspStarted message", (msg) => { const root = await this.wait("lspStarted message", (msg) => {
if (msg.event === "lspStarted") { if (msg.event === "lspStarted") {
return msg.root; return msg.root;
@ -538,7 +533,7 @@ class Test {
jsonrpc: "2.0", jsonrpc: "2.0",
id: msg.output.id, id: msg.output.id,
result: Array(msg.output.params.items.length).fill( result: Array(msg.output.params.items.length).fill(
this.config.lsp.config == undefined this.config.lsp.config !== undefined
? this.config.lsp.config ? this.config.lsp.config
: {} : {}
), ),
@ -560,11 +555,6 @@ class Test {
function lint(lang) { function lint(lang) {
const config = langs[lang]; const config = langs[lang];
if (!config.template.endsWith("\n")) {
throw new Error("template is missing a trailing newline");
}
// These can be removed when the types are adjusted to make these
// situations impossible.
if ( if (
config.format && config.format &&
!config.format.input && !config.format.input &&

View File

@ -289,7 +289,7 @@ async function main() {
scrollbar: { verticalScrollbarSize: 0 }, scrollbar: { verticalScrollbarSize: 0 },
}); });
window.addEventListener("resize", () => editor.layout()); window.addEventListener("resize", () => editor.layout());
editor.getModel().setValue(config.template); editor.getModel().setValue(config.template + "\n");
monaco.editor.setModelLanguage( monaco.editor.setModelLanguage(
editor.getModel(), editor.getModel(),
config.monacoLang || "plaintext" config.monacoLang || "plaintext"

View File

@ -20,7 +20,7 @@ install:
chmod +x "${pkg}/opt/mspyls/Microsoft.Python.LanguageServer" chmod +x "${pkg}/opt/mspyls/Microsoft.Python.LanguageServer"
ln -s "/opt/mspyls/Microsoft.Python.LanguageServer" "${pkg}/usr/local/bin/Microsoft.Python.LanguageServer" ln -s "/opt/mspyls/Microsoft.Python.LanguageServer" "${pkg}/usr/local/bin/Microsoft.Python.LanguageServer"
repl: >- repl: |
python3 -u python3 -u
main: "main.py" main: "main.py"
template: | template: |
@ -31,7 +31,7 @@ scope:
x = 123 * 234 x = 123 * 234
format: format:
run: >- run: |
black - black -
input: | input: |
print('Hello, world!') print('Hello, world!')
@ -39,7 +39,7 @@ format:
pkg: pkg:
install: "pip3 install --user NAME" install: "pip3 install --user NAME"
uninstall: "pip3 uninstall NAME" uninstall: "pip3 uninstall NAME"
search: >- search: |
python3 -c 'import json; from xmlrpc import client; print(json.dumps(client.ServerProxy("https://pypi.org/pypi").search({"name": "NAME"})))' | jq -r 'map(.name) | .[]' python3 -c 'import json; from xmlrpc import client; print(json.dumps(client.ServerProxy("https://pypi.org/pypi").search({"name": "NAME"})))' | jq -r 'map(.name) | .[]'
lsp: lsp:

View File

@ -39,7 +39,7 @@ cat <<EOF > "\${pkg}/DEBIAN/control"
${debianControlData} ${debianControlData}
EOF`); EOF`);
for (const part of manual || []) { for (const part of manual || []) {
parts.push(part.trim()); parts.push(part);
} }
return parts.join("\n\n"); return parts.join("\n\n");
} }