Migrate Java tests to Truth.
RELNOTES: None.
PiperOrigin-RevId: 157446717
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java b/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java
index 6cda0b7..4450b67 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java
@@ -14,23 +14,20 @@
package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
+import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assert.fail;
import com.google.devtools.build.lib.syntax.util.EvaluationTestCase;
-
+import java.util.Arrays;
+import java.util.Map;
+import java.util.TreeMap;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.TreeMap;
-
/**
- * Tests for {@link BaseFunction}.
- * This tests the argument processing by BaseFunction
- * between the outer call(posargs, kwargs, ast, env) and the inner call(args, ast, env).
+ * Tests for {@link BaseFunction}. This tests the argument processing by BaseFunction between the
+ * outer call(posargs, kwargs, ast, env) and the inner call(args, ast, env).
*/
@RunWith(JUnit4.class)
public class BaseFunctionTest extends EvaluationTestCase {
@@ -56,16 +53,18 @@
update(func.getName(), func);
if (expectedOutput.charAt(0) == '[') { // a tuple => expected to pass
- assertEquals("Wrong output for " + callExpression,
- expectedOutput, eval(callExpression).toString());
+ assertWithMessage("Wrong output for " + callExpression)
+ .that(eval(callExpression).toString())
+ .isEqualTo(expectedOutput);
} else { // expected to fail with an exception
try {
eval(callExpression);
fail();
} catch (EvalException e) {
- assertEquals("Wrong exception for " + callExpression,
- expectedOutput, e.getMessage());
+ assertWithMessage("Wrong exception for " + callExpression)
+ .that(e.getMessage())
+ .isEqualTo(expectedOutput);
}
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java b/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java
index a710481..dbab997 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java
@@ -14,9 +14,6 @@
package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.syntax.SkylarkList.Tuple;
@@ -59,14 +56,14 @@
"",
"x = [1,2,'foo',4] + [1,2, \"%s%d\" % ('foo', 1)]");
- assertTrue(buildfile.exec(env, getEventHandler()));
+ assertThat(buildfile.exec(env, getEventHandler())).isTrue();
// Test final environment is correctly modified:
//
// input1.BUILD contains:
// x = [1,2,'foo',4] + [1,2, "%s%d" % ('foo', 1)]
- assertEquals(SkylarkList.createImmutable(Tuple.of(1, 2, "foo", 4, 1, 2, "foo1")),
- env.lookup("x"));
+ assertThat(env.lookup("x"))
+ .isEqualTo(SkylarkList.createImmutable(Tuple.of(1, 2, "foo", 4, 1, 2, "foo1")));
}
@Test
@@ -78,9 +75,9 @@
"",
"z = x + y");
- assertFalse(buildfile.exec(env, getEventHandler()));
+ assertThat(buildfile.exec(env, getEventHandler())).isFalse();
Event e = assertContainsError("unsupported operand type(s) for +: 'int' and 'list'");
- assertEquals(4, e.getLocation().getStartLineAndColumn().getLine());
+ assertThat(e.getLocation().getStartLineAndColumn().getLine()).isEqualTo(4);
}
@Test
@@ -97,10 +94,9 @@
parseBuildFile("foo() bar() something = baz() bar()");
Event event = assertContainsError("syntax error at \'bar\': expected newline");
- assertEquals("/a/build/file/BUILD",
- event.getLocation().getPath().toString());
- assertEquals(1, event.getLocation().getStartLineAndColumn().getLine());
- assertTrue(buildFileAST.containsErrors());
+ assertThat(event.getLocation().getPath().toString()).isEqualTo("/a/build/file/BUILD");
+ assertThat(event.getLocation().getStartLineAndColumn().getLine()).isEqualTo(1);
+ assertThat(buildFileAST.containsErrors()).isTrue();
}
@Test
@@ -109,11 +105,10 @@
BuildFileAST buildFileAST = parseBuildFile("a = 'foo' 'bar'");
Event event = assertContainsError(
"Implicit string concatenation is forbidden, use the + operator");
- assertEquals("/a/build/file/BUILD",
- event.getLocation().getPath().toString());
- assertEquals(1, event.getLocation().getStartLineAndColumn().getLine());
- assertEquals(10, event.getLocation().getStartLineAndColumn().getColumn());
- assertTrue(buildFileAST.containsErrors());
+ assertThat(event.getLocation().getPath().toString()).isEqualTo("/a/build/file/BUILD");
+ assertThat(event.getLocation().getStartLineAndColumn().getLine()).isEqualTo(1);
+ assertThat(event.getLocation().getStartLineAndColumn().getColumn()).isEqualTo(10);
+ assertThat(buildFileAST.containsErrors()).isTrue();
}
@Test
@@ -122,11 +117,10 @@
BuildFileAST buildFileAST = parseBuildFile("a = 'foo'\n 'bar'");
Event event = assertContainsError("indentation error");
- assertEquals("/a/build/file/BUILD",
- event.getLocation().getPath().toString());
- assertEquals(2, event.getLocation().getStartLineAndColumn().getLine());
- assertEquals(2, event.getLocation().getStartLineAndColumn().getColumn());
- assertTrue(buildFileAST.containsErrors());
+ assertThat(event.getLocation().getPath().toString()).isEqualTo("/a/build/file/BUILD");
+ assertThat(event.getLocation().getStartLineAndColumn().getLine()).isEqualTo(2);
+ assertThat(event.getLocation().getStartLineAndColumn().getColumn()).isEqualTo(2);
+ assertThat(buildFileAST.containsErrors()).isTrue();
}
@Test
@@ -140,9 +134,9 @@
"cc_library(name = 'cc',",
" srcs = libs,",
" includes = [ abi + opt_level + '/include' ])");
- assertTrue(buildFile.containsErrors());
+ assertThat(buildFile.containsErrors()).isTrue();
assertContainsError("syntax error at '+': expected expression");
- assertFalse(buildFile.exec(env, getEventHandler()));
+ assertThat(buildFile.exec(env, getEventHandler())).isFalse();
MoreAsserts.assertDoesNotContainEvent(getEventCollector(), "$error$");
// This message should not be printed anymore.
MoreAsserts.assertDoesNotContainEvent(getEventCollector(), "contains syntax error(s)");
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EnvironmentTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EnvironmentTest.java
index 9f14759..8001f4e 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/EnvironmentTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/EnvironmentTest.java
@@ -15,8 +15,6 @@
package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import com.google.common.collect.Sets;
@@ -41,9 +39,9 @@
// Test the API directly
@Test
public void testLookupAndUpdate() throws Exception {
- assertNull(lookup("foo"));
+ assertThat(lookup("foo")).isNull();
update("foo", "bar");
- assertEquals("bar", lookup("foo"));
+ assertThat(lookup("foo")).isEqualTo("bar");
}
@Test
@@ -56,17 +54,17 @@
@Test
public void testDoubleUpdateSucceeds() throws Exception {
update("VERSION", 42);
- assertEquals(42, lookup("VERSION"));
+ assertThat(lookup("VERSION")).isEqualTo(42);
update("VERSION", 43);
- assertEquals(43, lookup("VERSION"));
+ assertThat(lookup("VERSION")).isEqualTo(43);
}
// Test assign through interpreter, lookup through API:
@Test
public void testAssign() throws Exception {
- assertNull(lookup("foo"));
+ assertThat(lookup("foo")).isNull();
eval("foo = 'bar'");
- assertEquals("bar", lookup("foo"));
+ assertThat(lookup("foo")).isEqualTo("bar");
}
// Test update through API, reference through interpreter:
@@ -80,7 +78,7 @@
assertThat(e).hasMessage("name 'foo' is not defined");
}
update("foo", "bar");
- assertEquals("bar", eval("foo"));
+ assertThat(eval("foo")).isEqualTo("bar");
}
// Test assign and reference through interpreter:
@@ -94,7 +92,7 @@
assertThat(e).hasMessage("name 'foo' is not defined");
}
eval("foo = 'bar'");
- assertEquals("bar", eval("foo"));
+ assertThat(eval("foo")).isEqualTo("bar");
}
@Test
@@ -116,71 +114,71 @@
.update("quux", 42);
}
- assertEquals(
- Sets.newHashSet(
- "foo",
- "wiz",
- "False",
- "None",
- "True",
- "-",
- "all",
- "any",
- "bool",
- "dict",
- "dir",
- "enumerate",
- "fail",
- "getattr",
- "hasattr",
- "hash",
- "int",
- "len",
- "list",
- "max",
- "min",
- "print",
- "range",
- "repr",
- "reversed",
- "sorted",
- "str",
- "tuple",
- "zip"),
- outerEnv.getVariableNames());
- assertEquals(
- Sets.newHashSet(
- "foo",
- "wiz",
- "quux",
- "False",
- "None",
- "True",
- "-",
- "all",
- "any",
- "bool",
- "dict",
- "dir",
- "enumerate",
- "fail",
- "getattr",
- "hasattr",
- "hash",
- "int",
- "len",
- "list",
- "max",
- "min",
- "print",
- "range",
- "repr",
- "reversed",
- "sorted",
- "str",
- "tuple",
- "zip"),
- innerEnv.getVariableNames());
+ assertThat(outerEnv.getVariableNames())
+ .isEqualTo(
+ Sets.newHashSet(
+ "foo",
+ "wiz",
+ "False",
+ "None",
+ "True",
+ "-",
+ "all",
+ "any",
+ "bool",
+ "dict",
+ "dir",
+ "enumerate",
+ "fail",
+ "getattr",
+ "hasattr",
+ "hash",
+ "int",
+ "len",
+ "list",
+ "max",
+ "min",
+ "print",
+ "range",
+ "repr",
+ "reversed",
+ "sorted",
+ "str",
+ "tuple",
+ "zip"));
+ assertThat(innerEnv.getVariableNames())
+ .isEqualTo(
+ Sets.newHashSet(
+ "foo",
+ "wiz",
+ "quux",
+ "False",
+ "None",
+ "True",
+ "-",
+ "all",
+ "any",
+ "bool",
+ "dict",
+ "dir",
+ "enumerate",
+ "fail",
+ "getattr",
+ "hasattr",
+ "hash",
+ "int",
+ "len",
+ "list",
+ "max",
+ "min",
+ "print",
+ "range",
+ "repr",
+ "reversed",
+ "sorted",
+ "str",
+ "tuple",
+ "zip"));
}
@Test
@@ -210,12 +208,12 @@
.setEventHandler(Environment.FAIL_FAST_HANDLER)
.build();
env.update("x", 1);
- assertEquals(1, env.lookup("x"));
+ assertThat(env.lookup("x")).isEqualTo(1);
env.update("y", 2);
- assertEquals(2, env.lookup("y"));
- assertEquals(1, env.lookup("x"));
+ assertThat(env.lookup("y")).isEqualTo(2);
+ assertThat(env.lookup("x")).isEqualTo(1);
env.update("x", 3);
- assertEquals(3, env.lookup("x"));
+ assertThat(env.lookup("x")).isEqualTo(3);
}
try {
// This update to an existing variable should fail because the environment was frozen.
@@ -299,15 +297,18 @@
BuildFileAST.eval(env, "special_var = 41");
throw new AssertionError("failed to fail");
} catch (EvalException e) {
- assertThat(e.getMessage()).contains("Variable special_var is read only");
+ assertThat(e).hasMessageThat().contains("Variable special_var is read only");
}
try {
BuildFileAST.eval(env, "def foo(x): x += global_var; global_var = 36; return x", "foo(1)");
throw new AssertionError("failed to fail");
} catch (EvalExceptionWithStackTrace e) {
- assertThat(e.getMessage()).contains("Variable 'global_var' is referenced before assignment. "
- + "The variable is defined in the global scope.");
+ assertThat(e)
+ .hasMessageThat()
+ .contains(
+ "Variable 'global_var' is referenced before assignment. "
+ + "The variable is defined in the global scope.");
}
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java
index e5f669e..94e50ae 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java
@@ -15,9 +15,6 @@
package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -81,38 +78,38 @@
@Test
public void testDataTypeNames() throws Exception {
- assertEquals("string", EvalUtils.getDataTypeName("foo"));
- assertEquals("int", EvalUtils.getDataTypeName(3));
- assertEquals("tuple", EvalUtils.getDataTypeName(Tuple.of(1, 2, 3)));
- assertEquals("list", EvalUtils.getDataTypeName(makeList(null)));
- assertEquals("dict", EvalUtils.getDataTypeName(makeDict(null)));
- assertEquals("NoneType", EvalUtils.getDataTypeName(Runtime.NONE));
- assertEquals("MockClassA", EvalUtils.getDataTypeName(new MockClassA()));
- assertEquals("MockClassA", EvalUtils.getDataTypeName(new MockClassB()));
+ assertThat(EvalUtils.getDataTypeName("foo")).isEqualTo("string");
+ assertThat(EvalUtils.getDataTypeName(3)).isEqualTo("int");
+ assertThat(EvalUtils.getDataTypeName(Tuple.of(1, 2, 3))).isEqualTo("tuple");
+ assertThat(EvalUtils.getDataTypeName(makeList(null))).isEqualTo("list");
+ assertThat(EvalUtils.getDataTypeName(makeDict(null))).isEqualTo("dict");
+ assertThat(EvalUtils.getDataTypeName(Runtime.NONE)).isEqualTo("NoneType");
+ assertThat(EvalUtils.getDataTypeName(new MockClassA())).isEqualTo("MockClassA");
+ assertThat(EvalUtils.getDataTypeName(new MockClassB())).isEqualTo("MockClassA");
}
@Test
public void testDatatypeMutabilityPrimitive() throws Exception {
- assertTrue(EvalUtils.isImmutable("foo"));
- assertTrue(EvalUtils.isImmutable(3));
+ assertThat(EvalUtils.isImmutable("foo")).isTrue();
+ assertThat(EvalUtils.isImmutable(3)).isTrue();
}
@Test
public void testDatatypeMutabilityShallow() throws Exception {
- assertTrue(EvalUtils.isImmutable(Tuple.of(1, 2, 3)));
+ assertThat(EvalUtils.isImmutable(Tuple.of(1, 2, 3))).isTrue();
// Mutability depends on the environment.
- assertTrue(EvalUtils.isImmutable(makeList(null)));
- assertTrue(EvalUtils.isImmutable(makeDict(null)));
- assertFalse(EvalUtils.isImmutable(makeList(env)));
- assertFalse(EvalUtils.isImmutable(makeDict(env)));
+ assertThat(EvalUtils.isImmutable(makeList(null))).isTrue();
+ assertThat(EvalUtils.isImmutable(makeDict(null))).isTrue();
+ assertThat(EvalUtils.isImmutable(makeList(env))).isFalse();
+ assertThat(EvalUtils.isImmutable(makeDict(env))).isFalse();
}
@Test
public void testDatatypeMutabilityDeep() throws Exception {
- assertTrue(EvalUtils.isImmutable(Tuple.<Object>of(makeList(null))));
+ assertThat(EvalUtils.isImmutable(Tuple.<Object>of(makeList(null)))).isTrue();
- assertFalse(EvalUtils.isImmutable(Tuple.<Object>of(makeList(env))));
+ assertThat(EvalUtils.isImmutable(Tuple.<Object>of(makeList(env)))).isFalse();
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
index 6e826bd..bd4f18c 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
@@ -14,9 +14,6 @@
package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.syntax.SkylarkList.MutableList;
@@ -355,13 +352,13 @@
// list
Object x = eval("[1,2] + [3,4]");
assertThat((Iterable<Object>) x).containsExactly(1, 2, 3, 4).inOrder();
- assertEquals(MutableList.of(env, 1, 2, 3, 4), x);
- assertFalse(EvalUtils.isImmutable(x));
+ assertThat(x).isEqualTo(MutableList.of(env, 1, 2, 3, 4));
+ assertThat(EvalUtils.isImmutable(x)).isFalse();
// tuple
x = eval("(1,2) + (3,4)");
- assertEquals(Tuple.of(1, 2, 3, 4), x);
- assertTrue(EvalUtils.isImmutable(x));
+ assertThat(x).isEqualTo(Tuple.of(1, 2, 3, 4));
+ assertThat(EvalUtils.isImmutable(x)).isTrue();
checkEvalError("unsupported operand type(s) for +: 'tuple' and 'list'",
"(1,2) + [3,4]"); // list + tuple
@@ -533,10 +530,10 @@
@Test
public void testDictComprehensions_ToString() throws Exception {
- assertEquals("{x: x for x in [1, 2]}",
- parseExpression("{x : x for x in [1, 2]}").toString());
- assertEquals("{x + \"a\": x for x in [1, 2]}",
- parseExpression("{x + 'a' : x for x in [1, 2]}").toString());
+ assertThat(parseExpression("{x : x for x in [1, 2]}").toString())
+ .isEqualTo("{x: x for x in [1, 2]}");
+ assertThat(parseExpression("{x + 'a' : x for x in [1, 2]}").toString())
+ .isEqualTo("{x + \"a\": x for x in [1, 2]}");
}
@Test
@@ -573,7 +570,7 @@
// TODO(fwe): cannot be handled by current testing suite
SelectorList x = (SelectorList) eval("select({'foo': ['FOO'], 'bar': ['BAR']}) + []");
List<Object> elements = x.getElements();
- assertThat(elements.size()).isEqualTo(2);
+ assertThat(elements).hasSize(2);
assertThat(elements.get(0)).isInstanceOf(SelectorValue.class);
assertThat((Iterable<Object>) elements.get(1)).isEmpty();
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ExceptionTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ExceptionTest.java
index b91e9c2..77a5a80 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ExceptionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ExceptionTest.java
@@ -16,7 +16,6 @@
import static com.google.common.truth.Truth.assertThat;
import com.google.devtools.build.lib.events.Location;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -32,7 +31,8 @@
public void testEmptyMessage() throws Exception {
EvalExceptionWithStackTrace ex =
new EvalExceptionWithStackTrace(new NullPointerException(), DUMMY_NODE);
- assertThat(ex.getMessage())
+ assertThat(ex)
+ .hasMessageThat()
.contains("Null Pointer: ExceptionTest.testEmptyMessage() in ExceptionTest.java:");
}
@@ -47,6 +47,6 @@
private void runExceptionTest(Exception toThrow, Exception expectedCause) {
EvalExceptionWithStackTrace ex = new EvalExceptionWithStackTrace(toThrow, DUMMY_NODE);
- assertThat(ex.getCause()).isEqualTo(expectedCause);
+ assertThat(ex).hasCauseThat().isEqualTo(expectedCause);
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java b/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java
index 258d219..0103669 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java
@@ -14,8 +14,6 @@
package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.syntax.util.EvaluationTestCase;
@@ -38,7 +36,7 @@
" a = 1",
" b = a\n");
UserDefinedFunction stmt = (UserDefinedFunction) lookup("func");
- assertNotNull(stmt);
+ assertThat(stmt).isNotNull();
assertThat(stmt.getName()).isEqualTo("func");
assertThat(stmt.getFunctionSignature().getSignature().getShape().getMandatoryPositionals())
.isEqualTo(3);
@@ -82,7 +80,7 @@
eval("def func():",
" a = 2",
"func()\n");
- assertEquals(1, lookup("a"));
+ assertThat(lookup("a")).isEqualTo(1);
}
@Test
@@ -92,7 +90,7 @@
" b = a",
" return b",
"c = func()\n");
- assertEquals(1, lookup("c"));
+ assertThat(lookup("c")).isEqualTo(1);
}
@Test
@@ -103,7 +101,7 @@
" b = a",
" return b",
"c = func()\n");
- assertEquals(2, lookup("c"));
+ assertThat(lookup("c")).isEqualTo(2);
}
@Test
@@ -138,7 +136,7 @@
" a = 3",
" return b",
"c = func()\n");
- assertEquals(2, lookup("c"));
+ assertThat(lookup("c")).isEqualTo(2);
}
@SuppressWarnings("unchecked")
@@ -153,7 +151,7 @@
eval("def func():",
" return 2",
"b = func()\n");
- assertEquals(2, lookup("b"));
+ assertThat(lookup("b")).isEqualTo(2);
}
@Test
@@ -162,7 +160,7 @@
" for i in [1, 2, 3, 4, 5]:",
" return i",
"b = func()\n");
- assertEquals(1, lookup("b"));
+ assertThat(lookup("b")).isEqualTo(1);
}
@Test
@@ -174,8 +172,8 @@
" return b",
"c = func(0)",
"d = func(1)\n");
- assertEquals(1, lookup("c"));
- assertEquals(2, lookup("d"));
+ assertThat(lookup("c")).isEqualTo(1);
+ assertThat(lookup("d")).isEqualTo(2);
}
@Test
@@ -199,14 +197,14 @@
"def func1():",
" return func2()",
"b = func1()\n");
- assertEquals(1, lookup("b"));
+ assertThat(lookup("b")).isEqualTo(1);
}
@Test
public void testSingleLineFunction() throws Exception {
eval("def func(): return 'a'",
"s = func()\n");
- assertEquals("a", lookup("s"));
+ assertThat(lookup("s")).isEqualTo("a");
}
@Test
@@ -214,7 +212,7 @@
eval("def func(): return {'a' : 1}",
"d = func()",
"a = d['a']\n");
- assertEquals(1, lookup("a"));
+ assertThat(lookup("a")).isEqualTo(1);
}
@Test
@@ -222,7 +220,7 @@
eval("def func(): return [1, 2, 3]",
"d = func()",
"a = d[1]\n");
- assertEquals(2, lookup("a"));
+ assertThat(lookup("a")).isEqualTo(2);
}
@SuppressWarnings("unchecked")
@@ -241,7 +239,7 @@
"def func(d):",
" d += {'a' : 2}",
"func(d)");
- assertEquals(ImmutableMap.of("a", 1), lookup("d"));
+ assertThat(lookup("d")).isEqualTo(ImmutableMap.of("a", 1));
}
@Test
@@ -250,7 +248,7 @@
" return a + 1",
"alias = func",
"r = alias(1)");
- assertEquals(2, lookup("r"));
+ assertThat(lookup("r")).isEqualTo(2);
}
@Test
@@ -258,7 +256,7 @@
eval("def func(a, b, c):",
" return a + b + c",
"v = func(1, c = 2, b = 3)");
- assertEquals(6, lookup("v"));
+ assertThat(lookup("v")).isEqualTo(6);
}
private String functionWithOptionalArgs() {
@@ -278,10 +276,10 @@
"v2 = func(b = 2, a = '2', c = 2)",
"v3 = func('3')",
"v4 = func('4', c = 1)\n");
- assertEquals("1abc", lookup("v1"));
- assertEquals("2abc", lookup("v2"));
- assertEquals("3a", lookup("v3"));
- assertEquals("4ac", lookup("v4"));
+ assertThat(lookup("v1")).isEqualTo("1abc");
+ assertThat(lookup("v2")).isEqualTo("2abc");
+ assertThat(lookup("v3")).isEqualTo("3a");
+ assertThat(lookup("v4")).isEqualTo("4ac");
}
@Test
@@ -292,10 +290,10 @@
"v2 = func(b = 'x', a = 'a', c = 'y')",
"v3 = func('a')",
"v4 = func('a', c = 'y')\n");
- assertEquals("axy", lookup("v1"));
- assertEquals("axy", lookup("v2"));
- assertEquals("abc", lookup("v3"));
- assertEquals("aby", lookup("v4"));
+ assertThat(lookup("v1")).isEqualTo("axy");
+ assertThat(lookup("v2")).isEqualTo("axy");
+ assertThat(lookup("v3")).isEqualTo("abc");
+ assertThat(lookup("v4")).isEqualTo("aby");
}
@Test
@@ -328,11 +326,11 @@
"v1 = foo(**args)",
"v2 = foo('x', c = 'c', d = 'e', **{'b': 'y'})",
"v3 = foo(c = 'z', a = 'x', **{'b': 'y', 'd': 'f'})");
- assertEquals("xbzd", lookup("v1"));
- assertEquals("xyce", lookup("v2"));
- assertEquals("xyzf", lookup("v3"));
+ assertThat(lookup("v1")).isEqualTo("xbzd");
+ assertThat(lookup("v2")).isEqualTo("xyce");
+ assertThat(lookup("v3")).isEqualTo("xyzf");
UserDefinedFunction foo = (UserDefinedFunction) lookup("foo");
- assertEquals("foo(a, b = \"b\", *, c, d = \"d\")", foo.toString());
+ assertThat(foo.toString()).isEqualTo("foo(a, b = \"b\", *, c, d = \"d\")");
}
@Test
@@ -385,14 +383,14 @@
" a = 3",
" return foo()",
"v = bar()\n");
- assertEquals(2, lookup("v"));
+ assertThat(lookup("v")).isEqualTo(2);
}
@Test
public void testMixingPositionalOptional() throws Exception {
eval("def f(name, value = '', optional = ''): return value",
"v = f('name', 'value')\n");
- assertEquals("value", lookup("v"));
+ assertThat(lookup("v")).isEqualTo("value");
}
@Test
@@ -402,10 +400,10 @@
"v2 = f('0', *['name', 'value'])",
"v3 = f('0', *['b'], optional = '3')",
"v4 = f(*[],name='a')\n");
- assertEquals("namevalue2", lookup("v1"));
- assertEquals("0namevalue", lookup("v2"));
- assertEquals("0b3", lookup("v3"));
- assertEquals("a12", lookup("v4"));
+ assertThat(lookup("v1")).isEqualTo("namevalue2");
+ assertThat(lookup("v2")).isEqualTo("0namevalue");
+ assertThat(lookup("v3")).isEqualTo("0b3");
+ assertThat(lookup("v4")).isEqualTo("a12");
}
@Test
@@ -419,11 +417,11 @@
"v3 = f('a', *['b', 'c', 'd'], mandatory = 'y', optional = 'z')",
"v4 = f(*['a'], **{'value': 'b', 'mandatory': 'c'})",
"v5 = f('a', 'b', 'c', *['d', 'e'], mandatory = 'f', **{'optional': 'g'})\n");
- assertEquals("abz2|", lookup("v1"));
- assertEquals("abz2|cd", lookup("v2"));
- assertEquals("abyz|cd", lookup("v3"));
- assertEquals("abc2|", lookup("v4"));
- assertEquals("abfg|cde", lookup("v5"));
+ assertThat(lookup("v1")).isEqualTo("abz2|");
+ assertThat(lookup("v2")).isEqualTo("abz2|cd");
+ assertThat(lookup("v3")).isEqualTo("abyz|cd");
+ assertThat(lookup("v4")).isEqualTo("abc2|");
+ assertThat(lookup("v5")).isEqualTo("abfg|cde");
}
@Test
@@ -436,8 +434,8 @@
"v1 = f('a', 'b', 'c', 'd', 'e')",
"v2 = f('a', optional='b', value='c')",
"v3 = f('a')");
- assertEquals("abc|de", lookup("v1"));
- assertEquals("acb|", lookup("v2"));
- assertEquals("a12|", lookup("v3"));
+ assertThat(lookup("v1")).isEqualTo("abc|de");
+ assertThat(lookup("v2")).isEqualTo("acb|");
+ assertThat(lookup("v3")).isEqualTo("a12|");
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/GlobCriteriaTest.java b/src/test/java/com/google/devtools/build/lib/syntax/GlobCriteriaTest.java
index ba70c5a..c75633a 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/GlobCriteriaTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/GlobCriteriaTest.java
@@ -14,14 +14,10 @@
package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.google.devtools.build.lib.testutil.Suite;
import com.google.devtools.build.lib.testutil.TestSpec;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -36,7 +32,7 @@
@Test
public void testParse_EmptyList() throws Exception {
GlobCriteria gc = GlobCriteria.parse("[]");
- assertFalse(gc.isGlob());
+ assertThat(gc.isGlob()).isFalse();
assertThat(gc.getIncludePatterns()).isEmpty();
assertThat(gc.getExcludePatterns()).isEmpty();
}
@@ -44,7 +40,7 @@
@Test
public void testParse_SingleList() throws Exception {
GlobCriteria gc = GlobCriteria.parse("['abc']");
- assertFalse(gc.isGlob());
+ assertThat(gc.isGlob()).isFalse();
assertThat(gc.getIncludePatterns()).containsExactly("abc");
assertThat(gc.getExcludePatterns()).isEmpty();
}
@@ -52,7 +48,7 @@
@Test
public void testParse_MultipleList() throws Exception {
GlobCriteria gc = GlobCriteria.parse("['abc', 'def', 'ghi']");
- assertFalse(gc.isGlob());
+ assertThat(gc.isGlob()).isFalse();
assertThat(gc.getIncludePatterns()).containsExactly("abc", "def", "ghi").inOrder();
assertThat(gc.getExcludePatterns()).isEmpty();
}
@@ -60,7 +56,7 @@
@Test
public void testParse_EmptyGlob() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob([])");
- assertTrue(gc.isGlob());
+ assertThat(gc.isGlob()).isTrue();
assertThat(gc.getIncludePatterns()).isEmpty();
assertThat(gc.getExcludePatterns()).isEmpty();
}
@@ -68,7 +64,7 @@
@Test
public void testParse_SingleGlob() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob(['abc'])");
- assertTrue(gc.isGlob());
+ assertThat(gc.isGlob()).isTrue();
assertThat(gc.getIncludePatterns()).containsExactly("abc");
assertThat(gc.getExcludePatterns()).isEmpty();
}
@@ -76,7 +72,7 @@
@Test
public void testParse_MultipleGlob() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob(['abc', 'def', 'ghi'])");
- assertTrue(gc.isGlob());
+ assertThat(gc.isGlob()).isTrue();
assertThat(gc.getIncludePatterns()).containsExactly("abc", "def", "ghi").inOrder();
assertThat(gc.getExcludePatterns()).isEmpty();
}
@@ -84,7 +80,7 @@
@Test
public void testParse_EmptyGlobWithExclude() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob([], exclude=['xyz'])");
- assertTrue(gc.isGlob());
+ assertThat(gc.isGlob()).isTrue();
assertThat(gc.getIncludePatterns()).isEmpty();
assertThat(gc.getExcludePatterns()).containsExactly("xyz");
}
@@ -92,7 +88,7 @@
@Test
public void testParse_SingleGlobWithExclude() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob(['abc'], exclude=['xyz'])");
- assertTrue(gc.isGlob());
+ assertThat(gc.isGlob()).isTrue();
assertThat(gc.getIncludePatterns()).containsExactly("abc");
assertThat(gc.getExcludePatterns()).containsExactly("xyz");
}
@@ -100,7 +96,7 @@
@Test
public void testParse_MultipleGlobWithExclude() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob(['abc', 'def', 'ghi'], exclude=['xyz'])");
- assertTrue(gc.isGlob());
+ assertThat(gc.isGlob()).isTrue();
assertThat(gc.getIncludePatterns()).containsExactly("abc", "def", "ghi").inOrder();
assertThat(gc.getExcludePatterns()).containsExactly("xyz");
}
@@ -109,7 +105,7 @@
public void testParse_MultipleGlobWithMultipleExclude() throws Exception {
GlobCriteria gc = GlobCriteria.parse(
"glob(['abc', 'def', 'ghi'], exclude=['rst', 'uvw', 'xyz'])");
- assertTrue(gc.isGlob());
+ assertThat(gc.isGlob()).isTrue();
assertThat(gc.getIncludePatterns()).containsExactly("abc", "def", "ghi").inOrder();
assertThat(gc.getExcludePatterns()).containsExactly("rst", "uvw", "xyz").inOrder();
}
@@ -117,7 +113,7 @@
@Test
public void testParse_GlobWithSlashesAndWildcards() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob(['java/src/net/jsunit/*.java'])");
- assertTrue(gc.isGlob());
+ assertThat(gc.isGlob()).isTrue();
assertThat(gc.getIncludePatterns()).containsExactly("java/src/net/jsunit/*.java");
assertThat(gc.getExcludePatterns()).isEmpty();
}
@@ -125,7 +121,7 @@
@Test
public void testParse_ExcludeWithInvalidLabel() throws Exception {
GlobCriteria gc = GlobCriteria.parse("glob(['abc', 'def', 'ghi'], exclude=['xyz~'])");
- assertTrue(gc.isGlob());
+ assertThat(gc.isGlob()).isTrue();
assertThat(gc.getIncludePatterns()).containsExactly("abc", "def", "ghi").inOrder();
assertThat(gc.getExcludePatterns()).containsExactly("xyz~");
}
@@ -190,6 +186,6 @@
builder.append("]");
String s = builder.toString();
GlobCriteria gc = GlobCriteria.parse(s);
- assertEquals(s, gc.toString());
+ assertThat(gc.toString()).isEqualTo(s);
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/GlobListTest.java b/src/test/java/com/google/devtools/build/lib/syntax/GlobListTest.java
index 64419fc..d5da29e 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/GlobListTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/GlobListTest.java
@@ -14,21 +14,16 @@
package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.testutil.Suite;
import com.google.devtools.build.lib.testutil.TestSpec;
-
+import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-import java.util.List;
-
-/**
- * Tests for {@link GlobList}
- */
+/** Tests for {@link GlobList} */
@TestSpec(size = Suite.SMALL_TESTS)
@RunWith(JUnit4.class)
public class GlobListTest {
@@ -36,19 +31,19 @@
@Test
public void testParse_glob() throws Exception {
String expression = "glob(['abc'])";
- assertEquals(expression, GlobList.parse(expression).toExpression());
+ assertThat(GlobList.parse(expression).toExpression()).isEqualTo(expression);
}
@Test
public void testParse_multipleGlobs() throws Exception {
String expression = "glob(['abc']) + glob(['def']) + glob(['ghi'])";
- assertEquals(expression, GlobList.parse(expression).toExpression());
+ assertThat(GlobList.parse(expression).toExpression()).isEqualTo(expression);
}
@Test
public void testParse_multipleLists() throws Exception {
String expression = "['abc'] + ['def'] + ['ghi']";
- assertEquals(expression, GlobList.parse(expression).toExpression());
+ assertThat(GlobList.parse(expression).toExpression()).isEqualTo(expression);
}
@Test
@@ -56,7 +51,7 @@
String expression = "glob(['abc', 'def', 'ghi'], "
+ "exclude=['rst', 'uvw', 'xyz']) "
+ "+ glob(['abc', 'def', 'ghi'], exclude=['rst', 'uvw', 'xyz'])";
- assertEquals(expression, GlobList.parse(expression).toExpression());
+ assertThat(GlobList.parse(expression).toExpression()).isEqualTo(expression);
}
@Test
@@ -66,7 +61,7 @@
GlobList<String> glob2 = GlobList.parse(
"glob(['xyzzy']) + glob(['foo'], exclude=['bar'])");
GlobList<String> cat = GlobList.concat(glob1, glob2);
- assertEquals(glob1.toExpression() + " + " + glob2.toExpression(), cat.toExpression());
+ assertThat(cat.toExpression()).isEqualTo(glob1.toExpression() + " + " + glob2.toExpression());
}
@Test
@@ -75,8 +70,8 @@
"glob(['abc'], exclude=['def']) + glob(['xyz'])");
List<String> list = ImmutableList.of("xyzzy", "foo", "bar");
GlobList<String> cat = GlobList.concat(list, glob);
- assertEquals("['xyzzy', 'foo', 'bar'] + glob(['abc'], exclude=['def']) + glob(['xyz'])",
- cat.toExpression());
+ assertThat(cat.toExpression())
+ .isEqualTo("['xyzzy', 'foo', 'bar'] + glob(['abc'], exclude=['def']) + glob(['xyz'])");
}
@Test
@@ -85,8 +80,8 @@
"glob(['abc'], exclude=['def']) + glob(['xyz'])");
List<String> list = ImmutableList.of("xyzzy", "foo", "bar");
GlobList<String> cat = GlobList.concat(glob, list);
- assertEquals("glob(['abc'], exclude=['def']) + glob(['xyz']) + ['xyzzy', 'foo', 'bar']",
- cat.toExpression());
+ assertThat(cat.toExpression())
+ .isEqualTo("glob(['abc'], exclude=['def']) + glob(['xyz']) + ['xyzzy', 'foo', 'bar']");
}
@Test
@@ -95,10 +90,10 @@
List<String> exclude = ImmutableList.of("rst", "uvw", "xyz");
List<String> matches = ImmutableList.of("xyzzy", "foo", "bar");
GlobList<String> glob = GlobList.captureResults(include, exclude, matches);
- assertEquals(matches, glob);
+ assertThat(glob).isEqualTo(matches);
ImmutableList<GlobCriteria> criteria = glob.getCriteria();
assertThat(criteria).hasSize(1);
- assertEquals(include, criteria.get(0).getIncludePatterns());
- assertEquals(exclude, criteria.get(0).getExcludePatterns());
+ assertThat(criteria.get(0).getIncludePatterns()).isEqualTo(include);
+ assertThat(criteria.get(0).getExcludePatterns()).isEqualTo(exclude);
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/LexerTest.java b/src/test/java/com/google/devtools/build/lib/syntax/LexerTest.java
index b270a54..bf9afdf 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/LexerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/LexerTest.java
@@ -13,9 +13,8 @@
// limitations under the License.
package com.google.devtools.build.lib.syntax;
+import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import com.google.common.eventbus.EventBus;
import com.google.devtools.build.lib.events.Event;
@@ -133,46 +132,47 @@
@Test
public void testBasics1() throws Exception {
- assertEquals("IDENTIFIER RPAREN NEWLINE EOF", names(tokens("wiz) ")));
- assertEquals("IDENTIFIER RPAREN NEWLINE EOF", names(tokens("wiz )")));
- assertEquals("IDENTIFIER RPAREN NEWLINE EOF", names(tokens(" wiz)")));
- assertEquals("IDENTIFIER RPAREN NEWLINE EOF", names(tokens(" wiz ) ")));
- assertEquals("IDENTIFIER RPAREN NEWLINE EOF", names(tokens("wiz\t)")));
+ assertThat(names(tokens("wiz) "))).isEqualTo("IDENTIFIER RPAREN NEWLINE EOF");
+ assertThat(names(tokens("wiz )"))).isEqualTo("IDENTIFIER RPAREN NEWLINE EOF");
+ assertThat(names(tokens(" wiz)"))).isEqualTo("IDENTIFIER RPAREN NEWLINE EOF");
+ assertThat(names(tokens(" wiz ) "))).isEqualTo("IDENTIFIER RPAREN NEWLINE EOF");
+ assertThat(names(tokens("wiz\t)"))).isEqualTo("IDENTIFIER RPAREN NEWLINE EOF");
}
@Test
public void testBasics2() throws Exception {
- assertEquals("RPAREN NEWLINE EOF", names(tokens(")")));
- assertEquals("RPAREN NEWLINE EOF", names(tokens(" )")));
- assertEquals("RPAREN NEWLINE EOF", names(tokens(" ) ")));
- assertEquals("RPAREN NEWLINE EOF", names(tokens(") ")));
+ assertThat(names(tokens(")"))).isEqualTo("RPAREN NEWLINE EOF");
+ assertThat(names(tokens(" )"))).isEqualTo("RPAREN NEWLINE EOF");
+ assertThat(names(tokens(" ) "))).isEqualTo("RPAREN NEWLINE EOF");
+ assertThat(names(tokens(") "))).isEqualTo("RPAREN NEWLINE EOF");
}
@Test
public void testBasics3() throws Exception {
- assertEquals("INT COMMENT NEWLINE INT NEWLINE EOF", names(tokens("123#456\n789")));
- assertEquals("INT COMMENT NEWLINE INT NEWLINE EOF", names(tokens("123 #456\n789")));
- assertEquals("INT COMMENT NEWLINE INT NEWLINE EOF", names(tokens("123#456 \n789")));
- assertEquals("INT COMMENT NEWLINE INDENT INT NEWLINE OUTDENT NEWLINE EOF",
- names(tokens("123#456\n 789")));
- assertEquals("INT COMMENT NEWLINE INT NEWLINE EOF", names(tokens("123#456\n789 ")));
+ assertThat(names(tokens("123#456\n789"))).isEqualTo("INT COMMENT NEWLINE INT NEWLINE EOF");
+ assertThat(names(tokens("123 #456\n789"))).isEqualTo("INT COMMENT NEWLINE INT NEWLINE EOF");
+ assertThat(names(tokens("123#456 \n789"))).isEqualTo("INT COMMENT NEWLINE INT NEWLINE EOF");
+ assertThat(names(tokens("123#456\n 789")))
+ .isEqualTo("INT COMMENT NEWLINE INDENT INT NEWLINE OUTDENT NEWLINE EOF");
+ assertThat(names(tokens("123#456\n789 "))).isEqualTo("INT COMMENT NEWLINE INT NEWLINE EOF");
}
@Test
public void testBasics4() throws Exception {
- assertEquals("NEWLINE EOF", names(tokens("")));
- assertEquals("COMMENT NEWLINE EOF", names(tokens("# foo")));
- assertEquals("INT INT INT INT NEWLINE EOF", names(tokens("1 2 3 4")));
- assertEquals("INT DOT INT NEWLINE EOF", names(tokens("1.234")));
- assertEquals("IDENTIFIER LPAREN IDENTIFIER COMMA IDENTIFIER RPAREN "
- + "NEWLINE EOF", names(tokens("foo(bar, wiz)")));
+ assertThat(names(tokens(""))).isEqualTo("NEWLINE EOF");
+ assertThat(names(tokens("# foo"))).isEqualTo("COMMENT NEWLINE EOF");
+ assertThat(names(tokens("1 2 3 4"))).isEqualTo("INT INT INT INT NEWLINE EOF");
+ assertThat(names(tokens("1.234"))).isEqualTo("INT DOT INT NEWLINE EOF");
+ assertThat(names(tokens("foo(bar, wiz)")))
+ .isEqualTo("IDENTIFIER LPAREN IDENTIFIER COMMA IDENTIFIER RPAREN " + "NEWLINE EOF");
}
@Test
public void testCrLf() throws Exception {
- assertEquals("NEWLINE EOF", names(tokens("\r\n\r\n")));
- assertEquals("NEWLINE INT NEWLINE EOF", names(tokens("\r\n\r1\r\r\n")));
- assertEquals("COMMENT NEWLINE COMMENT NEWLINE EOF", names(tokens("# foo\r\n# bar\r\n")));
+ assertThat(names(tokens("\r\n\r\n"))).isEqualTo("NEWLINE EOF");
+ assertThat(names(tokens("\r\n\r1\r\r\n"))).isEqualTo("NEWLINE INT NEWLINE EOF");
+ assertThat(names(tokens("# foo\r\n# bar\r\n")))
+ .isEqualTo("COMMENT NEWLINE COMMENT NEWLINE EOF");
}
@Test
@@ -181,262 +181,242 @@
// don't consume too many chars.
// decimal
- assertEquals("INT(12345) MINUS NEWLINE EOF", values(tokens("12345-")));
+ assertThat(values(tokens("12345-"))).isEqualTo("INT(12345) MINUS NEWLINE EOF");
// octal
- assertEquals("INT(5349) MINUS NEWLINE EOF", values(tokens("012345-")));
+ assertThat(values(tokens("012345-"))).isEqualTo("INT(5349) MINUS NEWLINE EOF");
// octal (bad)
- assertEquals("INT(0) MINUS NEWLINE EOF", values(tokens("012349-")));
- assertEquals("/some/path.txt:1: invalid base-8 integer constant: 012349",
- lastError.toString());
+ assertThat(values(tokens("012349-"))).isEqualTo("INT(0) MINUS NEWLINE EOF");
+ assertThat(lastError.toString())
+ .isEqualTo("/some/path.txt:1: invalid base-8 integer constant: 012349");
// hexadecimal (uppercase)
- assertEquals("INT(1193055) MINUS NEWLINE EOF", values(tokens("0X12345F-")));
+ assertThat(values(tokens("0X12345F-"))).isEqualTo("INT(1193055) MINUS NEWLINE EOF");
// hexadecimal (lowercase)
- assertEquals("INT(1193055) MINUS NEWLINE EOF", values(tokens("0x12345f-")));
+ assertThat(values(tokens("0x12345f-"))).isEqualTo("INT(1193055) MINUS NEWLINE EOF");
// hexadecimal (lowercase) [note: "g" cause termination of token]
- assertEquals("INT(74565) IDENTIFIER(g) MINUS NEWLINE EOF",
- values(tokens("0x12345g-")));
+ assertThat(values(tokens("0x12345g-"))).isEqualTo("INT(74565) IDENTIFIER(g) MINUS NEWLINE EOF");
}
@Test
public void testIntegersAndDot() throws Exception {
- assertEquals("INT(1) DOT INT(2345) NEWLINE EOF", values(tokens("1.2345")));
+ assertThat(values(tokens("1.2345"))).isEqualTo("INT(1) DOT INT(2345) NEWLINE EOF");
- assertEquals("INT(1) DOT INT(2) DOT INT(345) NEWLINE EOF",
- values(tokens("1.2.345")));
+ assertThat(values(tokens("1.2.345"))).isEqualTo("INT(1) DOT INT(2) DOT INT(345) NEWLINE EOF");
- assertEquals("INT(1) DOT INT(0) NEWLINE EOF", values(tokens("1.23E10")));
- assertEquals("/some/path.txt:1: invalid base-10 integer constant: 23E10",
- lastError.toString());
+ assertThat(values(tokens("1.23E10"))).isEqualTo("INT(1) DOT INT(0) NEWLINE EOF");
+ assertThat(lastError.toString())
+ .isEqualTo("/some/path.txt:1: invalid base-10 integer constant: 23E10");
- assertEquals("INT(1) DOT INT(0) MINUS INT(10) NEWLINE EOF",
- values(tokens("1.23E-10")));
- assertEquals("/some/path.txt:1: invalid base-10 integer constant: 23E",
- lastError.toString());
+ assertThat(values(tokens("1.23E-10"))).isEqualTo("INT(1) DOT INT(0) MINUS INT(10) NEWLINE EOF");
+ assertThat(lastError.toString())
+ .isEqualTo("/some/path.txt:1: invalid base-10 integer constant: 23E");
- assertEquals("DOT INT(123) NEWLINE EOF", values(tokens(". 123")));
- assertEquals("DOT INT(123) NEWLINE EOF", values(tokens(".123")));
- assertEquals("DOT IDENTIFIER(abc) NEWLINE EOF", values(tokens(".abc")));
+ assertThat(values(tokens(". 123"))).isEqualTo("DOT INT(123) NEWLINE EOF");
+ assertThat(values(tokens(".123"))).isEqualTo("DOT INT(123) NEWLINE EOF");
+ assertThat(values(tokens(".abc"))).isEqualTo("DOT IDENTIFIER(abc) NEWLINE EOF");
- assertEquals("IDENTIFIER(foo) DOT INT(123) NEWLINE EOF",
- values(tokens("foo.123")));
- assertEquals("IDENTIFIER(foo) DOT IDENTIFIER(bcd) NEWLINE EOF",
- values(tokens("foo.bcd"))); // 'b' are hex chars
- assertEquals("IDENTIFIER(foo) DOT IDENTIFIER(xyz) NEWLINE EOF",
- values(tokens("foo.xyz")));
+ assertThat(values(tokens("foo.123"))).isEqualTo("IDENTIFIER(foo) DOT INT(123) NEWLINE EOF");
+ assertThat(values(tokens("foo.bcd")))
+ .isEqualTo("IDENTIFIER(foo) DOT IDENTIFIER(bcd) NEWLINE EOF"); // 'b' are hex chars
+ assertThat(values(tokens("foo.xyz")))
+ .isEqualTo("IDENTIFIER(foo) DOT IDENTIFIER(xyz) NEWLINE EOF");
}
@Test
public void testStringDelimiters() throws Exception {
- assertEquals("STRING(foo) NEWLINE EOF", values(tokens("\"foo\"")));
- assertEquals("STRING(foo) NEWLINE EOF", values(tokens("'foo'")));
+ assertThat(values(tokens("\"foo\""))).isEqualTo("STRING(foo) NEWLINE EOF");
+ assertThat(values(tokens("'foo'"))).isEqualTo("STRING(foo) NEWLINE EOF");
}
@Test
public void testQuotesInStrings() throws Exception {
- assertEquals("STRING(foo'bar) NEWLINE EOF", values(tokens("'foo\\'bar'")));
- assertEquals("STRING(foo'bar) NEWLINE EOF", values(tokens("\"foo'bar\"")));
- assertEquals("STRING(foo\"bar) NEWLINE EOF", values(tokens("'foo\"bar'")));
- assertEquals("STRING(foo\"bar) NEWLINE EOF",
- values(tokens("\"foo\\\"bar\"")));
+ assertThat(values(tokens("'foo\\'bar'"))).isEqualTo("STRING(foo'bar) NEWLINE EOF");
+ assertThat(values(tokens("\"foo'bar\""))).isEqualTo("STRING(foo'bar) NEWLINE EOF");
+ assertThat(values(tokens("'foo\"bar'"))).isEqualTo("STRING(foo\"bar) NEWLINE EOF");
+ assertThat(values(tokens("\"foo\\\"bar\""))).isEqualTo("STRING(foo\"bar) NEWLINE EOF");
}
@Test
public void testStringEscapes() throws Exception {
- assertEquals("STRING(a\tb\nc\rd) NEWLINE EOF",
- values(tokens("'a\\tb\\nc\\rd'"))); // \t \r \n
- assertEquals("STRING(x\\hx) NEWLINE EOF",
- values(tokens("'x\\hx'"))); // \h is unknown => "\h"
- assertEquals("STRING(\\$$) NEWLINE EOF", values(tokens("'\\$$'")));
- assertEquals("STRING(ab) NEWLINE EOF",
- values(tokens("'a\\\nb'"))); // escape end of line
- assertEquals("STRING(abcd) NEWLINE EOF",
- values(tokens("\"ab\\ucd\"")));
- assertEquals("/some/path.txt:1: escape sequence not implemented: \\u",
- lastError.toString());
+ assertThat(values(tokens("'a\\tb\\nc\\rd'")))
+ .isEqualTo("STRING(a\tb\nc\rd) NEWLINE EOF"); // \t \r \n
+ assertThat(values(tokens("'x\\hx'")))
+ .isEqualTo("STRING(x\\hx) NEWLINE EOF"); // \h is unknown => "\h"
+ assertThat(values(tokens("'\\$$'"))).isEqualTo("STRING(\\$$) NEWLINE EOF");
+ assertThat(values(tokens("'a\\\nb'")))
+ .isEqualTo("STRING(ab) NEWLINE EOF"); // escape end of line
+ assertThat(values(tokens("\"ab\\ucd\""))).isEqualTo("STRING(abcd) NEWLINE EOF");
+ assertThat(lastError.toString())
+ .isEqualTo("/some/path.txt:1: escape sequence not implemented: \\u");
}
@Test
public void testEscapedCrlfInString() throws Exception {
- assertEquals("STRING(ab) NEWLINE EOF",
- values(tokens("'a\\\r\nb'")));
- assertEquals("STRING(ab) NEWLINE EOF",
- values(tokens("\"a\\\r\nb\"")));
- assertEquals("STRING(ab) NEWLINE EOF",
- values(tokens("\"\"\"a\\\r\nb\"\"\"")));
- assertEquals("STRING(ab) NEWLINE EOF",
- values(tokens("'''a\\\r\nb'''")));
- assertEquals("STRING(a\\\nb) NEWLINE EOF",
- values(tokens("r'a\\\r\nb'")));
- assertEquals("STRING(a\\\nb) NEWLINE EOF",
- values(tokens("r\"a\\\r\nb\"")));
- assertEquals("STRING(a\\\n\\\nb) NEWLINE EOF",
- values(tokens("r\"a\\\r\n\\\nb\"")));
+ assertThat(values(tokens("'a\\\r\nb'"))).isEqualTo("STRING(ab) NEWLINE EOF");
+ assertThat(values(tokens("\"a\\\r\nb\""))).isEqualTo("STRING(ab) NEWLINE EOF");
+ assertThat(values(tokens("\"\"\"a\\\r\nb\"\"\""))).isEqualTo("STRING(ab) NEWLINE EOF");
+ assertThat(values(tokens("'''a\\\r\nb'''"))).isEqualTo("STRING(ab) NEWLINE EOF");
+ assertThat(values(tokens("r'a\\\r\nb'"))).isEqualTo("STRING(a\\\nb) NEWLINE EOF");
+ assertThat(values(tokens("r\"a\\\r\nb\""))).isEqualTo("STRING(a\\\nb) NEWLINE EOF");
+ assertThat(values(tokens("r\"a\\\r\n\\\nb\""))).isEqualTo("STRING(a\\\n\\\nb) NEWLINE EOF");
}
@Test
public void testRawString() throws Exception {
- assertEquals("STRING(abcd) NEWLINE EOF",
- values(tokens("r'abcd'")));
- assertEquals("STRING(abcd) NEWLINE EOF",
- values(tokens("r\"abcd\"")));
- assertEquals("STRING(a\\tb\\nc\\rd) NEWLINE EOF",
- values(tokens("r'a\\tb\\nc\\rd'"))); // r'a\tb\nc\rd'
- assertEquals("STRING(a\\\") NEWLINE EOF",
- values(tokens("r\"a\\\"\""))); // r"a\""
- assertEquals("STRING(a\\\\b) NEWLINE EOF",
- values(tokens("r'a\\\\b'"))); // r'a\\b'
- assertEquals("STRING(ab) IDENTIFIER(r) NEWLINE EOF",
- values(tokens("r'ab'r")));
+ assertThat(values(tokens("r'abcd'"))).isEqualTo("STRING(abcd) NEWLINE EOF");
+ assertThat(values(tokens("r\"abcd\""))).isEqualTo("STRING(abcd) NEWLINE EOF");
+ assertThat(values(tokens("r'a\\tb\\nc\\rd'")))
+ .isEqualTo("STRING(a\\tb\\nc\\rd) NEWLINE EOF"); // r'a\tb\nc\rd'
+ assertThat(values(tokens("r\"a\\\"\""))).isEqualTo("STRING(a\\\") NEWLINE EOF"); // r"a\""
+ assertThat(values(tokens("r'a\\\\b'"))).isEqualTo("STRING(a\\\\b) NEWLINE EOF"); // r'a\\b'
+ assertThat(values(tokens("r'ab'r"))).isEqualTo("STRING(ab) IDENTIFIER(r) NEWLINE EOF");
// Unterminated raw string
values(tokens("r'\\'")); // r'\'
- assertEquals("/some/path.txt:1: unterminated string literal at eof",
- lastError.toString());
+ assertThat(lastError.toString())
+ .isEqualTo("/some/path.txt:1: unterminated string literal at eof");
}
@Test
public void testTripleRawString() throws Exception {
// r'''a\ncd'''
- assertEquals("STRING(ab\\ncd) NEWLINE EOF",
- values(tokens("r'''ab\\ncd'''")));
+ assertThat(values(tokens("r'''ab\\ncd'''"))).isEqualTo("STRING(ab\\ncd) NEWLINE EOF");
// r"""ab
// cd"""
- assertEquals(
- "STRING(ab\ncd) NEWLINE EOF",
- values(tokens("\"\"\"ab\ncd\"\"\"")));
+ assertThat(values(tokens("\"\"\"ab\ncd\"\"\""))).isEqualTo("STRING(ab\ncd) NEWLINE EOF");
// Unterminated raw string
values(tokens("r'''\\'''")); // r'''\'''
- assertEquals("/some/path.txt:1: unterminated string literal at eof",
- lastError.toString());
+ assertThat(lastError.toString())
+ .isEqualTo("/some/path.txt:1: unterminated string literal at eof");
}
@Test
public void testOctalEscapes() throws Exception {
// Regression test for a bug.
- assertEquals("STRING(\0 \1 \t \u003f I I1 \u00ff \u00ff \u00fe) NEWLINE EOF",
- values(tokens("'\\0 \\1 \\11 \\77 \\111 \\1111 \\377 \\777 \\776'")));
+ assertThat(values(tokens("'\\0 \\1 \\11 \\77 \\111 \\1111 \\377 \\777 \\776'")))
+ .isEqualTo("STRING(\0 \1 \t \u003f I I1 \u00ff \u00ff \u00fe) NEWLINE EOF");
// Test boundaries (non-octal char, EOF).
- assertEquals("STRING(\1b \1) NEWLINE EOF", values(tokens("'\\1b \\1'")));
+ assertThat(values(tokens("'\\1b \\1'"))).isEqualTo("STRING(\1b \1) NEWLINE EOF");
}
@Test
public void testTripleQuotedStrings() throws Exception {
- assertEquals("STRING(a\"b'c \n d\"\"e) NEWLINE EOF",
- values(tokens("\"\"\"a\"b'c \n d\"\"e\"\"\"")));
- assertEquals("STRING(a\"b'c \n d\"\"e) NEWLINE EOF",
- values(tokens("'''a\"b'c \n d\"\"e'''")));
+ assertThat(values(tokens("\"\"\"a\"b'c \n d\"\"e\"\"\"")))
+ .isEqualTo("STRING(a\"b'c \n d\"\"e) NEWLINE EOF");
+ assertThat(values(tokens("'''a\"b'c \n d\"\"e'''")))
+ .isEqualTo("STRING(a\"b'c \n d\"\"e) NEWLINE EOF");
}
@Test
public void testBadChar() throws Exception {
- assertEquals("IDENTIFIER(a) IDENTIFIER(b) NEWLINE EOF",
- values(tokens("a$b")));
- assertEquals("/some/path.txt:1: invalid character: '$'",
- lastError.toString());
+ assertThat(values(tokens("a$b"))).isEqualTo("IDENTIFIER(a) IDENTIFIER(b) NEWLINE EOF");
+ assertThat(lastError.toString()).isEqualTo("/some/path.txt:1: invalid character: '$'");
}
@Test
public void testIndentation() throws Exception {
- assertEquals("INT(1) NEWLINE INT(2) NEWLINE INT(3) NEWLINE EOF",
- values(tokens("1\n2\n3")));
- assertEquals("INT(1) NEWLINE INDENT INT(2) NEWLINE INT(3) NEWLINE OUTDENT "
- + "INT(4) NEWLINE EOF", values(tokens("1\n 2\n 3\n4 ")));
- assertEquals("INT(1) NEWLINE INDENT INT(2) NEWLINE INT(3) NEWLINE OUTDENT "
- + "NEWLINE EOF", values(tokens("1\n 2\n 3")));
- assertEquals("INT(1) NEWLINE INDENT INT(2) NEWLINE INDENT INT(3) NEWLINE "
- + "OUTDENT OUTDENT NEWLINE EOF",
- values(tokens("1\n 2\n 3")));
- assertEquals("INT(1) NEWLINE INDENT INT(2) NEWLINE INDENT INT(3) NEWLINE "
- + "OUTDENT INT(4) NEWLINE OUTDENT INT(5) NEWLINE EOF",
- values(tokens("1\n 2\n 3\n 4\n5")));
+ assertThat(values(tokens("1\n2\n3")))
+ .isEqualTo("INT(1) NEWLINE INT(2) NEWLINE INT(3) NEWLINE EOF");
+ assertThat(values(tokens("1\n 2\n 3\n4 ")))
+ .isEqualTo(
+ "INT(1) NEWLINE INDENT INT(2) NEWLINE INT(3) NEWLINE OUTDENT " + "INT(4) NEWLINE EOF");
+ assertThat(values(tokens("1\n 2\n 3")))
+ .isEqualTo("INT(1) NEWLINE INDENT INT(2) NEWLINE INT(3) NEWLINE OUTDENT " + "NEWLINE EOF");
+ assertThat(values(tokens("1\n 2\n 3")))
+ .isEqualTo(
+ "INT(1) NEWLINE INDENT INT(2) NEWLINE INDENT INT(3) NEWLINE "
+ + "OUTDENT OUTDENT NEWLINE EOF");
+ assertThat(values(tokens("1\n 2\n 3\n 4\n5")))
+ .isEqualTo(
+ "INT(1) NEWLINE INDENT INT(2) NEWLINE INDENT INT(3) NEWLINE "
+ + "OUTDENT INT(4) NEWLINE OUTDENT INT(5) NEWLINE EOF");
- assertEquals("INT(1) NEWLINE INDENT INT(2) NEWLINE INDENT INT(3) NEWLINE "
- + "OUTDENT INT(4) NEWLINE OUTDENT INT(5) NEWLINE EOF",
- values(tokens("1\n 2\n 3\n 4\n5")));
- assertEquals("/some/path.txt:4: indentation error", lastError.toString());
+ assertThat(values(tokens("1\n 2\n 3\n 4\n5")))
+ .isEqualTo(
+ "INT(1) NEWLINE INDENT INT(2) NEWLINE INDENT INT(3) NEWLINE "
+ + "OUTDENT INT(4) NEWLINE OUTDENT INT(5) NEWLINE EOF");
+ assertThat(lastError.toString()).isEqualTo("/some/path.txt:4: indentation error");
}
@Test
public void testIndentationWithCrLf() throws Exception {
- assertEquals("INT(1) NEWLINE INDENT INT(2) NEWLINE OUTDENT NEWLINE EOF",
- values(tokens("1\r\n 2\r\n")));
- assertEquals("INT(1) NEWLINE INDENT INT(2) NEWLINE OUTDENT NEWLINE EOF",
- values(tokens("1\r\n 2\r\n\r\n")));
- assertEquals("INT(1) NEWLINE INDENT INT(2) NEWLINE INDENT INT(3) NEWLINE OUTDENT INT(4) "
- + "NEWLINE OUTDENT INT(5) NEWLINE EOF",
- values(tokens("1\r\n 2\r\n 3\r\n 4\r\n5")));
- assertEquals(
- "INT(1) NEWLINE INDENT INT(2) NEWLINE INT(3) NEWLINE OUTDENT INT(4) NEWLINE EOF",
- values(tokens("1\r\n 2\r\n\r\n 3\r\n4")));
+ assertThat(values(tokens("1\r\n 2\r\n")))
+ .isEqualTo("INT(1) NEWLINE INDENT INT(2) NEWLINE OUTDENT NEWLINE EOF");
+ assertThat(values(tokens("1\r\n 2\r\n\r\n")))
+ .isEqualTo("INT(1) NEWLINE INDENT INT(2) NEWLINE OUTDENT NEWLINE EOF");
+ assertThat(values(tokens("1\r\n 2\r\n 3\r\n 4\r\n5")))
+ .isEqualTo(
+ "INT(1) NEWLINE INDENT INT(2) NEWLINE INDENT INT(3) NEWLINE OUTDENT INT(4) "
+ + "NEWLINE OUTDENT INT(5) NEWLINE EOF");
+ assertThat(values(tokens("1\r\n 2\r\n\r\n 3\r\n4")))
+ .isEqualTo(
+ "INT(1) NEWLINE INDENT INT(2) NEWLINE INT(3) NEWLINE OUTDENT INT(4) NEWLINE EOF");
}
@Test
public void testIndentationInsideParens() throws Exception {
// Indentation is ignored inside parens:
- assertEquals("INT(1) LPAREN INT(2) INT(3) INT(4) INT(5) NEWLINE EOF",
- values(tokens("1 (\n 2\n 3\n 4\n5")));
- assertEquals("INT(1) LBRACE INT(2) INT(3) INT(4) INT(5) NEWLINE EOF",
- values(tokens("1 {\n 2\n 3\n 4\n5")));
- assertEquals("INT(1) LBRACKET INT(2) INT(3) INT(4) INT(5) NEWLINE EOF",
- values(tokens("1 [\n 2\n 3\n 4\n5")));
- assertEquals("INT(1) LBRACKET INT(2) RBRACKET NEWLINE INDENT INT(3) "
- + "NEWLINE INT(4) NEWLINE OUTDENT INT(5) NEWLINE EOF",
- values(tokens("1 [\n 2]\n 3\n 4\n5")));
+ assertThat(values(tokens("1 (\n 2\n 3\n 4\n5")))
+ .isEqualTo("INT(1) LPAREN INT(2) INT(3) INT(4) INT(5) NEWLINE EOF");
+ assertThat(values(tokens("1 {\n 2\n 3\n 4\n5")))
+ .isEqualTo("INT(1) LBRACE INT(2) INT(3) INT(4) INT(5) NEWLINE EOF");
+ assertThat(values(tokens("1 [\n 2\n 3\n 4\n5")))
+ .isEqualTo("INT(1) LBRACKET INT(2) INT(3) INT(4) INT(5) NEWLINE EOF");
+ assertThat(values(tokens("1 [\n 2]\n 3\n 4\n5")))
+ .isEqualTo(
+ "INT(1) LBRACKET INT(2) RBRACKET NEWLINE INDENT INT(3) "
+ + "NEWLINE INT(4) NEWLINE OUTDENT INT(5) NEWLINE EOF");
}
@Test
public void testIndentationAtEOF() throws Exception {
// Matching OUTDENTS are created at EOF:
- assertEquals("INDENT INT(1) NEWLINE OUTDENT NEWLINE EOF",
- values(tokens("\n 1")));
+ assertThat(values(tokens("\n 1"))).isEqualTo("INDENT INT(1) NEWLINE OUTDENT NEWLINE EOF");
}
@Test
public void testBlankLineIndentation() throws Exception {
// Blank lines and comment lines should not generate any newlines indents
// (but note that every input ends with NEWLINE EOF).
- assertEquals("COMMENT NEWLINE EOF", names(tokens("\n #\n")));
- assertEquals("COMMENT NEWLINE EOF", names(tokens(" #")));
- assertEquals("COMMENT NEWLINE EOF", names(tokens(" #\n")));
- assertEquals("COMMENT NEWLINE EOF", names(tokens(" #comment\n")));
- assertEquals("DEF IDENTIFIER LPAREN IDENTIFIER RPAREN COLON NEWLINE "
- + "COMMENT INDENT RETURN IDENTIFIER NEWLINE "
- + "OUTDENT NEWLINE EOF",
- names(tokens("def f(x):\n"
- + " # comment\n"
- + "\n"
- + " \n"
- + " return x\n")));
+ assertThat(names(tokens("\n #\n"))).isEqualTo("COMMENT NEWLINE EOF");
+ assertThat(names(tokens(" #"))).isEqualTo("COMMENT NEWLINE EOF");
+ assertThat(names(tokens(" #\n"))).isEqualTo("COMMENT NEWLINE EOF");
+ assertThat(names(tokens(" #comment\n"))).isEqualTo("COMMENT NEWLINE EOF");
+ assertThat(names(tokens("def f(x):\n" + " # comment\n" + "\n" + " \n" + " return x\n")))
+ .isEqualTo(
+ "DEF IDENTIFIER LPAREN IDENTIFIER RPAREN COLON NEWLINE "
+ + "COMMENT INDENT RETURN IDENTIFIER NEWLINE "
+ + "OUTDENT NEWLINE EOF");
}
@Test
public void testMultipleCommentLines() throws Exception {
- assertEquals("COMMENT NEWLINE COMMENT COMMENT COMMENT "
- + "DEF IDENTIFIER LPAREN IDENTIFIER RPAREN COLON NEWLINE "
- + "INDENT RETURN IDENTIFIER NEWLINE OUTDENT NEWLINE EOF",
- names(tokens("# Copyright\n"
- + "#\n"
- + "# A comment line\n"
- + "# An adjoining line\n"
- + "def f(x):\n"
- + " return x\n")));
+ assertThat(
+ names(
+ tokens(
+ "# Copyright\n"
+ + "#\n"
+ + "# A comment line\n"
+ + "# An adjoining line\n"
+ + "def f(x):\n"
+ + " return x\n")))
+ .isEqualTo(
+ "COMMENT NEWLINE COMMENT COMMENT COMMENT "
+ + "DEF IDENTIFIER LPAREN IDENTIFIER RPAREN COLON NEWLINE "
+ + "INDENT RETURN IDENTIFIER NEWLINE OUTDENT NEWLINE EOF");
}
@Test
public void testBackslash() throws Exception {
- assertEquals("IDENTIFIER IDENTIFIER NEWLINE EOF",
- names(tokens("a\\\nb")));
- assertEquals("IDENTIFIER IDENTIFIER NEWLINE EOF", names(tokens("a\\\r\nb")));
- assertEquals("IDENTIFIER ILLEGAL IDENTIFIER NEWLINE EOF",
- names(tokens("a\\ b")));
- assertEquals("IDENTIFIER LPAREN INT RPAREN NEWLINE EOF",
- names(tokens("a(\\\n2)")));
+ assertThat(names(tokens("a\\\nb"))).isEqualTo("IDENTIFIER IDENTIFIER NEWLINE EOF");
+ assertThat(names(tokens("a\\\r\nb"))).isEqualTo("IDENTIFIER IDENTIFIER NEWLINE EOF");
+ assertThat(names(tokens("a\\ b"))).isEqualTo("IDENTIFIER ILLEGAL IDENTIFIER NEWLINE EOF");
+ assertThat(names(tokens("a(\\\n2)"))).isEqualTo("IDENTIFIER LPAREN INT RPAREN NEWLINE EOF");
}
@Test
@@ -450,43 +430,41 @@
@Test
public void testLineNumbers() throws Exception {
- assertEquals("1 1 1 1 2 2 2 2 4 4 4 4 4",
- linenums("foo = 1\nbar = 2\n\nwiz = 3"));
+ assertThat(linenums("foo = 1\nbar = 2\n\nwiz = 3")).isEqualTo("1 1 1 1 2 2 2 2 4 4 4 4 4");
- assertEquals("IDENTIFIER(foo) EQUALS INT(1) NEWLINE "
- + "IDENTIFIER(bar) EQUALS INT(2) NEWLINE "
- + "IDENTIFIER(wiz) EQUALS NEWLINE "
- + "IDENTIFIER(bar) EQUALS INT(2) NEWLINE EOF",
- values(tokens("foo = 1\nbar = 2\n\nwiz = $\nbar = 2")));
- assertEquals("/some/path.txt:4: invalid character: '$'",
- lastError.toString());
+ assertThat(values(tokens("foo = 1\nbar = 2\n\nwiz = $\nbar = 2")))
+ .isEqualTo(
+ "IDENTIFIER(foo) EQUALS INT(1) NEWLINE "
+ + "IDENTIFIER(bar) EQUALS INT(2) NEWLINE "
+ + "IDENTIFIER(wiz) EQUALS NEWLINE "
+ + "IDENTIFIER(bar) EQUALS INT(2) NEWLINE EOF");
+ assertThat(lastError.toString()).isEqualTo("/some/path.txt:4: invalid character: '$'");
// '\\n' in string should not increment linenum:
String s = "1\n'foo\\nbar'\3";
- assertEquals("INT(1) NEWLINE STRING(foo\nbar) NEWLINE EOF",
- values(tokens(s)));
- assertEquals("1 1 2 2 2", linenums(s));
+ assertThat(values(tokens(s))).isEqualTo("INT(1) NEWLINE STRING(foo\nbar) NEWLINE EOF");
+ assertThat(linenums(s)).isEqualTo("1 1 2 2 2");
}
@Test
public void testContainsErrors() throws Exception {
Lexer lexerSuccess = createLexer("foo");
- assertFalse(lexerSuccess.containsErrors());
+ assertThat(lexerSuccess.containsErrors()).isFalse();
Lexer lexerFail = createLexer("f$o");
- assertTrue(lexerFail.containsErrors());
+ assertThat(lexerFail.containsErrors()).isTrue();
String s = "'unterminated";
lexerFail = createLexer(s);
- assertTrue(lexerFail.containsErrors());
- assertEquals(0, lastErrorLocation.getStartOffset());
- assertEquals(s.length(), lastErrorLocation.getEndOffset());
- assertEquals("STRING(unterminated) NEWLINE EOF", values(tokens(s)));
+ assertThat(lexerFail.containsErrors()).isTrue();
+ assertThat(lastErrorLocation.getStartOffset()).isEqualTo(0);
+ assertThat(lastErrorLocation.getEndOffset()).isEqualTo(s.length());
+ assertThat(values(tokens(s))).isEqualTo("STRING(unterminated) NEWLINE EOF");
}
@Test
public void testUnterminatedRawStringWithEscapingError() throws Exception {
- assertEquals("STRING NEWLINE EOF", names(tokens("r'\\")));
- assertEquals("/some/path.txt:1: unterminated string literal at eof", lastError);
+ assertThat(names(tokens("r'\\"))).isEqualTo("STRING NEWLINE EOF");
+ assertThat(lastError).isEqualTo("/some/path.txt:1: unterminated string literal at eof");
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/LineNumberTableTest.java b/src/test/java/com/google/devtools/build/lib/syntax/LineNumberTableTest.java
index 4377b35..e7b4964 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/LineNumberTableTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/LineNumberTableTest.java
@@ -13,12 +13,11 @@
// limitations under the License.
package com.google.devtools.build.lib.syntax;
-import static org.junit.Assert.assertEquals;
+import static com.google.common.truth.Truth.assertThat;
import com.google.devtools.build.lib.events.Location.LineAndColumn;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.PathFragment;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -35,23 +34,23 @@
@Test
public void testEmpty() {
LineNumberTable table = create("");
- assertEquals(new LineAndColumn(1, 1), table.getLineAndColumn(0));
+ assertThat(table.getLineAndColumn(0)).isEqualTo(new LineAndColumn(1, 1));
}
@Test
public void testNewline() {
LineNumberTable table = create("\n");
- assertEquals(new LineAndColumn(1, 1), table.getLineAndColumn(0));
- assertEquals(new LineAndColumn(2, 1), table.getLineAndColumn(1));
+ assertThat(table.getLineAndColumn(0)).isEqualTo(new LineAndColumn(1, 1));
+ assertThat(table.getLineAndColumn(1)).isEqualTo(new LineAndColumn(2, 1));
}
@Test
public void testOneLiner() {
LineNumberTable table = create("foo");
- assertEquals(new LineAndColumn(1, 1), table.getLineAndColumn(0));
- assertEquals(new LineAndColumn(1, 2), table.getLineAndColumn(1));
- assertEquals(new LineAndColumn(1, 3), table.getLineAndColumn(2));
- assertEquals(Pair.of(0, 3), table.getOffsetsForLine(1));
+ assertThat(table.getLineAndColumn(0)).isEqualTo(new LineAndColumn(1, 1));
+ assertThat(table.getLineAndColumn(1)).isEqualTo(new LineAndColumn(1, 2));
+ assertThat(table.getLineAndColumn(2)).isEqualTo(new LineAndColumn(1, 3));
+ assertThat(table.getOffsetsForLine(1)).isEqualTo(Pair.of(0, 3));
}
@Test
@@ -59,29 +58,29 @@
LineNumberTable table = create("\ntwo\nthree\n\nfive\n");
// \n
- assertEquals(new LineAndColumn(1, 1), table.getLineAndColumn(0));
- assertEquals(Pair.of(0, 1), table.getOffsetsForLine(1));
+ assertThat(table.getLineAndColumn(0)).isEqualTo(new LineAndColumn(1, 1));
+ assertThat(table.getOffsetsForLine(1)).isEqualTo(Pair.of(0, 1));
// two\n
- assertEquals(new LineAndColumn(2, 1), table.getLineAndColumn(1));
- assertEquals(new LineAndColumn(2, 2), table.getLineAndColumn(2));
- assertEquals(new LineAndColumn(2, 3), table.getLineAndColumn(3));
- assertEquals(new LineAndColumn(2, 4), table.getLineAndColumn(4));
- assertEquals(Pair.of(1, 5), table.getOffsetsForLine(2));
+ assertThat(table.getLineAndColumn(1)).isEqualTo(new LineAndColumn(2, 1));
+ assertThat(table.getLineAndColumn(2)).isEqualTo(new LineAndColumn(2, 2));
+ assertThat(table.getLineAndColumn(3)).isEqualTo(new LineAndColumn(2, 3));
+ assertThat(table.getLineAndColumn(4)).isEqualTo(new LineAndColumn(2, 4));
+ assertThat(table.getOffsetsForLine(2)).isEqualTo(Pair.of(1, 5));
// three\n
- assertEquals(new LineAndColumn(3, 1), table.getLineAndColumn(5));
- assertEquals(new LineAndColumn(3, 6), table.getLineAndColumn(10));
- assertEquals(Pair.of(5, 11), table.getOffsetsForLine(3));
+ assertThat(table.getLineAndColumn(5)).isEqualTo(new LineAndColumn(3, 1));
+ assertThat(table.getLineAndColumn(10)).isEqualTo(new LineAndColumn(3, 6));
+ assertThat(table.getOffsetsForLine(3)).isEqualTo(Pair.of(5, 11));
// \n
- assertEquals(new LineAndColumn(4, 1), table.getLineAndColumn(11));
- assertEquals(Pair.of(11, 12), table.getOffsetsForLine(4));
+ assertThat(table.getLineAndColumn(11)).isEqualTo(new LineAndColumn(4, 1));
+ assertThat(table.getOffsetsForLine(4)).isEqualTo(Pair.of(11, 12));
// five\n
- assertEquals(new LineAndColumn(5, 1), table.getLineAndColumn(12));
- assertEquals(new LineAndColumn(5, 5), table.getLineAndColumn(16));
- assertEquals(Pair.of(12, 17), table.getOffsetsForLine(5));
+ assertThat(table.getLineAndColumn(12)).isEqualTo(new LineAndColumn(5, 1));
+ assertThat(table.getLineAndColumn(16)).isEqualTo(new LineAndColumn(5, 5));
+ assertThat(table.getOffsetsForLine(5)).isEqualTo(Pair.of(12, 17));
}
@Test
@@ -96,25 +95,27 @@
LineNumberTable table = create(data);
// Note: no attempt is made to return accurate column information.
- assertEquals(new LineAndColumn(67, 1), table.getLineAndColumn(data.indexOf("cc_binary")));
- assertEquals(new LineAndColumn(67, 1), table.getLineAndColumn(data.indexOf("name='a'")));
- assertEquals("/fake/file", table.getPath(0).toString());
+ assertThat(table.getLineAndColumn(data.indexOf("cc_binary")))
+ .isEqualTo(new LineAndColumn(67, 1));
+ assertThat(table.getLineAndColumn(data.indexOf("name='a'")))
+ .isEqualTo(new LineAndColumn(67, 1));
+ assertThat(table.getPath(0).toString()).isEqualTo("/fake/file");
// Note: newlines ignored; "srcs" is still (intentionally) considered to be
// on L67. Consider the alternative, and assume that rule 'a' is 50 lines
// when pretty-printed: the last line of 'a' would be reported as line 67 +
// 50, which may be in a part of the original BUILD file that has nothing
// to do with this rule. In other words, the size of rules before and
// after pretty printing are essentially unrelated.
- assertEquals(new LineAndColumn(67, 1), table.getLineAndColumn(data.indexOf("srcs")));
- assertEquals("/foo", table.getPath(data.indexOf("srcs")).toString());
- assertEquals(Pair.of(2, 57), table.getOffsetsForLine(67));
+ assertThat(table.getLineAndColumn(data.indexOf("srcs"))).isEqualTo(new LineAndColumn(67, 1));
+ assertThat(table.getPath(data.indexOf("srcs")).toString()).isEqualTo("/foo");
+ assertThat(table.getOffsetsForLine(67)).isEqualTo(Pair.of(2, 57));
- assertEquals(new LineAndColumn(23, 1), table.getLineAndColumn(data.indexOf("vardef")));
- assertEquals(new LineAndColumn(23, 1), table.getLineAndColumn(data.indexOf("x,y")));
- assertEquals("/ba.r", table.getPath(data.indexOf("x,y")).toString());
- assertEquals(Pair.of(57, 86), table.getOffsetsForLine(23));
+ assertThat(table.getLineAndColumn(data.indexOf("vardef"))).isEqualTo(new LineAndColumn(23, 1));
+ assertThat(table.getLineAndColumn(data.indexOf("x,y"))).isEqualTo(new LineAndColumn(23, 1));
+ assertThat(table.getPath(data.indexOf("x,y")).toString()).isEqualTo("/ba.r");
+ assertThat(table.getOffsetsForLine(23)).isEqualTo(Pair.of(57, 86));
- assertEquals(Pair.of(0, 0), table.getOffsetsForLine(42));
+ assertThat(table.getOffsetsForLine(42)).isEqualTo(Pair.of(0, 0));
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
index fb9c5cc..6b93e7e 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
@@ -16,7 +16,6 @@
import static com.google.common.truth.Truth.assertThat;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.syntax.SkylarkList.MutableList;
import com.google.devtools.build.lib.syntax.util.EvaluationTestCase;
@@ -1700,7 +1699,7 @@
eval("a = select({'a': 1})");
SelectorList result = (SelectorList) lookup("a");
assertThat(((SelectorValue) Iterables.getOnlyElement(result.getElements())).getDictionary())
- .isEqualTo(ImmutableMap.of("a", 1));
+ .containsExactly("a", 1);
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java
index 467a5ba..ce459d2 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java
@@ -15,23 +15,18 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.util.StringUtilities.joinLines;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
-
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
-/**
- * A test case for {@link ParserInputSource}.
- */
+/** A test case for {@link ParserInputSource}. */
@RunWith(JUnit4.class)
public class ParserInputSourceTest {
@@ -42,8 +37,8 @@
String content = joinLines("Line 1", "Line 2", "Line 3", "");
Path file = scratch.file("/tmp/my/file.txt", content.getBytes(StandardCharsets.UTF_8));
ParserInputSource input = ParserInputSource.create(file);
- assertEquals(content, new String(input.getContent()));
- assertEquals("/tmp/my/file.txt", input.getPath().toString());
+ assertThat(new String(input.getContent())).isEqualTo(content);
+ assertThat(input.getPath().toString()).isEqualTo("/tmp/my/file.txt");
}
@Test
@@ -51,8 +46,8 @@
String content = "Content provided as a string.";
String pathName = "/the/name/of/the/content.txt";
ParserInputSource input = ParserInputSource.create(content, PathFragment.create(pathName));
- assertEquals(content, new String(input.getContent()));
- assertEquals(pathName, input.getPath().toString());
+ assertThat(new String(input.getContent())).isEqualTo(content);
+ assertThat(input.getPath().toString()).isEqualTo(pathName);
}
@Test
@@ -61,8 +56,8 @@
String pathName = "/the/name/of/the/content.txt";
char[] contentChars = content.toCharArray();
ParserInputSource input = ParserInputSource.create(contentChars, PathFragment.create(pathName));
- assertEquals(content, new String(input.getContent()));
- assertEquals(pathName, input.getPath().toString());
+ assertThat(new String(input.getContent())).isEqualTo(content);
+ assertThat(input.getPath().toString()).isEqualTo(pathName);
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
index e107d1b..ad7d1c8 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
@@ -15,9 +15,6 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableList;
@@ -91,35 +88,35 @@
BinaryOperatorExpression e =
(BinaryOperatorExpression) parseExpression("'%sx' % 'foo' + 'bar'");
- assertEquals(Operator.PLUS, e.getOperator());
+ assertThat(e.getOperator()).isEqualTo(Operator.PLUS);
}
@Test
public void testPrecedence2() throws Exception {
BinaryOperatorExpression e =
(BinaryOperatorExpression) parseExpression("('%sx' % 'foo') + 'bar'");
- assertEquals(Operator.PLUS, e.getOperator());
+ assertThat(e.getOperator()).isEqualTo(Operator.PLUS);
}
@Test
public void testPrecedence3() throws Exception {
BinaryOperatorExpression e =
(BinaryOperatorExpression) parseExpression("'%sx' % ('foo' + 'bar')");
- assertEquals(Operator.PERCENT, e.getOperator());
+ assertThat(e.getOperator()).isEqualTo(Operator.PERCENT);
}
@Test
public void testPrecedence4() throws Exception {
BinaryOperatorExpression e =
(BinaryOperatorExpression) parseExpression("1 + - (2 - 3)");
- assertEquals(Operator.PLUS, e.getOperator());
+ assertThat(e.getOperator()).isEqualTo(Operator.PLUS);
}
@Test
public void testPrecedence5() throws Exception {
BinaryOperatorExpression e =
(BinaryOperatorExpression) parseExpression("2 * x | y + 1");
- assertEquals(Operator.PIPE, e.getOperator());
+ assertThat(e.getOperator()).isEqualTo(Operator.PIPE);
}
@Test
@@ -127,14 +124,14 @@
FuncallExpression e = (FuncallExpression) parseExpression("-5");
FuncallExpression e2 = (FuncallExpression) parseExpression("- 5");
- assertEquals("-", e.getFunction().getName());
- assertEquals("-", e2.getFunction().getName());
+ assertThat(e.getFunction().getName()).isEqualTo("-");
+ assertThat(e2.getFunction().getName()).isEqualTo("-");
assertThat(e.getArguments()).hasSize(1);
- assertEquals(1, e.getNumPositionalArguments());
+ assertThat(e.getNumPositionalArguments()).isEqualTo(1);
IntegerLiteral arg0 = (IntegerLiteral) e.getArguments().get(0).getValue();
- assertEquals(5, (int) arg0.getValue());
+ assertThat((int) arg0.getValue()).isEqualTo(5);
}
@Test
@@ -142,21 +139,21 @@
FuncallExpression e = (FuncallExpression) parseExpression("foo(1, 2, bar=wiz)");
Identifier ident = e.getFunction();
- assertEquals("foo", ident.getName());
+ assertThat(ident.getName()).isEqualTo("foo");
assertThat(e.getArguments()).hasSize(3);
- assertEquals(2, e.getNumPositionalArguments());
+ assertThat(e.getNumPositionalArguments()).isEqualTo(2);
IntegerLiteral arg0 = (IntegerLiteral) e.getArguments().get(0).getValue();
- assertEquals(1, (int) arg0.getValue());
+ assertThat((int) arg0.getValue()).isEqualTo(1);
IntegerLiteral arg1 = (IntegerLiteral) e.getArguments().get(1).getValue();
- assertEquals(2, (int) arg1.getValue());
+ assertThat((int) arg1.getValue()).isEqualTo(2);
Argument.Passed arg2 = e.getArguments().get(2);
- assertEquals("bar", arg2.getName());
+ assertThat(arg2.getName()).isEqualTo("bar");
Identifier arg2val = (Identifier) arg2.getValue();
- assertEquals("wiz", arg2val.getName());
+ assertThat(arg2val.getName()).isEqualTo("wiz");
}
@Test
@@ -165,21 +162,21 @@
(FuncallExpression) parseExpression("foo.foo(1, 2, bar=wiz)");
Identifier ident = e.getFunction();
- assertEquals("foo", ident.getName());
+ assertThat(ident.getName()).isEqualTo("foo");
assertThat(e.getArguments()).hasSize(3);
- assertEquals(2, e.getNumPositionalArguments());
+ assertThat(e.getNumPositionalArguments()).isEqualTo(2);
IntegerLiteral arg0 = (IntegerLiteral) e.getArguments().get(0).getValue();
- assertEquals(1, (int) arg0.getValue());
+ assertThat((int) arg0.getValue()).isEqualTo(1);
IntegerLiteral arg1 = (IntegerLiteral) e.getArguments().get(1).getValue();
- assertEquals(2, (int) arg1.getValue());
+ assertThat((int) arg1.getValue()).isEqualTo(2);
Argument.Passed arg2 = e.getArguments().get(2);
- assertEquals("bar", arg2.getName());
+ assertThat(arg2.getName()).isEqualTo("bar");
Identifier arg2val = (Identifier) arg2.getValue();
- assertEquals("wiz", arg2val.getName());
+ assertThat(arg2val.getName()).isEqualTo("wiz");
}
@Test
@@ -188,13 +185,13 @@
(FuncallExpression) parseExpression("foo.replace().split(1)");
Identifier ident = e.getFunction();
- assertEquals("split", ident.getName());
+ assertThat(ident.getName()).isEqualTo("split");
assertThat(e.getArguments()).hasSize(1);
- assertEquals(1, e.getNumPositionalArguments());
+ assertThat(e.getNumPositionalArguments()).isEqualTo(1);
IntegerLiteral arg0 = (IntegerLiteral) e.getArguments().get(0).getValue();
- assertEquals(1, (int) arg0.getValue());
+ assertThat((int) arg0.getValue()).isEqualTo(1);
}
@Test
@@ -202,7 +199,7 @@
DotExpression e = (DotExpression) parseExpression("foo.foo");
Identifier ident = e.getField();
- assertEquals("foo", ident.getName());
+ assertThat(ident.getName()).isEqualTo("foo");
}
@Test
@@ -210,7 +207,7 @@
FuncallExpression e = (FuncallExpression) parseExpression("'foo'.foo()");
Identifier ident = e.getFunction();
- assertEquals("foo", ident.getName());
+ assertThat(ident.getName()).isEqualTo("foo");
assertThat(e.getArguments()).isEmpty();
}
@@ -218,27 +215,27 @@
@Test
public void testStringLiteralOptimizationValue() throws Exception {
StringLiteral l = (StringLiteral) parseExpression("'abc' + 'def'");
- assertEquals("abcdef", l.value);
+ assertThat(l.value).isEqualTo("abcdef");
}
@Test
public void testStringLiteralOptimizationToString() throws Exception {
StringLiteral l = (StringLiteral) parseExpression("'abc' + 'def'");
- assertEquals("\"abcdef\"", l.toString());
+ assertThat(l.toString()).isEqualTo("\"abcdef\"");
}
@Test
public void testStringLiteralOptimizationLocation() throws Exception {
StringLiteral l = (StringLiteral) parseExpression("'abc' + 'def'");
- assertEquals(0, l.getLocation().getStartOffset());
- assertEquals(13, l.getLocation().getEndOffset());
+ assertThat(l.getLocation().getStartOffset()).isEqualTo(0);
+ assertThat(l.getLocation().getEndOffset()).isEqualTo(13);
}
@Test
public void testStringLiteralOptimizationDifferentQuote() throws Exception {
StringLiteral l = (StringLiteral) parseExpression("'abc' + \"def\"");
- assertEquals(0, l.getLocation().getStartOffset());
- assertEquals(13, l.getLocation().getEndOffset());
+ assertThat(l.getLocation().getStartOffset()).isEqualTo(0);
+ assertThat(l.getLocation().getEndOffset()).isEqualTo(13);
}
@Test
@@ -248,7 +245,7 @@
FuncallExpression e = (FuncallExpression) parseExpression(
"'FOO.CC'.lower()[1:].startswith('oo')");
- assertEquals("startswith", e.getFunction().getName());
+ assertThat(e.getFunction().getName()).isEqualTo("startswith");
assertThat(e.getArguments()).hasSize(1);
s = (SliceExpression) parseExpression("'FOO.CC'[1:][:2]");
@@ -313,24 +310,24 @@
// Test that the actual parameters are: (1, $error$, 3):
Identifier ident = e.getFunction();
- assertEquals("f", ident.getName());
+ assertThat(ident.getName()).isEqualTo("f");
assertThat(e.getArguments()).hasSize(3);
- assertEquals(3, e.getNumPositionalArguments());
+ assertThat(e.getNumPositionalArguments()).isEqualTo(3);
IntegerLiteral arg0 = (IntegerLiteral) e.getArguments().get(0).getValue();
- assertEquals(1, (int) arg0.getValue());
+ assertThat((int) arg0.getValue()).isEqualTo(1);
Argument.Passed arg1 = e.getArguments().get(1);
Identifier arg1val = ((Identifier) arg1.getValue());
- assertEquals("$error$", arg1val.getName());
+ assertThat(arg1val.getName()).isEqualTo("$error$");
assertLocation(5, 29, arg1val.getLocation());
- assertEquals("[x for foo foo foo foo]", expr.substring(5, 28));
- assertEquals(30, arg1val.getLocation().getEndLineAndColumn().getColumn());
+ assertThat(expr.substring(5, 28)).isEqualTo("[x for foo foo foo foo]");
+ assertThat(arg1val.getLocation().getEndLineAndColumn().getColumn()).isEqualTo(30);
IntegerLiteral arg2 = (IntegerLiteral) e.getArguments().get(2).getValue();
- assertEquals(3, (int) arg2.getValue());
+ assertThat((int) arg2.getValue()).isEqualTo(3);
}
@Test
@@ -370,7 +367,7 @@
public void testAssignLocation() {
List<Statement> statements = parseFile("a = b;c = d\n");
Statement statement = statements.get(0);
- assertEquals(5, statement.getLocation().getEndOffset());
+ assertThat(statement.getLocation().getEndOffset()).isEqualTo(5);
}
@Test
@@ -430,30 +427,31 @@
@Test
public void testAugmentedAssign() throws Exception {
- assertEquals("[x += 1\n]", parseFile("x += 1").toString());
- assertEquals("[x -= 1\n]", parseFile("x -= 1").toString());
- assertEquals("[x *= 1\n]", parseFile("x *= 1").toString());
- assertEquals("[x /= 1\n]", parseFile("x /= 1").toString());
- assertEquals("[x %= 1\n]", parseFile("x %= 1").toString());
+ assertThat(parseFile("x += 1").toString()).isEqualTo("[x += 1\n]");
+ assertThat(parseFile("x -= 1").toString()).isEqualTo("[x -= 1\n]");
+ assertThat(parseFile("x *= 1").toString()).isEqualTo("[x *= 1\n]");
+ assertThat(parseFile("x /= 1").toString()).isEqualTo("[x /= 1\n]");
+ assertThat(parseFile("x %= 1").toString()).isEqualTo("[x %= 1\n]");
}
@Test
public void testPrettyPrintFunctions() throws Exception {
- assertEquals("[x[1:3]\n]", parseFile("x[1:3]").toString());
- assertEquals("[x[1:3]\n]", parseFile("x[1:3:1]").toString());
- assertEquals("[x[1:3:2]\n]", parseFile("x[1:3:2]").toString());
- assertEquals("[x[1::2]\n]", parseFile("x[1::2]").toString());
- assertEquals("[x[1:]\n]", parseFile("x[1:]").toString());
- assertEquals("[str[42]\n]", parseFile("str[42]").toString());
- assertEquals("[ctx.new_file(\"hello\")\n]", parseFile("ctx.new_file('hello')").toString());
- assertEquals("[new_file(\"hello\")\n]", parseFile("new_file(\"hello\")").toString());
+ assertThat(parseFile("x[1:3]").toString()).isEqualTo("[x[1:3]\n]");
+ assertThat(parseFile("x[1:3:1]").toString()).isEqualTo("[x[1:3]\n]");
+ assertThat(parseFile("x[1:3:2]").toString()).isEqualTo("[x[1:3:2]\n]");
+ assertThat(parseFile("x[1::2]").toString()).isEqualTo("[x[1::2]\n]");
+ assertThat(parseFile("x[1:]").toString()).isEqualTo("[x[1:]\n]");
+ assertThat(parseFile("str[42]").toString()).isEqualTo("[str[42]\n]");
+ assertThat(parseFile("ctx.new_file('hello')").toString())
+ .isEqualTo("[ctx.new_file(\"hello\")\n]");
+ assertThat(parseFile("new_file(\"hello\")").toString()).isEqualTo("[new_file(\"hello\")\n]");
}
@Test
public void testFuncallLocation() {
List<Statement> statements = parseFile("a(b);c = d\n");
Statement statement = statements.get(0);
- assertEquals(4, statement.getLocation().getEndOffset());
+ assertThat(statement.getLocation().getEndOffset()).isEqualTo(4);
}
@Test
@@ -472,30 +470,30 @@
public void testListPositions() throws Exception {
String expr = "[0,f(1),2]";
ListLiteral list = (ListLiteral) parseExpression(expr);
- assertEquals("[0,f(1),2]", getText(expr, list));
- assertEquals("0", getText(expr, getElem(list, 0)));
- assertEquals("f(1)", getText(expr, getElem(list, 1)));
- assertEquals("2", getText(expr, getElem(list, 2)));
+ assertThat(getText(expr, list)).isEqualTo("[0,f(1),2]");
+ assertThat(getText(expr, getElem(list, 0))).isEqualTo("0");
+ assertThat(getText(expr, getElem(list, 1))).isEqualTo("f(1)");
+ assertThat(getText(expr, getElem(list, 2))).isEqualTo("2");
}
@Test
public void testDictPositions() throws Exception {
String expr = "{1:2,2:f(1),3:4}";
DictionaryLiteral list = (DictionaryLiteral) parseExpression(expr);
- assertEquals("{1:2,2:f(1),3:4}", getText(expr, list));
- assertEquals("1:2", getText(expr, getElem(list, 0)));
- assertEquals("2:f(1)", getText(expr, getElem(list, 1)));
- assertEquals("3:4", getText(expr, getElem(list, 2)));
+ assertThat(getText(expr, list)).isEqualTo("{1:2,2:f(1),3:4}");
+ assertThat(getText(expr, getElem(list, 0))).isEqualTo("1:2");
+ assertThat(getText(expr, getElem(list, 1))).isEqualTo("2:f(1)");
+ assertThat(getText(expr, getElem(list, 2))).isEqualTo("3:4");
}
@Test
public void testArgumentPositions() throws Exception {
String stmt = "f(0,g(1,2),2)";
FuncallExpression f = (FuncallExpression) parseExpression(stmt);
- assertEquals(stmt, getText(stmt, f));
- assertEquals("0", getText(stmt, getArg(f, 0)));
- assertEquals("g(1,2)", getText(stmt, getArg(f, 1)));
- assertEquals("2", getText(stmt, getArg(f, 2)));
+ assertThat(getText(stmt, f)).isEqualTo(stmt);
+ assertThat(getText(stmt, getArg(f, 0))).isEqualTo("0");
+ assertThat(getText(stmt, getArg(f, 1))).isEqualTo("g(1,2)");
+ assertThat(getText(stmt, getArg(f, 2))).isEqualTo("2");
}
@Test
@@ -526,33 +524,33 @@
@Test
public void testListLiterals1() throws Exception {
ListLiteral list = (ListLiteral) parseExpression("[0,1,2]");
- assertFalse(list.isTuple());
+ assertThat(list.isTuple()).isFalse();
assertThat(list.getElements()).hasSize(3);
- assertFalse(list.isTuple());
+ assertThat(list.isTuple()).isFalse();
for (int i = 0; i < 3; ++i) {
- assertEquals(i, getIntElem(list, i));
+ assertThat(getIntElem(list, i)).isEqualTo(i);
}
}
@Test
public void testTupleLiterals2() throws Exception {
ListLiteral tuple = (ListLiteral) parseExpression("(0,1,2)");
- assertTrue(tuple.isTuple());
+ assertThat(tuple.isTuple()).isTrue();
assertThat(tuple.getElements()).hasSize(3);
- assertTrue(tuple.isTuple());
+ assertThat(tuple.isTuple()).isTrue();
for (int i = 0; i < 3; ++i) {
- assertEquals(i, getIntElem(tuple, i));
+ assertThat(getIntElem(tuple, i)).isEqualTo(i);
}
}
@Test
public void testTupleWithoutParens() throws Exception {
ListLiteral tuple = (ListLiteral) parseExpression("0, 1, 2");
- assertTrue(tuple.isTuple());
+ assertThat(tuple.isTuple()).isTrue();
assertThat(tuple.getElements()).hasSize(3);
- assertTrue(tuple.isTuple());
+ assertThat(tuple.isTuple()).isTrue();
for (int i = 0; i < 3; ++i) {
- assertEquals(i, getIntElem(tuple, i));
+ assertThat(getIntElem(tuple, i)).isEqualTo(i);
}
}
@@ -570,56 +568,56 @@
clearEvents();
ListLiteral tuple = (ListLiteral) parseExpression("(0, 1, 2, 3,)");
- assertTrue(tuple.isTuple());
+ assertThat(tuple.isTuple()).isTrue();
assertThat(tuple.getElements()).hasSize(4);
- assertTrue(tuple.isTuple());
+ assertThat(tuple.isTuple()).isTrue();
for (int i = 0; i < 4; ++i) {
- assertEquals(i, getIntElem(tuple, i));
+ assertThat(getIntElem(tuple, i)).isEqualTo(i);
}
}
@Test
public void testTupleLiterals3() throws Exception {
ListLiteral emptyTuple = (ListLiteral) parseExpression("()");
- assertTrue(emptyTuple.isTuple());
+ assertThat(emptyTuple.isTuple()).isTrue();
assertThat(emptyTuple.getElements()).isEmpty();
}
@Test
public void testTupleLiterals4() throws Exception {
ListLiteral singletonTuple = (ListLiteral) parseExpression("(42,)");
- assertTrue(singletonTuple.isTuple());
+ assertThat(singletonTuple.isTuple()).isTrue();
assertThat(singletonTuple.getElements()).hasSize(1);
- assertEquals(42, getIntElem(singletonTuple, 0));
+ assertThat(getIntElem(singletonTuple, 0)).isEqualTo(42);
}
@Test
public void testTupleLiterals5() throws Exception {
IntegerLiteral intLit = (IntegerLiteral) parseExpression("(42)"); // not a tuple!
- assertEquals(42, (int) intLit.getValue());
+ assertThat((int) intLit.getValue()).isEqualTo(42);
}
@Test
public void testListLiterals6() throws Exception {
ListLiteral emptyList = (ListLiteral) parseExpression("[]");
- assertFalse(emptyList.isTuple());
+ assertThat(emptyList.isTuple()).isFalse();
assertThat(emptyList.getElements()).isEmpty();
}
@Test
public void testListLiterals7() throws Exception {
ListLiteral singletonList = (ListLiteral) parseExpression("[42,]");
- assertFalse(singletonList.isTuple());
+ assertThat(singletonList.isTuple()).isFalse();
assertThat(singletonList.getElements()).hasSize(1);
- assertEquals(42, getIntElem(singletonList, 0));
+ assertThat(getIntElem(singletonList, 0)).isEqualTo(42);
}
@Test
public void testListLiterals8() throws Exception {
ListLiteral singletonList = (ListLiteral) parseExpression("[42]"); // a singleton
- assertFalse(singletonList.isTuple());
+ assertThat(singletonList.isTuple()).isFalse();
assertThat(singletonList.getElements()).hasSize(1);
- assertEquals(42, getIntElem(singletonList, 0));
+ assertThat(getIntElem(singletonList, 0)).isEqualTo(42);
}
@Test
@@ -628,8 +626,8 @@
(DictionaryLiteral) parseExpression("{1:42}"); // a singleton dictionary
assertThat(dictionaryList.getEntries()).hasSize(1);
DictionaryEntryLiteral tuple = getElem(dictionaryList, 0);
- assertEquals(1, getIntElem(tuple, true));
- assertEquals(42, getIntElem(tuple, false));
+ assertThat(getIntElem(tuple, true)).isEqualTo(1);
+ assertThat(getIntElem(tuple, false)).isEqualTo(42);
}
@Test
@@ -645,8 +643,8 @@
(DictionaryLiteral) parseExpression("{1:42,}"); // a singleton dictionary
assertThat(dictionaryList.getEntries()).hasSize(1);
DictionaryEntryLiteral tuple = getElem(dictionaryList, 0);
- assertEquals(1, getIntElem(tuple, true));
- assertEquals(42, getIntElem(tuple, false));
+ assertThat(getIntElem(tuple, true)).isEqualTo(1);
+ assertThat(getIntElem(tuple, false)).isEqualTo(42);
}
@Test
@@ -655,8 +653,8 @@
assertThat(dictionaryList.getEntries()).hasSize(3);
for (int i = 0; i < 3; i++) {
DictionaryEntryLiteral tuple = getElem(dictionaryList, i);
- assertEquals(i + 1, getIntElem(tuple, true));
- assertEquals(i + 42, getIntElem(tuple, false));
+ assertThat(getIntElem(tuple, true)).isEqualTo(i + 1);
+ assertThat(getIntElem(tuple, false)).isEqualTo(i + 42);
}
}
@@ -664,7 +662,7 @@
public void testListLiterals9() throws Exception {
ListLiteral singletonList =
(ListLiteral) parseExpression("[ abi + opt_level + \'/include\' ]");
- assertFalse(singletonList.isTuple());
+ assertThat(singletonList.isTuple()).isFalse();
assertThat(singletonList.getElements()).hasSize(1);
}
@@ -858,10 +856,12 @@
StringBuilder commentLines = new StringBuilder();
for (Comment comment : result.getComments()) {
// Comments start and end on the same line
- assertEquals(comment.getLocation().getStartLineAndColumn().getLine() + " ends on "
- + comment.getLocation().getEndLineAndColumn().getLine(),
- comment.getLocation().getStartLineAndColumn().getLine(),
- comment.getLocation().getEndLineAndColumn().getLine());
+ assertWithMessage(
+ comment.getLocation().getStartLineAndColumn().getLine()
+ + " ends on "
+ + comment.getLocation().getEndLineAndColumn().getLine())
+ .that(comment.getLocation().getEndLineAndColumn().getLine())
+ .isEqualTo(comment.getLocation().getStartLineAndColumn().getLine());
commentLines.append('(');
commentLines.append(comment.getLocation().getStartLineAndColumn().getLine());
commentLines.append(',');
@@ -965,7 +965,7 @@
assertThat(bodyNone).hasSize(1);
ReturnStatement returnNone = (ReturnStatement) bodyNone.get(0);
- assertEquals("None", ((Identifier) returnNone.getReturnExpression()).getName());
+ assertThat(((Identifier) returnNone.getReturnExpression()).getName()).isEqualTo("None");
int i = 0;
for (String end : new String[]{";", "\n"}) {
@@ -978,7 +978,7 @@
ReturnStatement returnNoExpr = (ReturnStatement) bodyNoExpr.get(0);
Identifier none = (Identifier) returnNoExpr.getReturnExpression();
- assertEquals("None", none.getName());
+ assertThat(none.getName()).isEqualTo("None");
assertLocation(
returnNoExpr.getLocation().getStartOffset(),
returnNoExpr.getLocation().getEndOffset(),
@@ -1172,7 +1172,7 @@
List<Statement> statements = parseFileForSkylark(
"load('/foo/bar/file', 'fun_test')\n");
LoadStatement stmt = (LoadStatement) statements.get(0);
- assertEquals("/foo/bar/file", stmt.getImport().getValue());
+ assertThat(stmt.getImport().getValue()).isEqualTo("/foo/bar/file");
assertThat(stmt.getSymbols()).hasSize(1);
Identifier sym = stmt.getSymbols().get(0);
int startOffset = sym.getLocation().getStartOffset();
@@ -1186,7 +1186,7 @@
List<Statement> statements = parseFileForSkylark(
"load('/foo/bar/file', 'fun_test',)\n");
LoadStatement stmt = (LoadStatement) statements.get(0);
- assertEquals("/foo/bar/file", stmt.getImport().getValue());
+ assertThat(stmt.getImport().getValue()).isEqualTo("/foo/bar/file");
assertThat(stmt.getSymbols()).hasSize(1);
}
@@ -1195,7 +1195,7 @@
List<Statement> statements = parseFileForSkylark(
"load('file', 'foo', 'bar')\n");
LoadStatement stmt = (LoadStatement) statements.get(0);
- assertEquals("file", stmt.getImport().getValue());
+ assertThat(stmt.getImport().getValue()).isEqualTo("file");
assertThat(stmt.getSymbols()).hasSize(2);
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java b/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java
index d2a427c..0a7f841 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java
@@ -15,7 +15,6 @@
package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import com.google.common.base.Joiner;
@@ -24,17 +23,15 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.syntax.SkylarkList.MutableList;
import com.google.devtools.build.lib.syntax.SkylarkList.Tuple;
-
-import java.util.LinkedHashMap;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
import java.util.Arrays;
import java.util.IllegalFormatException;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Test properties of the evaluator's datatypes and utility functions
@@ -47,41 +44,37 @@
public void testPrinter() throws Exception {
// Note that prettyPrintValue and printValue only differ on behaviour of
// labels and strings at toplevel.
- assertEquals("foo\nbar", Printer.str("foo\nbar"));
- assertEquals("\"foo\\nbar\"", Printer.repr("foo\nbar"));
- assertEquals("'", Printer.str("'"));
- assertEquals("\"'\"", Printer.repr("'"));
- assertEquals("\"", Printer.str("\""));
- assertEquals("\"\\\"\"", Printer.repr("\""));
- assertEquals("3", Printer.str(3));
- assertEquals("3", Printer.repr(3));
- assertEquals("None", Printer.repr(Runtime.NONE));
+ assertThat(Printer.str("foo\nbar")).isEqualTo("foo\nbar");
+ assertThat(Printer.repr("foo\nbar")).isEqualTo("\"foo\\nbar\"");
+ assertThat(Printer.str("'")).isEqualTo("'");
+ assertThat(Printer.repr("'")).isEqualTo("\"'\"");
+ assertThat(Printer.str("\"")).isEqualTo("\"");
+ assertThat(Printer.repr("\"")).isEqualTo("\"\\\"\"");
+ assertThat(Printer.str(3)).isEqualTo("3");
+ assertThat(Printer.repr(3)).isEqualTo("3");
+ assertThat(Printer.repr(Runtime.NONE)).isEqualTo("None");
- assertEquals("//x:x", Printer.str(
- Label.parseAbsolute("//x")));
- assertEquals("\"//x:x\"", Printer.repr(
- Label.parseAbsolute("//x")));
+ assertThat(Printer.str(Label.parseAbsolute("//x"))).isEqualTo("//x:x");
+ assertThat(Printer.repr(Label.parseAbsolute("//x"))).isEqualTo("\"//x:x\"");
List<?> list = MutableList.of(null, "foo", "bar");
List<?> tuple = Tuple.of("foo", "bar");
- assertEquals("(1, [\"foo\", \"bar\"], 3)",
- Printer.str(Tuple.of(1, list, 3)));
- assertEquals("(1, [\"foo\", \"bar\"], 3)",
- Printer.repr(Tuple.of(1, list, 3)));
- assertEquals("[1, (\"foo\", \"bar\"), 3]",
- Printer.str(MutableList.of(null, 1, tuple, 3)));
- assertEquals("[1, (\"foo\", \"bar\"), 3]",
- Printer.repr(MutableList.of(null, 1, tuple, 3)));
+ assertThat(Printer.str(Tuple.of(1, list, 3))).isEqualTo("(1, [\"foo\", \"bar\"], 3)");
+ assertThat(Printer.repr(Tuple.of(1, list, 3))).isEqualTo("(1, [\"foo\", \"bar\"], 3)");
+ assertThat(Printer.str(MutableList.of(null, 1, tuple, 3)))
+ .isEqualTo("[1, (\"foo\", \"bar\"), 3]");
+ assertThat(Printer.repr(MutableList.of(null, 1, tuple, 3)))
+ .isEqualTo("[1, (\"foo\", \"bar\"), 3]");
Map<Object, Object> dict = ImmutableMap.<Object, Object>of(
1, tuple,
2, list,
"foo", MutableList.of(null));
- assertEquals("{1: (\"foo\", \"bar\"), 2: [\"foo\", \"bar\"], \"foo\": []}",
- Printer.str(dict));
- assertEquals("{1: (\"foo\", \"bar\"), 2: [\"foo\", \"bar\"], \"foo\": []}",
- Printer.repr(dict));
+ assertThat(Printer.str(dict))
+ .isEqualTo("{1: (\"foo\", \"bar\"), 2: [\"foo\", \"bar\"], \"foo\": []}");
+ assertThat(Printer.repr(dict))
+ .isEqualTo("{1: (\"foo\", \"bar\"), 2: [\"foo\", \"bar\"], \"foo\": []}");
}
private void checkFormatPositionalFails(String errorMessage, String format, Object... arguments) {
@@ -105,26 +98,26 @@
@Test
public void testFormatPositional() throws Exception {
- assertEquals("foo 3", Printer.formatToString("%s %d", Tuple.of("foo", 3)));
- assertEquals("foo 3", Printer.format("%s %d", "foo", 3));
+ assertThat(Printer.formatToString("%s %d", Tuple.of("foo", 3))).isEqualTo("foo 3");
+ assertThat(Printer.format("%s %d", "foo", 3)).isEqualTo("foo 3");
// Note: formatToString doesn't perform scalar x -> (x) conversion;
// The %-operator is responsible for that.
assertThat(Printer.formatToString("", Tuple.of())).isEmpty();
- assertEquals("foo", Printer.format("%s", "foo"));
- assertEquals("3.14159", Printer.format("%s", 3.14159));
+ assertThat(Printer.format("%s", "foo")).isEqualTo("foo");
+ assertThat(Printer.format("%s", 3.14159)).isEqualTo("3.14159");
checkFormatPositionalFails("not all arguments converted during string formatting",
"%s", 1, 2, 3);
- assertEquals("%foo", Printer.format("%%%s", "foo"));
+ assertThat(Printer.format("%%%s", "foo")).isEqualTo("%foo");
checkFormatPositionalFails("not all arguments converted during string formatting",
"%%s", "foo");
checkFormatPositionalFails("unsupported format character \" \" at index 1 in \"% %s\"",
"% %s", "foo");
- assertEquals("[1, 2, 3]", Printer.format("%s", MutableList.of(null, 1, 2, 3)));
- assertEquals("(1, 2, 3)", Printer.format("%s", Tuple.of(1, 2, 3)));
- assertEquals("[]", Printer.format("%s", MutableList.of(null)));
- assertEquals("()", Printer.format("%s", Tuple.of()));
- assertEquals("% 1 \"2\" 3", Printer.format("%% %d %r %s", 1, "2", "3"));
+ assertThat(Printer.format("%s", MutableList.of(null, 1, 2, 3))).isEqualTo("[1, 2, 3]");
+ assertThat(Printer.format("%s", Tuple.of(1, 2, 3))).isEqualTo("(1, 2, 3)");
+ assertThat(Printer.format("%s", MutableList.of(null))).isEqualTo("[]");
+ assertThat(Printer.format("%s", Tuple.of())).isEqualTo("()");
+ assertThat(Printer.format("%% %d %r %s", 1, "2", "3")).isEqualTo("% 1 \"2\" 3");
checkFormatPositionalFails(
"invalid argument \"1\" for format pattern %d",
@@ -142,9 +135,9 @@
assertThat(Printer.str("test", '\'')).isEqualTo("test");
assertThat(Printer.repr("test", '\'')).isEqualTo("'test'");
- assertEquals("'\\''", Printer.repr("'", '\''));
- assertEquals("\"", Printer.str("\"", '\''));
- assertEquals("'\"'", Printer.repr("\"", '\''));
+ assertThat(Printer.repr("'", '\'')).isEqualTo("'\\''");
+ assertThat(Printer.str("\"", '\'')).isEqualTo("\"");
+ assertThat(Printer.repr("\"", '\'')).isEqualTo("'\"'");
List<?> list = MutableList.of(null, "foo", "bar");
List<?> tuple = Tuple.of("foo", "bar");
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
index b88d972..d00c1bd 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
@@ -14,8 +14,6 @@
package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
@@ -1293,11 +1291,11 @@
@Test
public void testSkylarkTypes() {
- assertEquals(TransitiveInfoCollection.class,
- EvalUtils.getSkylarkType(FileConfiguredTarget.class));
- assertEquals(TransitiveInfoCollection.class,
- EvalUtils.getSkylarkType(RuleConfiguredTarget.class));
- assertEquals(Artifact.class, EvalUtils.getSkylarkType(SpecialArtifact.class));
+ assertThat(EvalUtils.getSkylarkType(FileConfiguredTarget.class))
+ .isEqualTo(TransitiveInfoCollection.class);
+ assertThat(EvalUtils.getSkylarkType(RuleConfiguredTarget.class))
+ .isEqualTo(TransitiveInfoCollection.class);
+ assertThat(EvalUtils.getSkylarkType(SpecialArtifact.class)).isEqualTo(Artifact.class);
}
// Override tests in EvaluationTest incompatible with Skylark
@@ -1317,11 +1315,11 @@
// tuple
x = eval("(1,2)");
assertThat((Iterable<Object>) x).containsExactly(1, 2).inOrder();
- assertTrue(((SkylarkList) x).isTuple());
+ assertThat(((SkylarkList) x).isTuple()).isTrue();
x = eval("(1,2) + (3,4)");
assertThat((Iterable<Object>) x).containsExactly(1, 2, 3, 4).inOrder();
- assertTrue(((SkylarkList) x).isTuple());
+ assertThat(((SkylarkList) x).isTuple()).isTrue();
}
@Override
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java
index 8a17607..161b913 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java
@@ -14,7 +14,6 @@
package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
import com.google.devtools.build.lib.syntax.SkylarkList.Tuple;
import com.google.devtools.build.lib.syntax.util.EvaluationTestCase;
@@ -165,10 +164,10 @@
"e1 = l[1]",
"e2 = l[2]",
"e3 = l[3]");
- assertEquals(1, lookup("e0"));
- assertEquals(2, lookup("e1"));
- assertEquals(3, lookup("e2"));
- assertEquals(4, lookup("e3"));
+ assertThat(lookup("e0")).isEqualTo(1);
+ assertThat(lookup("e1")).isEqualTo(2);
+ assertThat(lookup("e2")).isEqualTo(3);
+ assertThat(lookup("e3")).isEqualTo(4);
}
@Test
@@ -179,37 +178,37 @@
"e2 = l[2]",
"e3 = l[3]",
"e4 = l[4]");
- assertEquals(1, lookup("e0"));
- assertEquals(2, lookup("e1"));
- assertEquals(3, lookup("e2"));
- assertEquals(4, lookup("e3"));
- assertEquals(5, lookup("e4"));
+ assertThat(lookup("e0")).isEqualTo(1);
+ assertThat(lookup("e1")).isEqualTo(2);
+ assertThat(lookup("e2")).isEqualTo(3);
+ assertThat(lookup("e3")).isEqualTo(4);
+ assertThat(lookup("e4")).isEqualTo(5);
}
@Test
public void testConcatListSize() throws Exception {
- assertEquals(4, eval("len([1, 2] + [3, 4])"));
+ assertThat(eval("len([1, 2] + [3, 4])")).isEqualTo(4);
}
@Test
public void testAppend() throws Exception {
eval("l = [1, 2]");
- assertEquals(eval("l.append([3, 4])"), Runtime.NONE);
- assertEquals(lookup("l"), eval("[1, 2, [3, 4]]"));
+ assertThat(Runtime.NONE).isEqualTo(eval("l.append([3, 4])"));
+ assertThat(eval("[1, 2, [3, 4]]")).isEqualTo(lookup("l"));
}
@Test
public void testExtend() throws Exception {
eval("l = [1, 2]");
- assertEquals(eval("l.extend([3, 4])"), Runtime.NONE);
- assertEquals(lookup("l"), eval("[1, 2, 3, 4]"));
+ assertThat(Runtime.NONE).isEqualTo(eval("l.extend([3, 4])"));
+ assertThat(eval("[1, 2, 3, 4]")).isEqualTo(lookup("l"));
}
@Test
public void testConcatListToString() throws Exception {
eval("l = [1, 2] + [3, 4]",
"s = str(l)");
- assertEquals("[1, 2, 3, 4]", lookup("s"));
+ assertThat(lookup("s")).isEqualTo("[1, 2, 3, 4]");
}
@Test
@@ -219,7 +218,7 @@
" v = 1",
"else:",
" v = 0");
- assertEquals(1, lookup("v"));
+ assertThat(lookup("v")).isEqualTo(1);
}
@Test
@@ -229,18 +228,18 @@
" v = 1",
"else:",
" v = 0");
- assertEquals(0, lookup("v"));
+ assertThat(lookup("v")).isEqualTo(0);
}
@Test
public void testListComparison() throws Exception {
- assertEquals(true, eval("(1, 'two', [3, 4]) == (1, 'two', [3, 4])"));
- assertEquals(true, eval("[1, 2, 3, 4] == [1, 2] + [3, 4]"));
- assertEquals(false, eval("[1, 2, 3, 4] == (1, 2, 3, 4)"));
- assertEquals(false, eval("[1, 2] == [1, 2, 3]"));
- assertEquals(true, eval("[] == []"));
- assertEquals(true, eval("() == ()"));
- assertEquals(false, eval("() == (1,)"));
- assertEquals(false, eval("(1) == (1,)"));
+ assertThat(eval("(1, 'two', [3, 4]) == (1, 'two', [3, 4])")).isEqualTo(true);
+ assertThat(eval("[1, 2, 3, 4] == [1, 2] + [3, 4]")).isEqualTo(true);
+ assertThat(eval("[1, 2, 3, 4] == (1, 2, 3, 4)")).isEqualTo(false);
+ assertThat(eval("[1, 2] == [1, 2, 3]")).isEqualTo(false);
+ assertThat(eval("[] == []")).isEqualTo(true);
+ assertThat(eval("() == ()")).isEqualTo(true);
+ assertThat(eval("() == (1,)")).isEqualTo(false);
+ assertThat(eval("(1) == (1,)")).isEqualTo(false);
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkNestedSetTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkNestedSetTest.java
index c42905f..58fef45 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkNestedSetTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkNestedSetTest.java
@@ -50,7 +50,7 @@
eval("s = set([1, 2, 3], order='postorder')");
Assert.fail("`set` should have failed");
} catch (EvalException e) {
- assertThat(e.getMessage()).contains("The `set` constructor for depsets is deprecated");
+ assertThat(e).hasMessageThat().contains("The `set` constructor for depsets is deprecated");
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/TypeTest.java b/src/test/java/com/google/devtools/build/lib/syntax/TypeTest.java
index 8674e46..995683e 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/TypeTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/TypeTest.java
@@ -14,10 +14,6 @@
package com.google.devtools.build.lib.syntax;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableList;
@@ -37,7 +33,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -59,7 +54,7 @@
@Test
public void testInteger() throws Exception {
Object x = 3;
- assertEquals(x, Type.INTEGER.convert(x, null));
+ assertThat(Type.INTEGER.convert(x, null)).isEqualTo(x);
assertThat(collectLabels(Type.INTEGER, x)).isEmpty();
}
@@ -91,7 +86,7 @@
@Test
public void testString() throws Exception {
Object s = "foo";
- assertEquals(s, Type.STRING.convert(s, null));
+ assertThat(Type.STRING.convert(s, null)).isEqualTo(s);
assertThat(collectLabels(Type.STRING, s)).isEmpty();
}
@@ -109,12 +104,12 @@
public void testBoolean() throws Exception {
Object myTrue = true;
Object myFalse = false;
- assertEquals(Boolean.TRUE, Type.BOOLEAN.convert(1, null));
- assertEquals(Boolean.FALSE, Type.BOOLEAN.convert(0, null));
- assertTrue(Type.BOOLEAN.convert(true, null));
- assertTrue(Type.BOOLEAN.convert(myTrue, null));
- assertFalse(Type.BOOLEAN.convert(false, null));
- assertFalse(Type.BOOLEAN.convert(myFalse, null));
+ assertThat(Type.BOOLEAN.convert(1, null)).isEqualTo(Boolean.TRUE);
+ assertThat(Type.BOOLEAN.convert(0, null)).isEqualTo(Boolean.FALSE);
+ assertThat(Type.BOOLEAN.convert(true, null)).isTrue();
+ assertThat(Type.BOOLEAN.convert(myTrue, null)).isTrue();
+ assertThat(Type.BOOLEAN.convert(false, null)).isFalse();
+ assertThat(Type.BOOLEAN.convert(myFalse, null)).isFalse();
assertThat(collectLabels(Type.BOOLEAN, myTrue)).isEmpty();
}
@@ -132,26 +127,26 @@
Type.BOOLEAN.convert(2, null);
fail();
} catch (Type.ConversionException e) {
- assertEquals("boolean is not one of [0, 1]", e.getMessage());
+ assertThat(e).hasMessageThat().isEqualTo("boolean is not one of [0, 1]");
}
try {
Type.BOOLEAN.convert(-1, null);
fail();
} catch (Type.ConversionException e) {
- assertEquals("boolean is not one of [0, 1]", e.getMessage());
+ assertThat(e).hasMessageThat().isEqualTo("boolean is not one of [0, 1]");
}
}
@Test
public void testTriState() throws Exception {
- Assert.assertEquals(TriState.YES, BuildType.TRISTATE.convert(1, null));
- assertEquals(TriState.NO, BuildType.TRISTATE.convert(0, null));
- assertEquals(TriState.AUTO, BuildType.TRISTATE.convert(-1, null));
- assertEquals(TriState.YES, BuildType.TRISTATE.convert(true, null));
- assertEquals(TriState.NO, BuildType.TRISTATE.convert(false, null));
- assertEquals(TriState.YES, BuildType.TRISTATE.convert(TriState.YES, null));
- assertEquals(TriState.NO, BuildType.TRISTATE.convert(TriState.NO, null));
- assertEquals(TriState.AUTO, BuildType.TRISTATE.convert(TriState.AUTO, null));
+ assertThat(BuildType.TRISTATE.convert(1, null)).isEqualTo(TriState.YES);
+ assertThat(BuildType.TRISTATE.convert(0, null)).isEqualTo(TriState.NO);
+ assertThat(BuildType.TRISTATE.convert(-1, null)).isEqualTo(TriState.AUTO);
+ assertThat(BuildType.TRISTATE.convert(true, null)).isEqualTo(TriState.YES);
+ assertThat(BuildType.TRISTATE.convert(false, null)).isEqualTo(TriState.NO);
+ assertThat(BuildType.TRISTATE.convert(TriState.YES, null)).isEqualTo(TriState.YES);
+ assertThat(BuildType.TRISTATE.convert(TriState.NO, null)).isEqualTo(TriState.NO);
+ assertThat(BuildType.TRISTATE.convert(TriState.AUTO, null)).isEqualTo(TriState.AUTO);
assertThat(collectLabels(BuildType.TRISTATE, TriState.YES)).isEmpty();
}
@@ -227,7 +222,7 @@
public void testLabel() throws Exception {
Label label = Label
.parseAbsolute("//foo:bar");
- assertEquals(label, BuildType.LABEL.convert("//foo:bar", null, currentRule));
+ assertThat(BuildType.LABEL.convert("//foo:bar", null, currentRule)).isEqualTo(label);
assertThat(collectLabels(BuildType.LABEL, label)).containsExactly(label);
}
@@ -235,16 +230,16 @@
public void testNodepLabel() throws Exception {
Label label = Label
.parseAbsolute("//foo:bar");
- assertEquals(label, BuildType.NODEP_LABEL.convert("//foo:bar", null, currentRule));
+ assertThat(BuildType.NODEP_LABEL.convert("//foo:bar", null, currentRule)).isEqualTo(label);
assertThat(collectLabels(BuildType.NODEP_LABEL, label)).containsExactly(label);
}
@Test
public void testRelativeLabel() throws Exception {
- assertEquals(Label.parseAbsolute("//quux:wiz"),
- BuildType.LABEL.convert(":wiz", null, currentRule));
- assertEquals(Label.parseAbsolute("//quux:wiz"),
- BuildType.LABEL.convert("wiz", null, currentRule));
+ assertThat(BuildType.LABEL.convert(":wiz", null, currentRule))
+ .isEqualTo(Label.parseAbsolute("//quux:wiz"));
+ assertThat(BuildType.LABEL.convert("wiz", null, currentRule))
+ .isEqualTo(Label.parseAbsolute("//quux:wiz"));
try {
BuildType.LABEL.convert("wiz", null);
fail();
@@ -278,8 +273,8 @@
Object input = Arrays.asList("foo", "bar", "wiz");
List<String> converted =
Type.STRING_LIST.convert(input, null);
- assertEquals(input, converted);
- assertNotSame(input, converted);
+ assertThat(converted).isEqualTo(input);
+ assertThat(converted).isNotSameAs(input);
assertThat(collectLabels(Type.STRING_LIST, input)).isEmpty();
}
@@ -288,8 +283,8 @@
Object input = ImmutableMap.of("foo", "bar",
"wiz", "bang");
Map<String, String> converted = Type.STRING_DICT.convert(input, null);
- assertEquals(input, converted);
- assertNotSame(input, converted);
+ assertThat(converted).isEqualTo(input);
+ assertThat(converted).isNotSameAs(input);
assertThat(collectLabels(Type.STRING_DICT, converted)).isEmpty();
}
@@ -343,8 +338,8 @@
List<Label> expected =
Arrays.asList(Label.parseAbsolute("//foo:bar"),
Label.parseAbsolute("//quux:wiz"));
- assertEquals(expected, converted);
- assertNotSame(expected, converted);
+ assertThat(converted).isEqualTo(expected);
+ assertThat(converted).isNotSameAs(expected);
assertThat(collectLabels(BuildType.LABEL_LIST, converted)).containsExactlyElementsIn(expected);
}
@@ -392,8 +387,8 @@
Map<?, ?> expected = ImmutableMap.<String, List<String>>of(
"foo", Arrays.asList("foo", "bar"),
"wiz", Arrays.asList("bang"));
- assertEquals(expected, converted);
- assertNotSame(expected, converted);
+ assertThat(converted).isEqualTo(expected);
+ assertThat(converted).isNotSameAs(expected);
assertThat(collectLabels(Type.STRING_LIST_DICT, converted)).isEmpty();
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ValidationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ValidationTest.java
index 9b17d4b..0ad0297 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ValidationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ValidationTest.java
@@ -292,9 +292,11 @@
EvalUtils.getSkylarkType(ClassObject.class);
throw new Exception("Should have raised IllegalArgumentException exception");
} catch (IllegalArgumentException e) {
- assertThat(e.getMessage()).contains(
- "interface com.google.devtools.build.lib.syntax.ClassObject is not allowed "
- + "as a Skylark value");
+ assertThat(e)
+ .hasMessageThat()
+ .contains(
+ "interface com.google.devtools.build.lib.syntax.ClassObject is not allowed "
+ + "as a Skylark value");
}
}
@@ -313,9 +315,11 @@
SkylarkType.of(ClassObject.class);
throw new Exception("foo");
} catch (Exception e) {
- assertThat(e.getMessage()).contains(
- "interface com.google.devtools.build.lib.syntax.ClassObject "
- + "is not allowed as a Skylark value");
+ assertThat(e)
+ .hasMessageThat()
+ .contains(
+ "interface com.google.devtools.build.lib.syntax.ClassObject "
+ + "is not allowed as a Skylark value");
}
// Also test for these bazel classes, to avoid some regression.
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java b/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java
index 33ce2d8..9011cc9 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java
@@ -184,7 +184,7 @@
eval(input);
fail("Expected error containing '" + msg + "' but got no error");
} catch (IllegalArgumentException | EvalException e) {
- assertThat(e.getMessage()).contains(msg);
+ assertThat(e).hasMessageThat().contains(msg);
}
}