Ejemplo n.º 1
0
  @Test
  public void ControlCharTest() throws Exception {

    String input = "\\cC";
    String expectedOutput = "C";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.ControlChar));
    assertThat(token.getText(), is(expectedOutput));

    input = "\\cX";
    expectedOutput = "X";
    token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.ControlChar));
    assertThat(token.getText(), is(expectedOutput));
  }
Ejemplo n.º 2
0
  @Test
  public void NotWordCharTest() throws Exception {

    String input = "\\W";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.NotWordChar));
  }
Ejemplo n.º 3
0
  @Test
  public void NotVerticalWhiteSpaceTest() throws Exception {

    String input = "\\V";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.NotVerticalWhiteSpace));
  }
Ejemplo n.º 4
0
  @Test
  public void NewLineSequenceTest() throws Exception {

    String input = "\\R";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.NewLineSequence));
  }
Ejemplo n.º 5
0
  @Test
  public void NotDecimalDigitTest() throws Exception {

    String input = "\\D";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.NotDecimalDigit));
  }
Ejemplo n.º 6
0
  @Test
  public void ExtendedUnicodeCharTest() throws Exception {

    String input = "\\X";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.ExtendedUnicodeChar));
  }
Ejemplo n.º 7
0
  @Test
  public void PreviousMatchInSubjectTest() throws Exception {

    String input = "\\G";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.PreviousMatchInSubject));
  }
Ejemplo n.º 8
0
  @Test
  public void ResetStartMatchTest() throws Exception {

    String input = "\\K";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.ResetStartMatch));
  }
Ejemplo n.º 9
0
 private int getStringOrCommentIndent(int offset) {
   CommonToken tokenContainingOffset = getTokenStrictlyContainingOffset(offset);
   CommonToken token = getStartOfStringToken(tokenContainingOffset);
   if (token != null) {
     int type = token.getType();
     int start = token.getCharPositionInLine();
     if (token.getStartIndex() < offset) {
       switch (type) {
         case STRING_LITERAL:
         case STRING_START:
         case ASTRING_LITERAL:
           return start + 1;
         case STRING_MID:
         case STRING_END:
         case MULTI_COMMENT:
           return start + 1;
           // uncomment to get a bigger indent
           //                    return start+3;
         case VERBATIM_STRING:
         case AVERBATIM_STRING:
           return start + 3;
       }
     }
   }
   return -1;
 }
Ejemplo n.º 10
0
  @Test
  public void OneDataUnitTest() throws Exception {

    String input = "\\C";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.OneDataUnit));
  }
Ejemplo n.º 11
0
  @Test
  public void EndOfSubjectTest() throws Exception {

    String input = "\\z";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.EndOfSubject));
  }
Ejemplo n.º 12
0
 private String getExtraIndent(CommonToken token) {
   String extraIndent = "";
   switch (token.getType()) {
     case MULTI_COMMENT:
       // uncomment to get a bigger indent
       //            if (document.getLineOfOffset(command.offset) <
       //                document.getLineOfOffset(token.getStopIndex())) {
       //                extraIndent="   ";
       //            }
       //            else {
       extraIndent = " ";
       //            }
       break;
     case STRING_MID:
     case STRING_END:
       extraIndent = "  ";
       break;
     case STRING_LITERAL:
     case ASTRING_LITERAL:
     case STRING_START:
       extraIndent = " ";
       break;
     case VERBATIM_STRING:
     case AVERBATIM_STRING:
       extraIndent = "   ";
       break;
   }
   return extraIndent;
 }
Ejemplo n.º 13
0
  @Test
  public void NonWordBoundaryTest() throws Exception {

    String input = "\\B";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.NonWordBoundary));
  }
Ejemplo n.º 14
0
 @Test
 public void VUCTest() throws Exception {
   String input = "V";
   CommonToken token = getToken(input);
   assertThat(token.getType(), is(PCRELexer.VUC));
   assertThat(token.getText(), is(input));
 }
