move newKey and newPath to Path from PathBuilder

This commit is contained in:
Havoc Pennington 2011-11-10 14:44:43 -05:00
parent e0a49c06da
commit fb2d68ff3c
4 changed files with 26 additions and 26 deletions

View File

@ -95,4 +95,14 @@ final class Path {
appendToStringBuilder(sb);
return sb.toString();
}
static Path newKey(String key) {
return new Path(key, null);
}
static Path newPath(String path) {
PathBuilder pb = new PathBuilder();
pb.appendPath(path);
return pb.result();
}
}

View File

@ -54,14 +54,4 @@ final class PathBuilder {
}
return result;
}
static Path newPath(String path) {
PathBuilder pb = new PathBuilder();
pb.appendPath(path);
return pb.result();
}
static Path newKey(String key) {
return new Path(key, null);
}
}

View File

@ -8,12 +8,12 @@ class PathTest extends TestUtils {
@Test
def pathEquality() {
// note: foo.bar is a single key here
val a = PathBuilder.newKey("foo.bar")
val sameAsA = PathBuilder.newKey("foo.bar")
val differentKey = PathBuilder.newKey("hello")
val a = Path.newKey("foo.bar")
val sameAsA = Path.newKey("foo.bar")
val differentKey = Path.newKey("hello")
// here foo.bar is two elements
val twoElements = PathBuilder.newPath("foo.bar")
val sameAsTwoElements = PathBuilder.newPath("foo.bar")
val twoElements = Path.newPath("foo.bar")
val sameAsTwoElements = Path.newPath("foo.bar")
checkEqualObjects(a, a)
checkEqualObjects(a, sameAsA)
@ -24,18 +24,18 @@ class PathTest extends TestUtils {
@Test
def pathToString() {
assertEquals("Path(foo)", PathBuilder.newPath("foo").toString())
assertEquals("Path(foo.bar)", PathBuilder.newPath("foo.bar").toString())
assertEquals("Path(foo.\"bar*\")", PathBuilder.newPath("foo.bar*").toString())
assertEquals("Path(\"foo.bar\")", PathBuilder.newKey("foo.bar").toString())
assertEquals("Path(foo)", Path.newPath("foo").toString())
assertEquals("Path(foo.bar)", Path.newPath("foo.bar").toString())
assertEquals("Path(foo.\"bar*\")", Path.newPath("foo.bar*").toString())
assertEquals("Path(\"foo.bar\")", Path.newKey("foo.bar").toString())
}
@Test
def pathRender() {
assertEquals("foo", PathBuilder.newPath("foo").render())
assertEquals("foo.bar", PathBuilder.newPath("foo.bar").render())
assertEquals("foo.\"bar*\"", PathBuilder.newPath("foo.bar*").render())
assertEquals("\"foo.bar\"", PathBuilder.newKey("foo.bar").render())
assertEquals("foo bar", PathBuilder.newKey("foo bar").render())
assertEquals("foo", Path.newPath("foo").render())
assertEquals("foo.bar", Path.newPath("foo.bar").render())
assertEquals("foo.\"bar*\"", Path.newPath("foo.bar*").render())
assertEquals("\"foo.bar\"", Path.newKey("foo.bar").render())
assertEquals("foo bar", Path.newKey("foo bar").render())
}
}

View File

@ -238,13 +238,13 @@ abstract trait TestUtils {
}
protected def subst(ref: String) = {
val pieces = java.util.Collections.singletonList[Object](PathBuilder.newPath(ref))
val pieces = java.util.Collections.singletonList[Object](Path.newPath(ref))
new ConfigSubstitution(fakeOrigin(), pieces)
}
protected def substInString(ref: String) = {
import scala.collection.JavaConverters._
val pieces = List("start<", PathBuilder.newPath(ref), ">end")
val pieces = List("start<", Path.newPath(ref), ">end")
new ConfigSubstitution(fakeOrigin(), pieces.asJava)
}