コード例 #1
0
  private static String rangeString(String text, int startOffset, int endOffset) {
    int startLine = StringUtil.offsetToLineNumber(text, startOffset);
    int endLine = StringUtil.offsetToLineNumber(text, endOffset);

    int startCol = startOffset - StringUtil.lineColToOffset(text, startLine, 0);
    int endCol = endOffset - StringUtil.lineColToOffset(text, endLine, 0);

    if (startLine == endLine) {
      return String.format("(%d:%d/%d)", startLine + 1, startCol + 1, endCol - startCol);
    }
    return String.format("(%d:%d..%d:%d)", startLine + 1, endLine + 1, startCol + 1, endCol + 1);
  }
コード例 #2
0
  public void checkResult(Collection<HighlightInfo> infos, String text, @Nullable String filePath) {
    if (filePath == null) {
      VirtualFile virtualFile = myFile == null ? null : myFile.getVirtualFile();
      filePath =
          virtualFile == null ? null : virtualFile.getUserData(VfsTestUtil.TEST_DATA_FILE_PATH);
    }
    String fileName = myFile == null ? "" : myFile.getName() + ": ";
    String failMessage = "";

    for (HighlightInfo info : reverseCollection(infos)) {
      if (!expectedInfosContainsInfo(info)) {
        final int startOffset = info.startOffset;
        final int endOffset = info.endOffset;
        String s = text.substring(startOffset, endOffset);
        String desc = info.getDescription();

        int y1 = StringUtil.offsetToLineNumber(text, startOffset);
        int y2 = StringUtil.offsetToLineNumber(text, endOffset);
        int x1 = startOffset - StringUtil.lineColToOffset(text, y1, 0);
        int x2 = endOffset - StringUtil.lineColToOffset(text, y2, 0);

        if (!failMessage.isEmpty()) failMessage += '\n';
        failMessage +=
            fileName
                + "Extra text fragment highlighted "
                + "("
                + (x1 + 1)
                + ", "
                + (y1 + 1)
                + ")"
                + "-"
                + "("
                + (x2 + 1)
                + ", "
                + (y2 + 1)
                + ")"
                + " :'"
                + s
                + "'"
                + (desc == null ? "" : " (" + desc + ")")
                + " ["
                + info.type
                + "]";
      }
    }

    final Collection<ExpectedHighlightingSet> expectedHighlights = highlightingTypes.values();
    for (ExpectedHighlightingSet highlightingSet : reverseCollection(expectedHighlights)) {
      final Set<HighlightInfo> expInfos = highlightingSet.infos;
      for (HighlightInfo expectedInfo : expInfos) {
        if (!infosContainsExpectedInfo(infos, expectedInfo) && highlightingSet.enabled) {
          final int startOffset = expectedInfo.startOffset;
          final int endOffset = expectedInfo.endOffset;
          String s = text.substring(startOffset, endOffset);
          String desc = expectedInfo.getDescription();

          int y1 = StringUtil.offsetToLineNumber(text, startOffset);
          int y2 = StringUtil.offsetToLineNumber(text, endOffset);
          int x1 = startOffset - StringUtil.lineColToOffset(text, y1, 0);
          int x2 = endOffset - StringUtil.lineColToOffset(text, y2, 0);

          if (!failMessage.isEmpty()) failMessage += '\n';
          failMessage +=
              fileName
                  + "Text fragment was not highlighted "
                  + "("
                  + (x1 + 1)
                  + ", "
                  + (y1 + 1)
                  + ")"
                  + "-"
                  + "("
                  + (x2 + 1)
                  + ", "
                  + (y2 + 1)
                  + ")"
                  + " :'"
                  + s
                  + "'"
                  + (desc == null ? "" : " (" + desc + ")");
        }
      }
    }

    if (!failMessage.isEmpty()) {
      compareTexts(infos, text, failMessage + "\n", filePath);
    }
  }
コード例 #3
0
  public void checkLineMarkers(Collection<LineMarkerInfo> markerInfos, String text) {
    String fileName = myFile == null ? "" : myFile.getName() + ": ";
    String failMessage = "";

    if (markerInfos != null) {
      for (LineMarkerInfo info : markerInfos) {
        if (!containsLineMarker(info, lineMarkerInfos.values())) {
          final int startOffset = info.startOffset;
          final int endOffset = info.endOffset;

          int y1 = StringUtil.offsetToLineNumber(text, startOffset);
          int y2 = StringUtil.offsetToLineNumber(text, endOffset);
          int x1 = startOffset - StringUtil.lineColToOffset(text, y1, 0);
          int x2 = endOffset - StringUtil.lineColToOffset(text, y2, 0);

          if (!failMessage.isEmpty()) failMessage += '\n';
          failMessage +=
              fileName
                  + "Extra line marker highlighted "
                  + "("
                  + (x1 + 1)
                  + ", "
                  + (y1 + 1)
                  + ")"
                  + "-"
                  + "("
                  + (x2 + 1)
                  + ", "
                  + (y2 + 1)
                  + ")"
                  + ": '"
                  + info.getLineMarkerTooltip()
                  + "'";
        }
      }
    }

    for (LineMarkerInfo expectedLineMarker : lineMarkerInfos.values()) {
      if (markerInfos != null && !containsLineMarker(expectedLineMarker, markerInfos)) {
        final int startOffset = expectedLineMarker.startOffset;
        final int endOffset = expectedLineMarker.endOffset;

        int y1 = StringUtil.offsetToLineNumber(text, startOffset);
        int y2 = StringUtil.offsetToLineNumber(text, endOffset);
        int x1 = startOffset - StringUtil.lineColToOffset(text, y1, 0);
        int x2 = endOffset - StringUtil.lineColToOffset(text, y2, 0);

        if (!failMessage.isEmpty()) failMessage += '\n';
        failMessage +=
            fileName
                + "Line marker was not highlighted "
                + "("
                + (x1 + 1)
                + ", "
                + (y1 + 1)
                + ")"
                + "-"
                + "("
                + (x2 + 1)
                + ", "
                + (y2 + 1)
                + ")"
                + ": '"
                + expectedLineMarker.getLineMarkerTooltip()
                + "'";
      }
    }

    if (!failMessage.isEmpty()) Assert.fail(failMessage);
  }