-
Notifications
You must be signed in to change notification settings - Fork 748
Added tests #1813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added tests #1813
Changes from all commits
097be77
04b9e5e
367cfce
0674335
cf03997
8caa7ce
dcf0f39
d51b790
689587c
d3d08bf
62ba888
e5fe7d5
d12a4cc
1326145
583d683
fa3b85a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,217 @@ | ||
| import { TestRunner } from "./tester"; | ||
|
|
||
| export async function runAceEditorTests(writeOutput) { | ||
| const runner = new TestRunner("Ace Editor API Tests"); | ||
|
|
||
| function createEditor() { | ||
| const container = document.createElement("div"); | ||
| container.style.width = "500px"; | ||
| container.style.height = "300px"; | ||
| container.style.backgroundColor = "#a02f2f"; | ||
| document.body.appendChild(container); | ||
|
|
||
| const editor = ace.edit(container); | ||
| return { editor, container }; | ||
| } | ||
|
|
||
| async function withEditor(test, fn) { | ||
| let editor, container; | ||
|
|
||
| try { | ||
| ({ editor, container } = createEditor()); | ||
| test.assert(editor != null, "Editor instance should be created"); | ||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||
| await fn(editor); | ||
| await new Promise((resolve) => setTimeout(resolve, 200)); | ||
| } finally { | ||
| if (editor) editor.destroy(); | ||
| if (container) container.remove(); | ||
| } | ||
RohitKushvaha01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // Test 1: Ace is available | ||
| runner.test("Ace is loaded", async (test) => { | ||
| test.assert(typeof ace !== "undefined", "Ace should be available globally"); | ||
| test.assert( | ||
| typeof ace.edit === "function", | ||
| "ace.edit should be a function", | ||
| ); | ||
| }); | ||
|
|
||
| // Test 2: Editor creation | ||
| runner.test("Editor creation", async (test) => { | ||
| const { editor, container } = createEditor(); | ||
| test.assert(editor != null, "Editor instance should be created"); | ||
| test.assert( | ||
| typeof editor.getSession === "function", | ||
| "Editor should expose getSession", | ||
| ); | ||
| editor.destroy(); | ||
| container.remove(); | ||
|
Comment on lines
+42
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test manually creates and destroys the editor instead of using the Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: src/test/editor.tests.js
Line: 42:50
Comment:
this test manually creates and destroys the editor instead of using the `withEditor` helper like all other tests. This creates inconsistency and doesn't include the wait delays that other tests have. Consider using `withEditor` for consistency.
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise. |
||
| }); | ||
|
|
||
| // Test 3: Session access | ||
| runner.test("Session access", async (test) => { | ||
| await withEditor(test, async (editor) => { | ||
| const session = editor.getSession(); | ||
| test.assert(session != null, "Editor session should exist"); | ||
| test.assert( | ||
| typeof session.getValue === "function", | ||
| "Session should expose getValue", | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| // Test 4: Set and get value | ||
| runner.test("Set and get value", async (test) => { | ||
| await withEditor(test, async (editor) => { | ||
| const text = "Hello Ace Editor"; | ||
| editor.setValue(text, -1); | ||
| test.assertEqual(editor.getValue(), text); | ||
| }); | ||
| }); | ||
|
|
||
| // Test 5: Cursor movement | ||
| runner.test("Cursor movement", async (test) => { | ||
| await withEditor(test, async (editor) => { | ||
| editor.setValue("line1\nline2\nline3", -1); | ||
| editor.moveCursorTo(1, 2); | ||
|
|
||
| const pos = editor.getCursorPosition(); | ||
| test.assertEqual(pos.row, 1); | ||
| test.assertEqual(pos.column, 2); | ||
| }); | ||
| }); | ||
|
|
||
| // Test 6: Selection API | ||
| runner.test("Selection handling", async (test) => { | ||
| await withEditor(test, async (editor) => { | ||
| editor.setValue("abc\ndef", -1); | ||
| editor.selectAll(); | ||
| test.assert(editor.getSelectedText().length > 0); | ||
| }); | ||
| }); | ||
|
|
||
| // Test 7: Undo manager | ||
| runner.test("Undo manager works", async (test) => { | ||
| await withEditor(test, async (editor) => { | ||
| const session = editor.getSession(); | ||
| const undoManager = session.getUndoManager(); | ||
|
|
||
| session.setValue("one"); | ||
| undoManager.reset(); | ||
|
|
||
| editor.insert("\ntwo"); | ||
RohitKushvaha01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| editor.undo(); | ||
|
|
||
| test.assertEqual(editor.getValue(), "one"); | ||
| }); | ||
| }); | ||
|
|
||
| // Test 8: Mode setting | ||
| runner.test("Mode setting", async (test) => { | ||
| await withEditor(test, async (editor) => { | ||
| const session = editor.getSession(); | ||
| session.setMode("ace/mode/javascript"); | ||
|
|
||
| const mode = session.getMode(); | ||
| test.assert(mode && mode.$id === "ace/mode/javascript"); | ||
| }); | ||
| }); | ||
|
|
||
| // Test 9: Theme setting | ||
| runner.test("Theme setting", async (test) => { | ||
| await withEditor(test, async (editor) => { | ||
| editor.setTheme("ace/theme/monokai"); | ||
| test.assert(editor.getTheme().includes("monokai")); | ||
| }); | ||
| }); | ||
|
|
||
| // Test 11: Line count | ||
RohitKushvaha01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| runner.test("Line count", async (test) => { | ||
| await withEditor(test, async (editor) => { | ||
| editor.setValue("a\nb\nc\nd", -1); | ||
| test.assertEqual(editor.session.getLength(), 4); | ||
| }); | ||
| }); | ||
|
Comment on lines
+130
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test numbering jumps from Test 9 to Test 11, skipping Test 10. Either add the missing test or renumber this test to maintain sequential ordering. Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: src/test/editor.tests.js
Line: 130:136
Comment:
test numbering jumps from Test 9 to Test 11, skipping Test 10. Either add the missing test or renumber this test to maintain sequential ordering.
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| // Test 12: Replace text | ||
| runner.test("Replace text", async (test) => { | ||
| await withEditor(test, async (editor) => { | ||
| editor.setValue("hello world", -1); | ||
| editor.find("world"); | ||
| editor.replace("ace"); | ||
|
|
||
| test.assertEqual(editor.getValue(), "hello ace"); | ||
| }); | ||
| }); | ||
|
|
||
| // Test 13: Search API | ||
| runner.test("Search API", async (test) => { | ||
| await withEditor(test, async (editor) => { | ||
| editor.setValue("foo bar foo", -1); | ||
| editor.find("foo"); | ||
|
|
||
| const range = editor.getSelectionRange(); | ||
| test.assert(range.start.column === 0); | ||
| }); | ||
| }); | ||
|
|
||
| // Test 14: Renderer availability | ||
| runner.test("Renderer exists", async (test) => { | ||
| await withEditor(test, async (editor) => { | ||
| const renderer = editor.renderer; | ||
| test.assert(renderer != null); | ||
| test.assert(typeof renderer.updateFull === "function"); | ||
| }); | ||
| }); | ||
|
|
||
| // Test 15: Editor options | ||
| runner.test("Editor options", async (test) => { | ||
| await withEditor(test, async (editor) => { | ||
| editor.setOption("showPrintMargin", false); | ||
| test.assertEqual(editor.getOption("showPrintMargin"), false); | ||
| }); | ||
| }); | ||
|
|
||
| // Test 16: Scroll API | ||
| runner.test("Scroll API", async (test) => { | ||
| await withEditor(test, async (editor) => { | ||
| editor.setValue(Array(100).fill("line").join("\n"), -1); | ||
| editor.scrollToLine(50, true, true, () => {}); | ||
|
|
||
| const firstVisibleRow = editor.renderer.getFirstVisibleRow(); | ||
| test.assert(firstVisibleRow >= 0); | ||
| }); | ||
| }); | ||
|
|
||
| // Test 17: Redo manager | ||
| runner.test("Redo manager works", async (test) => { | ||
| await withEditor(test, async (editor) => { | ||
| const session = editor.getSession(); | ||
| const undoManager = session.getUndoManager(); | ||
|
|
||
| session.setValue("one"); | ||
| undoManager.reset(); | ||
|
|
||
| session.insert({ row: 0, column: 3 }, "\ntwo"); | ||
| editor.undo(); | ||
| editor.redo(); | ||
|
|
||
| test.assertEqual(editor.getValue(), "one\ntwo"); | ||
| }); | ||
| }); | ||
|
|
||
| // Test 18: Focus and blur | ||
| runner.test("Focus and blur", async (test) => { | ||
| await withEditor(test, async (editor) => { | ||
| editor.focus(); | ||
| test.assert(editor.isFocused()); | ||
|
|
||
| editor.blur(); | ||
| test.assert(!editor.isFocused()); | ||
| }); | ||
| }); | ||
|
|
||
| return await runner.run(writeOutput); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { TestRunner } from "./tester"; | ||
|
|
||
| export async function runSanityTests(writeOutput) { | ||
| const runner = new TestRunner("JS (WebView) Sanity Tests"); | ||
|
|
||
| // Test 1: String operations | ||
| runner.test("String concatenation", (test) => { | ||
| const result = "Hello" + " " + "World"; | ||
| test.assertEqual(result, "Hello World", "String concatenation should work"); | ||
| }); | ||
|
|
||
| // Test 2: Number operations | ||
| runner.test("Basic arithmetic", (test) => { | ||
| const sum = 5 + 3; | ||
| test.assertEqual(sum, 8, "Addition should work correctly"); | ||
| }); | ||
|
|
||
| // Test 3: Array operations | ||
| runner.test("Array operations", (test) => { | ||
| const arr = [1, 2, 3]; | ||
| test.assertEqual(arr.length, 3, "Array length should be correct"); | ||
| test.assert(arr.includes(2), "Array should include 2"); | ||
| }); | ||
|
|
||
| // Test 4: Object operations | ||
| runner.test("Object operations", (test) => { | ||
| const obj = { name: "Test", value: 42 }; | ||
| test.assertEqual(obj.name, "Test", "Object property should be accessible"); | ||
| test.assertEqual(obj.value, 42, "Object value should be correct"); | ||
| }); | ||
|
|
||
| // Test 5: Function execution | ||
| runner.test("Function execution", (test) => { | ||
| const add = (a, b) => a + b; | ||
| const result = add(10, 20); | ||
| test.assertEqual(result, 30, "Function should return correct value"); | ||
| }); | ||
|
|
||
| // Test 6: Async function | ||
| runner.test("Async function handling", async (test) => { | ||
| const asyncFunc = async () => { | ||
| return new Promise((resolve) => { | ||
| setTimeout(() => resolve("done"), 10); | ||
| }); | ||
| }; | ||
|
|
||
| const result = await asyncFunc(); | ||
| test.assertEqual(result, "done", "Async function should work correctly"); | ||
| }); | ||
|
|
||
| // Test 7: Error handling | ||
| runner.test("Error handling", (test) => { | ||
| try { | ||
| throw new Error("Test error"); | ||
| } catch (e) { | ||
| test.assert(e instanceof Error, "Should catch Error instances"); | ||
| } | ||
| }); | ||
|
|
||
| // Test 8: Conditional logic | ||
| runner.test("Conditional logic", (test) => { | ||
| const value = 10; | ||
| test.assert(value > 5, "Condition should be true"); | ||
| test.assert(!(value < 5), "Negation should work"); | ||
| }); | ||
|
|
||
| // Run all tests | ||
| return await runner.run(writeOutput); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.