Skip to content

Commit 43d5db4

Browse files
Copilotna-trium-144
andcommitted
Add Ruby runtime tests to test suite
Co-authored-by: na-trium-144 <100704180+na-trium-144@users.noreply.github.com>
1 parent f722cf2 commit 43d5db4

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

app/terminal/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ import "mocha/mocha.js";
44
import "mocha/mocha.css";
55
import { useEffect, useRef, useState } from "react";
66
import { usePyodide } from "./python/runtime";
7+
import { useRuby } from "./ruby/runtime";
78
import { useWandbox } from "./wandbox/runtime";
89
import { RuntimeContext, RuntimeLang } from "./runtime";
910
import { useEmbedContext } from "./embedContext";
1011
import { defineTests } from "./tests";
1112

1213
export default function RuntimeTestPage() {
1314
const pyodide = usePyodide();
15+
const ruby = useRuby();
1416
const wandboxCpp = useWandbox("cpp");
1517
const runtimeRef = useRef<Record<RuntimeLang, RuntimeContext>>(null!);
1618
runtimeRef.current = {
1719
python: pyodide,
20+
ruby: ruby,
1821
cpp: wandboxCpp,
1922
};
2023
const { files, writeFile } = useEmbedContext();

app/terminal/tests.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function defineTests(
1212
(
1313
{
1414
python: 2000,
15+
ruby: 2000,
1516
cpp: 10000,
1617
} as Record<RuntimeLang, number>
1718
)[lang]
@@ -30,6 +31,7 @@ export function defineTests(
3031
const printCode = (
3132
{
3233
python: `print("${msg}")`,
34+
ruby: `puts "${msg}"`,
3335
cpp: null,
3436
} satisfies Record<RuntimeLang, string | null>
3537
)[lang];
@@ -54,6 +56,7 @@ export function defineTests(
5456
const [setIntVarCode, printIntVarCode] = (
5557
{
5658
python: [`${varName} = ${value}`, `print(${varName})`],
59+
ruby: [`${varName} = ${value}`, `puts ${varName}`],
5760
cpp: [null, null],
5861
} satisfies Record<RuntimeLang, string[] | null[]>
5962
)[lang];
@@ -80,6 +83,7 @@ export function defineTests(
8083
const errorCode = (
8184
{
8285
python: `raise Exception("${errorMsg}")`,
86+
ruby: `raise "${errorMsg}"`,
8387
cpp: null,
8488
} satisfies Record<RuntimeLang, string | null>
8589
)[lang];
@@ -99,6 +103,7 @@ export function defineTests(
99103
const [setIntVarCode, infLoopCode, printIntVarCode] = (
100104
{
101105
python: [`testVar = 42`, `while True:\n pass`, `print(testVar)`],
106+
ruby: [`testVar = 42`, `loop do\nend`, `puts testVar`],
102107
cpp: [null, null, null],
103108
} satisfies Record<RuntimeLang, (string | null)[]>
104109
)[lang];
@@ -132,6 +137,7 @@ export function defineTests(
132137
const [filename, code] = (
133138
{
134139
python: ["test.py", `print("${msg}")`],
140+
ruby: ["test.rb", `puts "${msg}"`],
135141
cpp: [
136142
"test.cpp",
137143
`#include <iostream>\nint main() {\n std::cout << "${msg}" << std::endl;\n return 0;\n}\n`,
@@ -156,6 +162,7 @@ export function defineTests(
156162
const [filename, code] = (
157163
{
158164
python: ["test_error.py", `raise Exception("${errorMsg}")\n`],
165+
ruby: ["test_error.rb", `raise "${errorMsg}"\n`],
159166
cpp: [
160167
"test_error.cpp",
161168
`#include <stdexcept>\nint main() {\n throw std::runtime_error("${errorMsg}");\n return 0;\n}\n`,
@@ -183,6 +190,14 @@ export function defineTests(
183190
},
184191
["test_multi_main.py"],
185192
],
193+
ruby: [
194+
{
195+
"test_multi_main.rb":
196+
"require_relative 'test_multi_sub'\nprint_message\n",
197+
"test_multi_sub.rb": `def print_message\n puts "${msg}"\nend\n`,
198+
},
199+
["test_multi_main.rb"],
200+
],
186201
cpp: [
187202
{
188203
"test_multi_main.cpp":

0 commit comments

Comments
 (0)