Ejemplo n.º 15
0
  @Test
  public void CharWithoutPropertyTest() throws Exception {

    for (String property : PCRELexer.propertySet) {
      CommonToken token = getToken(String.format("\\P{%s}", property));
      assertThat(token.getType(), is(PCRELexer.CharWithoutProperty));
    }
  }
Ejemplo n.º 16
0
  @Test
  public void AmpersandTest() throws Exception {

    String input = "&";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.Ampersand));
    assertThat(token.getText(), is(input));
  }
Ejemplo n.º 17
0
  @Test
  public void UnderscoreTest() throws Exception {

    String input = "_";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.Underscore));
    assertThat(token.getText(), is(input));
  }
Ejemplo n.º 18
0
  @Test
  public void SingleQuoteTest() throws Exception {

    String input = "'";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.SingleQuote));
    assertThat(token.getText(), is(input));
  }
Ejemplo n.º 19
0
  @Test
  public void GreaterThanTest() throws Exception {

    String input = ">";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.GreaterThan));
    assertThat(token.getText(), is(input));
  }
Ejemplo n.º 20
0
  @Test
  public void POSIXNegatedNamedSetTest() throws Exception {

    for (String name : PCRELexer.namedSet) {
      CommonToken token = getToken(String.format("[[:^%s:]]", name));
      assertThat(token.getType(), is(PCRELexer.POSIXNegatedNamedSet));
    }
  }
Ejemplo n.º 21
0
  @Test
  public void SubroutineOrNamedReferenceStartGTest() throws Exception {

    String input = "\\g";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.SubroutineOrNamedReferenceStartG));
    assertThat(token.getText(), is(input));
  }
Ejemplo n.º 22
0
  @Test
  public void OpenBraceTest() throws Exception {

    String input = "{";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.OpenBrace));
    assertThat(token.getText(), is(input));
  }
Ejemplo n.º 23
0
  @Test
  public void QuestionMarkTest() throws Exception {

    String input = "?";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.QuestionMark));
    assertThat(token.getText(), is(input));
  }
Ejemplo n.º 24
0
  @Test
  public void NamedReferenceStartKTest() throws Exception {

    String input = "\\k";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.NamedReferenceStartK));
    assertThat(token.getText(), is(input));
  }
Ejemplo n.º 25
0
 private int getTokenTypeOfCharacterAtOffset(int offset) {
   int tokenIndex = getTokenIndexAtCharacter(tokens, offset);
   if (tokenIndex >= 0) {
     CommonToken token = tokens.get(tokenIndex);
     return token.getType();
   }
   return -1;
 }
Ejemplo n.º 26
0
  @Test
  public void CloseParenTest() throws Exception {

    String input = ")";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.CloseParen));
    assertThat(token.getText(), is(input));
  }
Ejemplo n.º 27
0
 private CommonToken getStartOfStringToken(CommonToken token) {
   if (token == null) {
     return null;
   }
   int type = token.getType();
   if (type == STRING_MID || type == STRING_END) {
     while (type != STRING_START) {
       int index = token.getTokenIndex();
       if (index == 0) {
         return null;
       }
       token = tokens.get(index - 1);
       type = token.getType();
     }
   }
   return token;
 }
Ejemplo n.º 28
0
  @Test
  public void CharacterClassEndTest() throws Exception {

    String input = "]";
    CommonToken token = getToken(input);
    assertThat(token.getType(), is(PCRELexer.CharacterClassEnd));
    assertThat(token.getText(), is(input));
  }
Ejemplo n.º 29
0
 private boolean isInheritanceClause(CommonToken t) {
   if (t == null) return false;
   int tt = t.getType();
   return tt == CeylonLexer.EXTENDS
       || tt == CeylonLexer.CASE_TYPES
       || tt == CeylonLexer.TYPE_CONSTRAINT
       || tt == CeylonLexer.SATISFIES;
 }
Ejemplo n.º 30
0
  @Test
  public void BackslashTest() throws Exception {

    CommonToken token = getToken("\\");

    assertThat(token.getType(), is(PCRELexer.Backslash));
    assertThat(token.getText(), is("\\"));
  }