Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

141
LINES

< > BotCompany Repo | #1034158 // test_LeftArrowScriptAutoCompleter

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (69857L) is out of date.

1  
!include once #1034831 // Gazelle 22 Function Include for Testing
2  
3  
scope test_LeftArrowScriptAutoCompleter
4  
5  
svoid test_LeftArrowScriptAutoCompleter() {
6  
  new GazelleV_LeftArrowScriptParser parser;
7  
  LeftArrowScriptAutoCompleter completer = new(parser);
8  
  
9  
  // simple test for completing global function name
10  
  
11  
  completer.globalMethodNames = -> ll("add", "pat", "lol");
12  
  
13  
  completer.parser.noImports();
14  
  
15  
  assertEmpty(completer.parser.globalClassNames());
16  
  completer.seek("a", 1);
17  
  assertEqualsVerbose("a", completer.typedCharacters());
18  
  assertEqualsVerbose(ll("add", "pat", "false"), completer.getCompletions());
19  
  
20  
  // test that completed word is not shown as suggestion
21  
  parser = new GazelleV_LeftArrowScriptParser;
22  
  completer = new LeftArrowScriptAutoCompleter(parser);
23  
  completer.globalMethodNames = -> ll("add", "pat", "lol");
24  
  completer.parser.importedPackages = -> null; // to suppress class names being returned
25  
  
26  
  completer.seek("add", 3);
27  
  assertFalseVerbose(contains(completer.getCompletions(), "add"));
28  
  
29  
  // test for standard function arguments (untyped, will break when
30  
  // we introduce typing)
31  
  
32  
  parser = new GazelleV_LeftArrowScriptParser;
33  
  completer = new LeftArrowScriptAutoCompleter(parser);
34  
  completer.globalMethodNames = -> ll("add", "pat", "lol");
35  
  completer.parser.importedPackages = -> null; // to suppress class names being returned
36  
  
37  
  completer.seek("add ", 4);
38  
  assertContainsAll(completer.getCompletions(), ll("true", "false", "null"));
39  
  
40  
  // complete class name
41  
  for (S text : ll("Mat", "Mat ")) {
42  
    parser = new GazelleV_LeftArrowScriptParser; // restore class finding
43  
    completer = new LeftArrowScriptAutoCompleter(parser);
44  
    completer.seek(printQuoted(+text), 3);
45  
    var completions = completer.getCompletions();
46  
    pnlReversed(takeFirst(10, completions));
47  
    assertEquals(0, indexOf(completions, "Math"));
48  
  }
49  
  
50  
  // same after "new"
51  
  parser = new GazelleV_LeftArrowScriptParser; // restore class finding
52  
  completer = new LeftArrowScriptAutoCompleter(parser);
53  
  
54  
  completer.seek(print("new Inte"), 8);
55  
  var completions = completer.getCompletions();
56  
  pnlReversed(takeFirst(10, completions));
57  
  assertEquals(0, indexOf(completions, "Integer"));
58  
  
59  
  // find inner classes of global function container
60  
  parser = new GazelleV_LeftArrowScriptParser; // restore class finding
61  
  parser.allowTheWorld(FunctionContainer.class);
62  
  completer = new LeftArrowScriptAutoCompleter(parser);
63  
  completer.seek(print("MyN"), 3);
64  
  completions = completer.getCompletions();
65  
  pnlReversed(takeFirst(10, completions));
66  
  assertEquals(0, indexOf(completions, "MyName"));
67  
  
68  
  // auto-complete global script-defined functions
69  
  parser = new GazelleV_LeftArrowScriptParser;
70  
  parser.functionDefs.put("hello", new GazelleV_LeftArrowScript.FunctionDef);
71  
  completer = new LeftArrowScriptAutoCompleter(parser);
72  
  completer.seekEnd("he");
73  
  completions = completer.getCompletions();
74  
  assertContains(completions, "hello");
75  
  
76  
  testVars();
77  
  testMethodsOfNewInstance();
78  
  testMethodsOfNewInstanceInVar();
79  
  testMethodsOfFunctionResultInVar();
80  
  testMethodsOfLambdaParameter();
81  
  testMethodsOfForVariable();
82  
    
83  
  printWithPrecedingNL("Auto-completer works!");
84  
}
85  
86  
svoid #testVars {
87  
  // auto-complete variable names
88  
  var parser = new GazelleV_LeftArrowScriptParser;
89  
  parser.noImports();
90  
  var completer = new LeftArrowScriptAutoCompleter(parser);
91  
  completer.seekEnd("a <- 1\n");
92  
  pnl("knowVarsByTokenIdx", completer.knownVarsByTokenIdx);
93  
  assertSetsEqual(print(listPlus(completer.predefinedExpressions(), "a")),
94  
    print(completer.getCompletions()));
95  
}
96  
97  
svoid #testMethodsOfNewInstance {
98  
  var parser = enableScaffolding(new GazelleV_LeftArrowScriptParser);
99  
  //parser.noImports();
100  
  var completer = enableScaffolding(new LeftArrowScriptAutoCompleter(parser));
101  
  completer.seekEnd("new Double, ");
102  
  assertContains(print(completer.getCompletions()), "doubleValue"); 
103  
}
104  
105  
svoid #testMethodsOfNewInstanceInVar {
106  
  var parser = enableScaffolding(new GazelleV_LeftArrowScriptParser);
107  
  parser.onTypeHook(type -> print("TypeHook at " + parser.t() + " (" + parser.tokIdx() + ": " + type);
108  
  //parser.noImports();
109  
  var completer = /*enableScaffolding*/(new LeftArrowScriptAutoCompleter(parser));
110  
  completer.seekEnd("x <- new Double; x ");
111  
  //pnl("TYPEHOOK", completer.typeHooks);
112  
  assertContains(print(completer.getCompletions()), "doubleValue"); 
113  
}
114  
115  
svoid #testMethodsOfFunctionResultInVar {
116  
  var parser = enableScaffolding(new GazelleV_LeftArrowScriptParser);
117  
  var completer = /*enableScaffolding*/(new LeftArrowScriptAutoCompleter(parser));
118  
  completer.seekEnd([[ def myFunc: S { "" }; x <- myFunc; x ]]);
119  
  assertContains(print(completer.getCompletions()), "length"); 
120  
}
121  
122  
svoid #testMethodsOfLambdaParameter {
123  
  var parser = enableScaffolding(new GazelleV_LeftArrowScriptParser);
124  
  parser.allowTheWorld(FunctionContainer.class);
125  
  var completer = /*enableScaffolding*/(new LeftArrowScriptAutoCompleter(parser));
126  
  completer.seekEnd([[ IVF1 a: S -> a ]]);
127  
  assertContains(print(completer.getCompletions()), "length"); 
128  
}
129  
130  
svoid #testMethodsOfForVariable {
131  
  var parser = enableScaffolding(new GazelleV_LeftArrowScriptParser);
132  
  parser.allowTheWorld(FunctionContainer.class);
133  
  var completer = /*enableScaffolding*/(new LeftArrowScriptAutoCompleter(parser));
134  
  completer.seekEnd([[ for s: S in null { s ]]);
135  
  assertContains(print(completer.getCompletions()), "length"); 
136  
}
137  
138  
sclass #FunctionContainer {
139  
  class MyName {}
140  
  interface IVF1<A> { void get(A a); }
141  
}

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: 281 / 821
Version history: 60 change(s)
Referenced in: [show references]