Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #59

Merged
merged 5 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
version=2.4.2
version=2.5.0-RC1
align.openParenCallSite = true
align.openParenDefnSite = true
maxColumn = 120
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
danglingParentheses = true
rewrite.rules = [AvoidInfix, SortImports, RedundantBraces, RedundantParens, SortModifiers]
rewrite.rules = [AvoidInfix, SortImports, RedundantParens, SortModifiers]
docstrings = JavaDoc
newlines.alwaysBeforeMultilineDef = false
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: scala
dist: xenial

scala:
- 2.13.1
- 2.13.2
- 2.12.11

jdk:
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ val previousVersion = "0.2.0"
val catsVersion = "2.1.1"
val circeVersion = "0.13.0"
val jawnVersion = "1.0.0"
val munitVersion = "0.7.2"
val munitVersion = "0.7.3"
val scalaCheckVersion = "1.14.3"
val snakeYamlVersion = "1.26"
val http4sVersion = "0.21.3"
Expand All @@ -19,7 +19,7 @@ val testDependencies = Seq(

val http4sDependencies = Seq(
"org.typelevel" %% "cats-core" % catsVersion,
"org.typelevel" %% "cats-effect" % "2.1.2",
"org.typelevel" %% "cats-effect" % "2.1.3",
"org.http4s" %% "http4s-client" % http4sVersion
)
val http4sBlazeClient =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ object Canonicalization {
case i => F.pure(i)
}

def canonicalize[F[_]](parent: ImportContext, child: ImportContext)(
implicit F: Sync[F]
def canonicalize[F[_]](parent: ImportContext, child: ImportContext)(implicit
F: Sync[F]
): F[ImportContext] =
parent match {
case Remote(uri, headers) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ object ImportCache {

def backupCache =
for {
cacheO <- if (isWindows)
makeCacheFromEnvVar("LOCALAPPDATA", "")
else makeCacheFromEnvVar("HOME", ".cache")
cacheO <-
if (isWindows)
makeCacheFromEnvVar("LOCALAPPDATA", "")
else makeCacheFromEnvVar("HOME", ".cache")
cache <- cacheO.fold[F[ImportCache[F]]](F.as(warnCacheNotCreated, new NoopImportCache[F]))(F.pure)
} yield cache

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ final private class ResolveImportsVisitor[F[_] <: AnyRef](
semanticCache: ImportCache[F],
semiSemanticCache: ImportCache[F],
parents: NonEmptyList[ImportContext]
)(
implicit Client: Client[F],
)(implicit
Client: Client[F],
F: Sync[F]
) extends LiftVisitor[F](F) {
def this(
Expand Down Expand Up @@ -211,11 +211,13 @@ private object ResolveImportsVisitor {

def apply[F[_] <: AnyRef: Sync: Client](semanticCache: ImportCache[F],
semiSemanticCache: ImportCache[F],
relativeTo: Path): ResolveImportsVisitor[F] =
relativeTo: Path
): ResolveImportsVisitor[F] =
//We add a placeholder filename "package.dhall" for the base directory as a Local import must have a filename
new ResolveImportsVisitor(semanticCache,
semiSemanticCache,
NonEmptyList.one(Local(relativeTo.resolve("package.dhall"))))
NonEmptyList.one(Local(relativeTo.resolve("package.dhall")))
)

def apply[F[_] <: AnyRef: Sync: Client](semanticCache: ImportCache[F], relativeTo: Path): ResolveImportsVisitor[F] =
apply[F](semanticCache, new ImportCache.NoopImportCache, relativeTo)
Expand All @@ -225,7 +227,8 @@ private object ResolveImportsVisitor {
def apply[F[_] <: AnyRef: Sync: Client]: F[ResolveImportsVisitor[F]] = apply[F](cwd)

def apply[F[_] <: AnyRef: Sync: Client](semanticCache: ImportCache[F],
semiSemanticCache: ImportCache[F]): ResolveImportsVisitor[F] =
semiSemanticCache: ImportCache[F]
): ResolveImportsVisitor[F] =
apply[F](semanticCache, semiSemanticCache, cwd)

def apply[F[_] <: AnyRef: Sync: Client](semanticCache: ImportCache[F]): ResolveImportsVisitor[F] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ class CanonicalizationSuite extends FunSuite {

test("Imports - quoted") {
assertEquals(canonicalize[IO](Local(Paths.get("/\"foo\"/\"bar.dhall\""))).unsafeRunSync,
Local(Paths.get("/foo/bar.dhall")))
Local(Paths.get("/foo/bar.dhall"))
)
}

test("Paths - Trailing .") {
assertEquals(canonicalize[IO](Local(Paths.get("/foo/./bar.dhall"))).unsafeRunSync,
Local(Paths.get("/foo/bar.dhall")))
Local(Paths.get("/foo/bar.dhall"))
)
}

test("Paths - Trailing ..") {
assertEquals(canonicalize[IO](Local(Paths.get("/foo/bar/../baz.dhall"))).unsafeRunSync,
Local(Paths.get("/foo/baz.dhall")))
Local(Paths.get("/foo/baz.dhall"))
)
}

//TODO determine whether spec is correct on this
Expand Down Expand Up @@ -155,30 +158,37 @@ class CanonicalizationSuite extends FunSuite {

test("Chaining - local / remote") {
assertEquals(
canonicalize[IO](Local(Paths.get("/foo/bar.dhall")), Remote(new URI("http://foo.org/bar.dhall"), headers1)).unsafeRunSync,
canonicalize[IO](Local(Paths.get("/foo/bar.dhall")),
Remote(new URI("http://foo.org/bar.dhall"), headers1)
).unsafeRunSync,
Remote(new URI("http://foo.org/bar.dhall"), headers1)
)
}

test("Chaining - remote / remote absolute") {
assertEquals(
canonicalize[IO](Remote(new URI("http://foo.org/bar.dhall"), headers1),
Remote(new URI("https://bar.com/bar/baz.dhall"), headers2)).unsafeRunSync,
Remote(new URI("https://bar.com/bar/baz.dhall"), headers2)
).unsafeRunSync,
Remote((new URI("https://bar.com/bar/baz.dhall")), headers2)
)
}

test("Chaining - remote / local relative") {
assertEquals(
canonicalize[IO](Remote(new URI("http://foo.org/bar.dhall"), headers1), Local(Paths.get("./baz.dhall"))).unsafeRunSync,
canonicalize[IO](Remote(new URI("http://foo.org/bar.dhall"), headers1),
Local(Paths.get("./baz.dhall"))
).unsafeRunSync,
Remote(new URI("http://foo.org/baz.dhall"), headers1)
)
}

//This is actually prohibited by the sanity check but we don't worry about it here
test("Chaining - remote / local absolute") {
assertEquals(
canonicalize[IO](Remote(new URI("http://foo.org/bar.dhall"), headers1), Local(Paths.get("/baz.dhall"))).unsafeRunSync,
canonicalize[IO](Remote(new URI("http://foo.org/bar.dhall"), headers1),
Local(Paths.get("/baz.dhall"))
).unsafeRunSync,
Local(Paths.get("/baz.dhall"))
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ class CorsComplianceCheckSuite extends FunSuite {
test("Remote - different origin, allow *") {
CorsComplianceCheck[IO](Remote(fooOrigin, null),
Remote(barOrigin, null),
Headers.of(Header("Access-Control-Allow-Origin", "*"))).unsafeRunSync()
Headers.of(Header("Access-Control-Allow-Origin", "*"))
).unsafeRunSync()
}

test("Remote - different origin, allow parent authority") {
CorsComplianceCheck[IO](Remote(fooOrigin, null),
Remote(barOrigin, null),
Headers.of(Header("Access-Control-Allow-Origin", "http://foo.org"))).unsafeRunSync()
Headers.of(Header("Access-Control-Allow-Origin", "http://foo.org"))
).unsafeRunSync()
}

test("Remote - different origin".fail) {
Expand All @@ -40,25 +42,29 @@ class CorsComplianceCheckSuite extends FunSuite {
test("Remote - different origin, cors parent different authority".fail) {
CorsComplianceCheck[IO](Remote(fooOrigin, null),
Remote(barOrigin, null),
Headers.of(Header("Access-Control-Allow-Origin", "http://bar.org"))).unsafeRunSync()
Headers.of(Header("Access-Control-Allow-Origin", "http://bar.org"))
).unsafeRunSync()
}

test("Remote - different origin, cors parent different scheme".fail) {
CorsComplianceCheck[IO](Remote(fooOrigin, null),
Remote(barOrigin, null),
Headers.of(Header("Access-Control-Allow-Origin", "https://foo.org"))).unsafeRunSync()
Headers.of(Header("Access-Control-Allow-Origin", "https://foo.org"))
).unsafeRunSync()
}

test("Remote - different origin, cors parent different port".fail) {
CorsComplianceCheck[IO](Remote(fooOrigin, null),
Remote(barOrigin, null),
Headers.of(Header("Access-Control-Allow-Origin", "http://foo.org:8080"))).unsafeRunSync()
Headers.of(Header("Access-Control-Allow-Origin", "http://foo.org:8080"))
).unsafeRunSync()
}

test("Remote - different origin, cors parent different port 2".fail) {
CorsComplianceCheck[IO](Remote(fooOrigin8080, null),
Remote(barOrigin, null),
Headers.of(Header("Access-Control-Allow-Origin", "http://foo.org"))).unsafeRunSync()
Headers.of(Header("Access-Control-Allow-Origin", "http://foo.org"))
).unsafeRunSync()
}

test("Local") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ class ImportResolutionSuite extends FunSuite {
val cached = parse("let x = 1 in x")
val expected = parse("let x = 2 in x")
val encoded = cached.normalize.alphaNormalize.getEncodedBytes
val hash = MessageDigest.getInstance("SHA-256").digest(expected.normalize.getEncodedBytes) //Hash doesn't match what is stored
val hash =
MessageDigest
.getInstance("SHA-256")
.digest(expected.normalize.getEncodedBytes) //Hash doesn't match what is stored

val expr =
parse(
Expand Down
3 changes: 2 additions & 1 deletion modules/scala/src/main/scala/org/dhallj/ast/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ object UnionType extends Constructor[Map[String, Option[Expr]]] {
protected[this] val extractor: ExternalVisitor[Option[Result]] =
new OptionVisitor[Result] {
override def onUnionType(fields: JIterable[JMap.Entry[String, Expr]],
size: Int): Option[Map[String, Option[Expr]]] =
size: Int
): Option[Map[String, Option[Expr]]] =
Some(fields.asScala.map(entryToOptionTuple).toMap)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ trait ArbitraryInstances {
genType(defaultMaxDepth).flatMap(tpe =>
genForType(tpe).map(_.map(expr => Annotated(expr, tpe))).getOrElse(genType(defaultMaxDepth))
)
*/
*/
)
.map(WellTypedExpr(_))
)
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.0")
addSbtPlugin("dev.travisbrown" % "sbt-javacc" % "0.1.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.7")
16 changes: 4 additions & 12 deletions tests/src/main/scala/org/dhallj/tests/CheckersFunSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,13 @@ class CheckersFunSuite(
f: A => P,
testConfig: Test.Parameters = defaultTestConfig,
prettyConfig: Pretty.Params = defaultPrettyConfig
)(implicit
loc: Location,
tp: P => Prop,
AA: Arbitrary[A],
AS: Shrink[A],
AP: A => Pretty): Unit = check(Prop.forAll(f)(tp, AA, AS, AP), testConfig, prettyConfig)
)(implicit loc: Location, tp: P => Prop, AA: Arbitrary[A], AS: Shrink[A], AP: A => Pretty): Unit =
check(Prop.forAll(f)(tp, AA, AS, AP), testConfig, prettyConfig)

def testAll1[A, P](name: String)(
f: A => P,
testConfig: Test.Parameters = defaultTestConfig,
prettyConfig: Pretty.Params = defaultPrettyConfig
)(implicit
loc: Location,
tp: P => Prop,
AA: Arbitrary[A],
AS: Shrink[A],
AP: A => Pretty): Unit = test(name)(check1(f, testConfig, prettyConfig))
)(implicit loc: Location, tp: P => Prop, AA: Arbitrary[A], AS: Shrink[A], AP: A => Pretty): Unit =
test(name)(check1(f, testConfig, prettyConfig))
}