Skip to content

Commit

Permalink
added test for string assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
ghik committed Apr 22, 2024
1 parent ab68a80 commit 1e291b8
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,60 @@ class SchemaComparatorTest extends AnyFunSuite {
))
}

test("string assertions") {
assert(compare(
stringSchema.copy(
maxLength = Some(10),
minLength = Some(1),
pattern = Some(Pattern("[a-z]+")),
),
stringSchema,
) == Nil)

assert(compare(
stringSchema.copy(
maxLength = Some(8),
minLength = Some(3),
pattern = Some(Pattern("[a-z]+")),
),
stringSchema.copy(
maxLength = Some(10),
minLength = Some(1),
),
) == Nil)

assert(compare(
stringSchema,
stringSchema.copy(
maxLength = Some(10),
minLength = Some(1),
pattern = Some(Pattern("[a-z]+")),
),
) == List(
StringLengthBoundsMismatch(
Bounds(Some(Bound.inclusive(0)), None),
Bounds(Some(Bound.inclusive(1)), Some(Bound.inclusive(10)))),
PatternMismatch(None, Pattern("[a-z]+"))
))

assert(compare(
stringSchema.copy(
maxLength = Some(10),
minLength = Some(1),
pattern = Some(Pattern("[a-z]+")),
),
stringSchema.copy(
maxLength = Some(10),
minLength = Some(2),
pattern = Some(Pattern("[A-Z]+")),
),
) == List(
StringLengthBoundsMismatch(
Bounds(Some(Bound.inclusive(1)), Some(Bound.inclusive(10))),
Bounds(Some(Bound.inclusive(2)), Some(Bound.inclusive(10)))),
PatternMismatch(Some(Pattern("[a-z]+")), Pattern("[A-Z]+"))
))
}

//TODO significantly more tests
}

0 comments on commit 1e291b8

Please sign in to comment.