JsonPath仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
3.1 KiB

package com.jayway.jsonpath;
import com.jayway.jsonpath.internal.filter.eval.ExpressionEvaluator;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Created by IntelliJ IDEA.
* User: kallestenflo
* Date: 2/4/11
* Time: 9:32 PM
*/
public class ExpressionEvalTest {
@Test
public void long_eval() throws Exception {
assertTrue(ExpressionEvaluator.eval(1L, "==", "1"));
assertTrue(ExpressionEvaluator.eval(2L, "!=", "1"));
assertTrue(ExpressionEvaluator.eval(2L, ">", "1"));
assertTrue(ExpressionEvaluator.eval(2L, ">=", "1"));
assertTrue(ExpressionEvaluator.eval(2L, ">=", "2"));
assertTrue(ExpressionEvaluator.eval(1L, "<", "2"));
assertTrue(ExpressionEvaluator.eval(2L, "<=", "2"));
assertFalse(ExpressionEvaluator.eval(1, ">", "2"));
assertFalse(ExpressionEvaluator.eval(1, ">=", "2"));
assertFalse(ExpressionEvaluator.eval(2, "<", "1"));
assertFalse(ExpressionEvaluator.eval(2, "<=", "1"));
assertFalse(ExpressionEvaluator.eval(1, "==", "2"));
assertFalse(ExpressionEvaluator.eval(1, "!=", "1"));
}
@Test
public void double_eval() throws Exception {
assertTrue(ExpressionEvaluator.eval(1D, "==", "1"));
assertTrue(ExpressionEvaluator.eval(2D, "!=", "1"));
assertTrue(ExpressionEvaluator.eval(2D, ">", "1"));
assertTrue(ExpressionEvaluator.eval(2D, ">=", "1"));
assertTrue(ExpressionEvaluator.eval(2D, ">=", "2"));
assertTrue(ExpressionEvaluator.eval(1D, "<", "2"));
assertTrue(ExpressionEvaluator.eval(2D, "<=", "2"));
assertFalse(ExpressionEvaluator.eval(1D, ">", "2"));
assertFalse(ExpressionEvaluator.eval(1D, ">=", "2"));
assertFalse(ExpressionEvaluator.eval(2D, "<", "1"));
assertFalse(ExpressionEvaluator.eval(2D, "<=", "1"));
assertFalse(ExpressionEvaluator.eval(1D, "==", "2"));
assertFalse(ExpressionEvaluator.eval(1D, "!=", "1"));
}
@Test
public void string_eval() throws Exception {
assertTrue(ExpressionEvaluator.eval("A", "==", "A"));
assertTrue(ExpressionEvaluator.eval("B", "!=", "A"));
}
@Test
public void boolean_eval() throws Exception {
assertTrue(ExpressionEvaluator.eval(true, "==", "true"));
assertTrue(ExpressionEvaluator.eval(false, "==", "false"));
assertTrue(ExpressionEvaluator.eval(true, "!=", "false"));
assertTrue(ExpressionEvaluator.eval(true, "<>", "false"));
assertTrue(ExpressionEvaluator.eval(false, "!=", "true"));
assertTrue(ExpressionEvaluator.eval(false, "<>", "true"));
assertFalse(ExpressionEvaluator.eval(true, "==", "false"));
assertFalse(ExpressionEvaluator.eval(false, "==", "true"));
assertFalse(ExpressionEvaluator.eval(true, "!=", "true"));
assertFalse(ExpressionEvaluator.eval(true, "<>", "true"));
assertFalse(ExpressionEvaluator.eval(false, "!=", "false"));
assertFalse(ExpressionEvaluator.eval(false, "<>", "false"));
}
}