Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7dc6105
Add schema-test-suite repository as submodule
OptimumCode Jul 25, 2023
c283dee
Move schema test suites
OptimumCode Jul 26, 2023
616e33f
Implement test suites base. Add test suite for draft7
OptimumCode Jul 26, 2023
62370a0
Init submodules
OptimumCode Jul 26, 2023
646a59b
Correct the equailty check for numbers
OptimumCode Jul 26, 2023
9dbc2a7
Correct enum assertion to correctly work with numbers
OptimumCode Jul 26, 2023
2613504
Correct type to correctly treat numbers with zero fraction part as in…
OptimumCode Jul 26, 2023
09d449d
Handle engineering number format
OptimumCode Jul 26, 2023
27fcd20
Treat numbers with zero fraction as valid integers
OptimumCode Jul 26, 2023
6a9107a
Correct unique items assertion to correctly work with numbers
OptimumCode Jul 26, 2023
c6b2ce3
Correct multipleOf assertion to work with small numbers
OptimumCode Jul 26, 2023
a91d079
Correct number comparison
OptimumCode Jul 26, 2023
26d43d4
Reformat code. Correct detekt errors
OptimumCode Jul 26, 2023
dd1d149
Fix incorrect precision computation
OptimumCode Jul 26, 2023
ff1ce0a
Use linked maps to keep reproducable order
OptimumCode Jul 27, 2023
e62c586
Exclude unsupported functionality from test-suites
OptimumCode Jul 27, 2023
640f122
Add proper support for unicode characters
OptimumCode Jul 27, 2023
9fa6d4d
Load all if-then-else assertions because they might be referenced
OptimumCode Jul 27, 2023
e501479
Correct work with empty path segment in JSON pointer
OptimumCode Jul 27, 2023
f5174a6
Add quotation for special characters when adding segment to pointer
OptimumCode Jul 27, 2023
2fc0a7b
Correct uri resolution
OptimumCode Jul 28, 2023
a8ab2e6
Add resolution for test suites for nodejs test run
OptimumCode Jul 28, 2023
8b2156c
Remove todo comment. Create an issue for that instead
OptimumCode Jul 28, 2023
b667649
Correct test name to correctly work on windows
OptimumCode Jul 28, 2023
a663df4
Correct formatting
OptimumCode Jul 28, 2023
ea6828a
Use chars instead of string for quotation
OptimumCode Jul 28, 2023
7036f8a
Add note about test suite compliance
OptimumCode Jul 28, 2023
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add proper support for unicode characters
  • Loading branch information
OptimumCode committed Jul 27, 2023
commit 640f122b21a6169f91dbd86ca0aa366e75843f6e
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.github.optimumcode.json.schema.ErrorCollector
import io.github.optimumcode.json.schema.ValidationError
import io.github.optimumcode.json.schema.internal.AssertionContext
import io.github.optimumcode.json.schema.internal.JsonSchemaAssertion
import io.github.optimumcode.json.schema.internal.factories.string.util.codePointCount
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.contentOrNull
Expand All @@ -20,14 +21,15 @@ internal class LengthAssertion(
return true
}
val content = element.contentOrNull ?: return true
if (check(content.length, lengthValue)) {
val codePointCount = content.codePointCount()
if (check(codePointCount, lengthValue)) {
return true
}
errorCollector.onError(
ValidationError(
schemaPath = path,
objectPath = context.objectPath,
message = "string length (${content.length}) $errorMessage $lengthValue",
message = "string length ($codePointCount) $errorMessage $lengthValue",
),
)
return false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.github.optimumcode.json.schema.internal.factories.string.util

internal fun CharSequence.codePointCount(): Int {
val endIndex = length
var index = 0
var count = 0
while (index < endIndex) {
val firstChar = this[index]
index++
if (firstChar.isHighSurrogate() && index < endIndex) {
val nextChar = this[index]
if (nextChar.isLowSurrogate()) {
index++
}
}

count++
}

return count
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.github.optimumcode.json.pointer.JsonPointer
import io.github.optimumcode.json.schema.JsonSchema
import io.github.optimumcode.json.schema.ValidationError
import io.github.optimumcode.json.schema.base.KEY
import io.github.optimumcode.json.schema.internal.factories.string.util.codePointCount
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.collections.shouldContainExactly
import io.kotest.matchers.collections.shouldHaveSize
Expand Down Expand Up @@ -32,6 +33,8 @@ class JsonSchemaMaxLengthValidationTest : FunSpec() {
"╒",
"V",
"",
"💩".repeat(20),
"💩",
)
for (str in validStrings) {
test("'$str' passes validation") {
Expand All @@ -46,6 +49,7 @@ class JsonSchemaMaxLengthValidationTest : FunSpec() {
"EFDzZMRawYGD9eNfknAUB",
"⌻ⲝ⣞ℤ⸍⠗⠜ↈ✋☧⾛✩ⓥ⇩⡽⚘\u20FC◭┐⥸⒗",
"⠺⪒⑸⋶⥠⇀⨑⨋ⅸ⥼\u245F⏇Ⓙⴷ⻘⢢≧\u20C8⬫⡜⸁",
"💩".repeat(21),
)
for (str in invalidStrings) {
test("'$str' does not pass validation") {
Expand All @@ -56,7 +60,7 @@ class JsonSchemaMaxLengthValidationTest : FunSpec() {
ValidationError(
schemaPath = JsonPointer("/maxLength"),
objectPath = JsonPointer.ROOT,
message = "string length (${str.length}) must be less or equal to 20",
message = "string length (${str.codePointCount()}) must be less or equal to 20",
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.github.optimumcode.json.pointer.JsonPointer
import io.github.optimumcode.json.schema.JsonSchema
import io.github.optimumcode.json.schema.ValidationError
import io.github.optimumcode.json.schema.base.KEY
import io.github.optimumcode.json.schema.internal.factories.string.util.codePointCount
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.collections.shouldContainExactly
import io.kotest.matchers.collections.shouldHaveSize
Expand Down Expand Up @@ -31,6 +32,8 @@ class JsonSchemaMinLengthValidationTest : FunSpec() {
"JpEblYiJE57H70qGNXs",
"ⅵ┡\u243A⢻␀⁾⡪∛⫑⏽",
"Si1kaAhdpS",
"💩".repeat(11),
"💩".repeat(10),
)
for (str in validStrings) {
test("'$str' passes validation") {
Expand All @@ -47,6 +50,7 @@ class JsonSchemaMinLengthValidationTest : FunSpec() {
" ⍘↽♔⚪➕ⷰ➖",
"⧦",
"",
"💩".repeat(9),
)
for (str in invalidStrings) {
test("'$str' does not pass validation") {
Expand All @@ -57,7 +61,7 @@ class JsonSchemaMinLengthValidationTest : FunSpec() {
ValidationError(
schemaPath = JsonPointer("/minLength"),
objectPath = JsonPointer.ROOT,
message = "string length (${str.length}) must be greater or equal to 10",
message = "string length (${str.codePointCount()}) must be greater or equal to 10",
),
)
}
Expand Down