Transpiled version (69857L) is out of date.
!include once #1034831 // Gazelle 22 Function Include for Testing scope test_LeftArrowScriptAutoCompleter svoid test_LeftArrowScriptAutoCompleter() { new GazelleV_LeftArrowScriptParser parser; LeftArrowScriptAutoCompleter completer = new(parser); // simple test for completing global function name completer.globalMethodNames = -> ll("add", "pat", "lol"); completer.parser.noImports(); assertEmpty(completer.parser.globalClassNames()); completer.seek("a", 1); assertEqualsVerbose("a", completer.typedCharacters()); assertEqualsVerbose(ll("add", "pat", "false"), completer.getCompletions()); // test that completed word is not shown as suggestion parser = new GazelleV_LeftArrowScriptParser; completer = new LeftArrowScriptAutoCompleter(parser); completer.globalMethodNames = -> ll("add", "pat", "lol"); completer.parser.importedPackages = -> null; // to suppress class names being returned completer.seek("add", 3); assertFalseVerbose(contains(completer.getCompletions(), "add")); // test for standard function arguments (untyped, will break when // we introduce typing) parser = new GazelleV_LeftArrowScriptParser; completer = new LeftArrowScriptAutoCompleter(parser); completer.globalMethodNames = -> ll("add", "pat", "lol"); completer.parser.importedPackages = -> null; // to suppress class names being returned completer.seek("add ", 4); assertContainsAll(completer.getCompletions(), ll("true", "false", "null")); // complete class name for (S text : ll("Mat", "Mat ")) { parser = new GazelleV_LeftArrowScriptParser; // restore class finding completer = new LeftArrowScriptAutoCompleter(parser); completer.seek(printQuoted(+text), 3); var completions = completer.getCompletions(); pnlReversed(takeFirst(10, completions)); assertEquals(0, indexOf(completions, "Math")); } // same after "new" parser = new GazelleV_LeftArrowScriptParser; // restore class finding completer = new LeftArrowScriptAutoCompleter(parser); completer.seek(print("new Inte"), 8); var completions = completer.getCompletions(); pnlReversed(takeFirst(10, completions)); assertEquals(0, indexOf(completions, "Integer")); // find inner classes of global function container parser = new GazelleV_LeftArrowScriptParser; // restore class finding parser.allowTheWorld(FunctionContainer.class); completer = new LeftArrowScriptAutoCompleter(parser); completer.seek(print("MyN"), 3); completions = completer.getCompletions(); pnlReversed(takeFirst(10, completions)); assertEquals(0, indexOf(completions, "MyName")); // auto-complete global script-defined functions parser = new GazelleV_LeftArrowScriptParser; parser.functionDefs.put("hello", new GazelleV_LeftArrowScript.FunctionDef); completer = new LeftArrowScriptAutoCompleter(parser); completer.seekEnd("he"); completions = completer.getCompletions(); assertContains(completions, "hello"); testVars(); testMethodsOfNewInstance(); testMethodsOfNewInstanceInVar(); testMethodsOfFunctionResultInVar(); testMethodsOfLambdaParameter(); testMethodsOfForVariable(); printWithPrecedingNL("Auto-completer works!"); } svoid #testVars { // auto-complete variable names var parser = new GazelleV_LeftArrowScriptParser; parser.noImports(); var completer = new LeftArrowScriptAutoCompleter(parser); completer.seekEnd("a <- 1\n"); pnl("knowVarsByTokenIdx", completer.knownVarsByTokenIdx); assertSetsEqual(print(listPlus(completer.predefinedExpressions(), "a")), print(completer.getCompletions())); } svoid #testMethodsOfNewInstance { var parser = enableScaffolding(new GazelleV_LeftArrowScriptParser); //parser.noImports(); var completer = enableScaffolding(new LeftArrowScriptAutoCompleter(parser)); completer.seekEnd("new Double, "); assertContains(print(completer.getCompletions()), "doubleValue"); } svoid #testMethodsOfNewInstanceInVar { var parser = enableScaffolding(new GazelleV_LeftArrowScriptParser); parser.onTypeHook(type -> print("TypeHook at " + parser.t() + " (" + parser.tokIdx() + ": " + type); //parser.noImports(); var completer = /*enableScaffolding*/(new LeftArrowScriptAutoCompleter(parser)); completer.seekEnd("x <- new Double; x "); //pnl("TYPEHOOK", completer.typeHooks); assertContains(print(completer.getCompletions()), "doubleValue"); } svoid #testMethodsOfFunctionResultInVar { var parser = enableScaffolding(new GazelleV_LeftArrowScriptParser); var completer = /*enableScaffolding*/(new LeftArrowScriptAutoCompleter(parser)); completer.seekEnd([[ def myFunc: S { "" }; x <- myFunc; x ]]); assertContains(print(completer.getCompletions()), "length"); } svoid #testMethodsOfLambdaParameter { var parser = enableScaffolding(new GazelleV_LeftArrowScriptParser); parser.allowTheWorld(FunctionContainer.class); var completer = /*enableScaffolding*/(new LeftArrowScriptAutoCompleter(parser)); completer.seekEnd([[ IVF1 a: S -> a ]]); assertContains(print(completer.getCompletions()), "length"); } svoid #testMethodsOfForVariable { var parser = enableScaffolding(new GazelleV_LeftArrowScriptParser); parser.allowTheWorld(FunctionContainer.class); var completer = /*enableScaffolding*/(new LeftArrowScriptAutoCompleter(parser)); completer.seekEnd([[ for s: S in null { s ]]); assertContains(print(completer.getCompletions()), "length"); } sclass #FunctionContainer { class MyName {} interface IVF1<A> { void get(A a); } }
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, ekrmjmnbrukm, elmgxqgtpvxh, mowyntqkapby, mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
Snippet ID: | #1034158 |
Snippet name: | test_LeftArrowScriptAutoCompleter |
Eternal ID of this version: | #1034158/61 |
Text MD5: | 56e7cf6dc05fb2d5b6a93e0a4bb60b2d |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2023-03-14 13:55:08 |
Source code size: | 5661 bytes / 141 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 280 / 819 |
Version history: | 60 change(s) |
Referenced in: | [show references] |