-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
48 additions
and
1 deletion.
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
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
21 changes: 21 additions & 0 deletions
21
...mmonMain/kotlin/io/github/optimumcode/json/schema/internal/formats/UuidFormatValidator.kt
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,21 @@ | ||
package io.github.optimumcode.json.schema.internal.formats | ||
|
||
import io.github.optimumcode.json.schema.FormatValidationResult | ||
import io.github.optimumcode.json.schema.FormatValidator | ||
|
||
internal object UuidFormatValidator : AbstractStringFormatValidator() { | ||
private const val UUID_LENGTH = 36 | ||
private const val HEX = "[0-9a-fA-F]" | ||
private val UUID_REGEX = Regex("$HEX{8}-$HEX{4}-$HEX{4}-$HEX{4}-$HEX{12}") | ||
|
||
override fun validate(value: String): FormatValidationResult { | ||
if (value.isEmpty() || value.length != UUID_LENGTH) { | ||
return FormatValidator.Invalid() | ||
} | ||
return if (UUID_REGEX.matches(value)) { | ||
FormatValidator.Valid() | ||
} else { | ||
FormatValidator.Invalid() | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...b/optimumcode/json/schema/assertions/general/format/JsonSchemaUuidFormatValidationTest.kt
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,24 @@ | ||
package io.github.optimumcode.json.schema.assertions.general.format | ||
|
||
import io.kotest.core.spec.style.FunSpec | ||
|
||
class JsonSchemaUuidFormatValidationTest : FunSpec() { | ||
init { | ||
formatValidationTestSuite( | ||
format = "uuid", | ||
validTestCases = | ||
listOf( | ||
"f81d4fae-7dec-11d0-a765-00a0c91e6bf6", | ||
"F81D4FAE-7DEC-11D0-A765-00A0C91E6BF6", | ||
), | ||
invalidTestCases = | ||
listOf( | ||
TestCase("", "empty value"), | ||
TestCase("f81d4fae-7dec-11d0-a765-00a0c91e6bf", "too short"), | ||
TestCase("f81d4fae-7dec-11d0-a765-00a0c91e6bf64", "too long"), | ||
TestCase("f81d4fae-7dec-11d0-a7865-00a0c91e6bf64", "wrong block length"), | ||
TestCase("f81d4fae-7dec-11d0-g765-00a0c91e6bf6", "invalid character"), | ||
), | ||
) | ||
} | ||
} |
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