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

83
LINES

< > BotCompany Repo | #1025409 // test_tok_recordDecls

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

Transpiled version (8562L) is out of date.

svoid test_tok_recordDecls() {
  LS tok = jtok("record $HappensBefore$<A, B>(A event1, B event2) extends Fact {}");
  tok_recordDecls(tok);
  print(join(tok));
  assertTrueVerbose(jMatchStart([[
    class $HappensBefore$<A, B> extends Fact implements IFieldsToList {
      A event1;
      B event2;
    ]], tok));
    
  test_tok_recordDecls_2();
}

// we can omit the field types if the type is Object
svoid test_tok_recordDecls_2() {
  LS tok = jtok("record Blubb(a, b) {}");
  tok_recordDecls(tok);
  print(join(tok));
  assertTrueVerbose(jMatchStart([[
    class Blubb implements IFieldsToList {
      Object a;
      Object b;
    ]], tok));
    
  test_tok_recordDecls_3();
}

// handle existing "implements"
svoid test_tok_recordDecls_3() {
  LS tok = jtok("record Blubb implements Bla {}");
  tok_recordDecls(tok);
  print(join(tok));
  assertTrueVerbose(jMatchStart([[
    class Blubb implements Bla, IFieldsToList {
    ]], tok));
    
  test_tok_recordDecls_4();
}

svoid test_tok_recordDecls_4() {
  LS tok = jtok("record Blubb extends Bla {}");
  tok_recordDecls(tok);
  print(join(tok));
  assertTrueVerbose(join(tok), jMatchStart([[
    class Blubb extends Bla implements IFieldsToList {
    ]], tok));
    
  test_tok_recordDecls_5();
}

// existing constructor
svoid test_tok_recordDecls_5() {
  // constructor in star syntax
  LS tok = jtok("record Blubb(S a) { *(S *a) { otherStuff(); } }");
  tok_recordDecls(tok);
  print(join(tok));
  assertEqualsVerbose(1, l(jfindAll(tok, "*(S *a)")));
  
  // with ...
  tok = jtok("record Blubb(S a) { *(S... *a) { otherStuff(); } }");
  tok_recordDecls(tok);
  print(join(tok));
  assertEqualsVerbose(1, l(jfindAll(tok, "*(S... *a)")));
  
  // !customConstructor
  tok = jtok([[record Blubb(S a) {
    // !customConstructor
    Blubb(S a) { otherStuff(); }
  }]]);
  tok_recordDecls(tok);
  print(join(tok));
  assertEqualsVerbose(0, l(jfindAll(tok, "*(S *a)")));
  
  // !customConstructor in some inner class
  tok = jtok([[record Blubb(S a) {
    class Bla {
      // !customConstructor
    }
  }]]);
  tok_recordDecls(tok);
  print(join(tok));
  assertEqualsVerbose(1, l(jfindAll(tok, "*(S *a)")));  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1025409
Snippet name: test_tok_recordDecls
Eternal ID of this version: #1025409/14
Text MD5: 5d60535f52260f63e087400532ce94af
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-07 21:58:51
Source code size: 2249 bytes / 83 lines
Pitched / IR pitched: No / No
Views / Downloads: 147 / 299
Version history: 13 change(s)
Referenced in: [show references]