本文整理了Java中org.mozilla.zest.core.v1.ZestVariables.setVariable()
方法的一些代码示例,展示了ZestVariables.setVariable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZestVariables.setVariable()
方法的具体详情如下:
包路径:org.mozilla.zest.core.v1.ZestVariables
类名称:ZestVariables
方法名:setVariable
[英]Sets the token.
[中]设置令牌。
代码示例来源:origin: mozilla/zest
@Override
public void setVariable(String name, String value) {
vars.setVariable(name, value);
}
代码示例来源:origin: mozilla/zest
@Override
public void setVariable(String name, String value) {
if (this.debug) {
String val = value;
if (val != null) {
if (val.length() > 80) {
val = val.substring(0, 80) + "...";
}
// Put on one line and strip duplicate whitespace - this is just for basic debuging
val = val.replace("\n", "\\n");
val = val.replace("\r", "\\r");
val = val.replaceAll("\\s", " ");
}
this.debug("Set " + name + " = " + val);
}
this.variables.setVariable(name, value);
}
代码示例来源:origin: mozilla/zest
@Override
public ZestVariables deepCopy() {
ZestVariables zt = new ZestVariables();
zt.setTokenStart(this.tokenStart);
zt.setTokenEnd(this.tokenEnd);
for (Entry<String, String> entry : tokens.entrySet()) {
zt.setVariable(entry.getKey(), entry.getValue());
}
return zt;
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldReplaceVariablesInVariablesInString() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
zestVars.setVariable("Var1", "-1 < " + token(zestVars, "Var2"));
zestVars.setVariable("Var2", token(zestVars, "Var3"));
zestVars.setVariable("Var3", "1");
String string = token(zestVars, "Var1") + " <= " + token(zestVars, "Var3");
// When
String finalString = zestVars.replaceInString(string, false);
// Then
assertTrue("-1 < 1 <= 1".equals(finalString));
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldReplaceVariablesInString() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
zestVars.setVariable("Var1", "0");
zestVars.setVariable(null, "1");
zestVars.setVariable("Var3", null);
String string =
token(zestVars, "Var1")
+ " < "
+ token(zestVars, null)
+ " != ["
+ token(zestVars, "Var3")
+ "]";
// When
String finalString = zestVars.replaceInString(string, false);
// Then
assertTrue("0 < 1 != []".equals(finalString));
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldSetVariable() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
// When
zestVars.setVariable(VAR_NAME, VAR_NAME);
// Then
assertTrue(zestVars.getVariables().size() == 1);
assertTrue(VAR_NAME.equals(zestVars.getVariables().get(0)[0]));
assertTrue(VAR_NAME.equals(zestVars.getVariables().get(0)[1]));
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldSetVariableWithNullValue() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
String value = null;
// When
zestVars.setVariable(VAR_NAME, value);
// Then
assertTrue(zestVars.getVariables().size() == 1);
assertTrue(VAR_NAME.equals(zestVars.getVariables().get(0)[0]));
assertTrue(zestVars.getVariables().get(0)[1] == value);
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldReplaceEncodedVariablesInString() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
zestVars.setVariable("Var%", "0");
zestVars.setVariable(null, "1");
zestVars.setVariable("Var&", null);
String string =
urlencoded(token(zestVars, "Var%"))
+ " < "
+ token(zestVars, null)
+ " != ["
+ urlencoded(token(zestVars, "Var&"))
+ "]";
boolean encode = true;
// When
String finalString = zestVars.replaceInString(string, encode);
// Then
assertTrue("0 < 1 != []".equals(finalString));
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldSetVariableWithNullName() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
String name = null;
// When
zestVars.setVariable(name, VAR_VALUE);
// Then
assertTrue(zestVars.getVariables().size() == 1);
assertTrue(zestVars.getVariables().get(0)[0] == null);
assertTrue(zestVars.getVariables().get(0)[1] == VAR_VALUE);
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldReplaceVariablesInEncodedVariablesInString() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
zestVars.setVariable("Var%", "-1 < " + token(zestVars, "Var&"));
zestVars.setVariable("Var&", urlencoded(token(zestVars, "Var?")));
zestVars.setVariable("Var?", "1");
String string =
urlencoded(token(zestVars, "Var%")) + " <= " + urlencoded(token(zestVars, "Var?"));
boolean encode = true;
// When
String finalString = zestVars.replaceInString(string, encode);
// Then
assertTrue("-1 < 1 <= 1".equals(finalString));
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldReplaceLoopingVariablesInVariablesInString() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
zestVars.setVariable("Var1", "No Loop: " + token(zestVars, "Var2"));
zestVars.setVariable("Var2", "[" + token(zestVars, "Var3") + "]");
zestVars.setVariable("Var3", token(zestVars, "Var2"));
String string = token(zestVars, "Var1") + " | " + token(zestVars, "Var3");
// When
String finalString = zestVars.replaceInString(string, false);
// Then
assertTrue(
("No Loop: [" + token(zestVars, "Var2") + "] | " + token(zestVars, "Var2"))
.equals(finalString));
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldSetVariables() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
Map<String, String> vars = new HashMap<>();
String varName1 = "Var1";
String varValue1 = "Value1";
vars.put(varName1, varValue1);
String varName2 = "Var2";
String varValue2 = "Value2";
vars.put(varName2, varValue2);
String varName3 = "Var3";
String varValue3 = null;
vars.put(varName3, varValue3);
// When
zestVars.setVariable(vars);
// Then
assertTrue(zestVars.getVariables().size() == 3);
assertTrue(varName1.equals(zestVars.getVariables().get(0)[0]));
assertTrue(varValue1.equals(zestVars.getVariables().get(0)[1]));
assertTrue(varName2.equals(zestVars.getVariables().get(1)[0]));
assertTrue(varValue2.equals(zestVars.getVariables().get(1)[1]));
assertTrue(varName3.equals(zestVars.getVariables().get(2)[0]));
assertTrue(zestVars.getVariables().get(2)[1] == varValue3);
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldReplaceLoopingVariablesInEncodedVariablesInString() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
zestVars.setVariable("Var1", "No Loop: " + token(zestVars, "Var2"));
zestVars.setVariable("Var2", "[" + token(zestVars, "Var3") + "]");
zestVars.setVariable("Var3", token(zestVars, "Var2"));
String string =
urlencoded(token(zestVars, "Var1")) + " | " + urlencoded(token(zestVars, "Var3"));
boolean encode = true;
// When
String finalString = zestVars.replaceInString(string, encode);
// Then
assertTrue(
("No Loop: ["
+ token(zestVars, "Var2")
+ "] | "
+ urlencoded(token(zestVars, "Var3")))
.equals(finalString));
}
内容来源于网络,如有侵权,请联系作者删除!