mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
test frameworks: reduce duplication of MapSerializerUtil
GitOrigin-RevId: 15a5693a7815c62bdc77be6e4c512ffc00d0bd94
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f61d720f31
commit
310550fcb6
@@ -2,6 +2,7 @@
|
||||
package com.intellij.rt.testng;
|
||||
|
||||
import com.intellij.rt.execution.junit.ComparisonFailureData;
|
||||
import com.intellij.rt.execution.junit.MapSerializerUtil;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.internal.ConstructorOrMethod;
|
||||
@@ -250,7 +251,7 @@ public class IDEATestNGRemoteListener {
|
||||
attrs.put("message", "");
|
||||
}
|
||||
myPrintStream.println();
|
||||
myPrintStream.println(MapSerializerUtil.asString("testFailed", attrs));
|
||||
myPrintStream.println(MapSerializerUtil.asString(MapSerializerUtil.TEST_FAILED, attrs));
|
||||
onTestFinished(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.rt.testng;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class MapSerializerUtil {
|
||||
private static final String STD_EX_SUFFIX =
|
||||
"Valid property list format is (name( )*=( )*\'escaped_value\'( )*)* where escape simbol is \"|\"";
|
||||
|
||||
|
||||
/**
|
||||
* String escaping info provider.
|
||||
*/
|
||||
public interface EscapeInfoProvider {
|
||||
/**
|
||||
* Converts character to its representation in the final string
|
||||
* @param c character to convert
|
||||
* @return character representation or 0 if conversion is not applicable to that character
|
||||
*/
|
||||
char escape(char c);
|
||||
|
||||
/**
|
||||
* Escape character to use before escaped characters (before character representations generated by {@link #escape(char)} method)
|
||||
* @return see above
|
||||
*/
|
||||
char escapeCharacter();
|
||||
}
|
||||
|
||||
public static final EscapeInfoProvider STD_ESCAPER = new EscapeInfoProvider() {
|
||||
public char escape(final char c) {
|
||||
switch (c) {
|
||||
case '\n': return 'n';
|
||||
case '\r': return 'r';
|
||||
case '\b': return 'b';
|
||||
case '\u0085': return 'x'; // next-line character
|
||||
case '\u2028': return 'l'; // line-separator character
|
||||
case '\u2029': return 'p'; // paragraph-separator character
|
||||
case '|': return '|';
|
||||
case '\'': return '\'';
|
||||
case '[': return '[';
|
||||
case ']': return ']';
|
||||
default:return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public char escapeCharacter() {
|
||||
return '|';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Escapes characters specified by provider with '\' and specified character.
|
||||
* @param str initial string
|
||||
* @param p escape info provider.
|
||||
* @return escaped string.
|
||||
*/
|
||||
public static String escapeStr(final String str, EscapeInfoProvider p) {
|
||||
if (str == null) return null;
|
||||
int finalCount = calcFinalEscapedStringCount(str, p);
|
||||
|
||||
if (str.length() == finalCount) return str;
|
||||
|
||||
char[] resultChars = new char[finalCount];
|
||||
int resultPos = 0;
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char c = str.charAt(i);
|
||||
final char escaped = p.escape(c);
|
||||
if (escaped != 0) {
|
||||
resultChars[resultPos++] = p.escapeCharacter();
|
||||
resultChars[resultPos++] = escaped;
|
||||
}
|
||||
else {
|
||||
resultChars[resultPos++] = c;
|
||||
}
|
||||
}
|
||||
|
||||
if (resultPos != finalCount) {
|
||||
throw new RuntimeException("Incorrect escaping for '" + str + "'");
|
||||
}
|
||||
return new String(resultChars);
|
||||
}
|
||||
|
||||
private static int calcFinalEscapedStringCount(final String name, final EscapeInfoProvider p) {
|
||||
int result = 0;
|
||||
for (int i = 0; i < name.length(); i++) {
|
||||
char c = name.charAt(i);
|
||||
if (p.escape(c) != 0) {
|
||||
result += 2;
|
||||
}
|
||||
else {
|
||||
result += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String asString(final String messageName, final Map<String, String> attributes) {
|
||||
String text = "##teamcity[" + messageName;
|
||||
for (final String attrName : attributes.keySet()) {
|
||||
text += " " + attrName + "='" + escapeStr(attributes.get(attrName), STD_ESCAPER) + "'";
|
||||
}
|
||||
text += "]";
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user