-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- preserve object field order (#298)
- preserve object field order - introduce schema equality framework - introduce schema matcher to me used in tests for detailed difference presentation
- Loading branch information
Showing
10 changed files
with
390 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
api/src/test/scala/com/github/andyglow/jsonschema/SchemaMatchers.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.github.andyglow.jsonschema | ||
|
||
import com.github.andyglow.jsonschema.SchemaEquality.{ Equal, UnEqual } | ||
import json.Schema | ||
import org.scalatest.enablers.Sequencing | ||
import org.scalatest.matchers.{MatchResult, Matcher} | ||
|
||
class SchemaMatchers(right: Schema[_], checkOrder: Boolean) extends Matcher[Schema[_]] { | ||
|
||
override def apply(left: Schema[_]): MatchResult = { | ||
import Schema._, `object`.Field | ||
|
||
val eq = SchemaEquality(checkOrder).compute(left, right) | ||
val explanation = eq match { | ||
case Equal => "" | ||
case UnEqual(diff) => " due to " + diff.toDebugString | ||
} | ||
|
||
MatchResult( | ||
eq == Equal, | ||
left.toDebugString + " was not equal to " + right.toDebugString + explanation, | ||
left.toDebugString + " was equal to " + right.toDebugString | ||
) | ||
} | ||
} | ||
|
||
object SchemaMatchers { | ||
|
||
def matchSchema(x: Schema[_]) = new SchemaMatchers(x, checkOrder = true) | ||
|
||
def unorderedMatchSchema(x: Schema[_]) = new SchemaMatchers(x, checkOrder = false) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.