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

Initial commit for test-toml #141

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1,445 changes: 7 additions & 1,438 deletions kotlin-js-store/yarn.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ktoml-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ kotlin {
explicitApi()

js(IR) {
browser()
nodejs()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class TomlAbstractDecoder : AbstractDecoder() {
// Invalid Toml primitive types, we will simply throw an error for them
override fun decodeByte(): Byte = invalidType("Byte", "Long")
override fun decodeShort(): Short = invalidType("Short", "Long")
override fun decodeInt(): Int = invalidType("Int", "Long")
override fun decodeInt(): Int = decodePrimitiveType()
override fun decodeFloat(): Float = invalidType("Float", "Double")
override fun decodeChar(): Char = invalidType("Char", "String")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.akuleshov7.ktoml.decoders

import com.akuleshov7.ktoml.Toml
import com.akuleshov7.ktoml.tree.TomlInlineTable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
1 change: 1 addition & 0 deletions ktoml-file/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ kotlin {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:${Versions.SERIALIZATION}")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.akuleshov7.certification

import com.akuleshov7.certification.schemas.*
import com.akuleshov7.ktoml.Toml
import com.akuleshov7.ktoml.file.getOsSpecificFileSystem
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import okio.Path.Companion.toPath
import kotlin.test.Test

class CertificationTest {
@Test
fun `VALID parse TOML files and compare it with JSON result`() {
val jsonPath = "src/commonTest/resources/toml_certification/valid/array/array.json".toPath()
val tomlPath = "src/commonTest/resources/toml_certification/valid/array/array.toml".toPath()

val toml = getOsSpecificFileSystem().read(tomlPath) {
generateSequence { readUtf8Line() }.toList()
}

val json = getOsSpecificFileSystem().read(jsonPath) {
generateSequence { readUtf8Line() }.toList()
}

println(
Json.decodeFromString<ArrayCertification>(json.joinToString("\n"))
== Toml.decodeFromString<ArrayCertification>(toml.joinToString("\n"))
)
}

@Test
fun `INVALID fail during parsing of TOML`() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.akuleshov7.certification.schemas

import kotlinx.datetime.LocalDateTime
import kotlinx.serialization.Serializable

@Serializable
data class ArrayCertification(
val ints: List<Int>,
val floats: List<Float>,
val dates: List<LocalDateTime>,
val comments: List<Int>,
val strings: List<String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wrong = [ 1 2 3 ]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = [42 #
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = [{ key = 42 #
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = [{ key = 42
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
long_array = [ 1, 2, 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# INVALID TOML DOC
fruit = []

[[fruit]] # Not allowed
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# INVALID TOML DOC
[[fruit]]
name = "apple"

[[fruit.variety]]
name = "red delicious"

# This table conflicts with the previous table
[fruit.variety]
name = "granny smith"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
array = [
"Is there life after an array separator?", No
"Entry"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
array = [
"Is there life before an array separator?" No,
"Entry"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
array = [
"Entry 1",
I don't belong,
"Entry 2",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = falsify
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = fals
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = truthy
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = tru
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = f
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = t
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
valid = False
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = falsey
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = truer
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b = FALSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = TRUE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# The following line contains a single carriage return control character

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bare-formfeed =
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bare-vertical-tab =
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment-cr = "Carriage return in comment" # a=1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment-del = "0x7f" # 
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment-lf = "ctrl-P" # 
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment-us = "ctrl-_" # 
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# "\x.." sequences are replaced with literal control characters.

comment-null = "null" # \x00
comment-lf = "ctrl-P" # \x10
comment-us = "ctrl-_" # \x1f
comment-del = "0x7f" # \x7f
comment-cr = "Carriage return in comment" # \x0da=1

string-null = "null\x00"
string-lf = "null\x10"
string-us = "null\x1f"
string-del = "null\x7f"

rawstring-null = 'null\x00'
rawstring-lf = 'null\x10'
rawstring-us = 'null\x1f'
rawstring-del = 'null\x7f'

multi-null = """null\x00"""
multi-lf = """null\x10"""
multi-us = """null\x1f"""
multi-del = """null\x7f"""

rawmulti-null = '''null\x00'''
rawmulti-lf = '''null\x10'''
rawmulti-us = '''null\x1f'''
rawmulti-del = '''null\x7f'''

string-bs = "backspace\x08"

bare-null = "some value" \x00
bare-formfeed = \x0c
bare-vertical-tab = \x0b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
multi-del = """null"""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
multi-lf = """null"""
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
multi-us = """null"""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rawmulti-del = '''null'''
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rawmulti-lf = '''null'''
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rawmulti-us = '''null'''
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rawstring-del = 'null'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rawstring-lf = 'null'
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rawstring-us = 'null'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
string-bs = "backspace"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
string-del = "null"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
string-lf = "null"
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
string-us = "null"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# time-hour = 2DIGIT ; 00-23
d = 2006-01-01T24:00:00-00:00
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on
# ; month/year
d = 2006-01-32T00:00:00-00:00
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on
# ; month/year
d = 2006-01-00T00:00:00-00:00
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# time-minute = 2DIGIT ; 00-59
d = 2006-01-01T00:60:00-00:00
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# date-month = 2DIGIT ; 01-12
d = 2006-13-01T00:00:00-00:00
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# date-month = 2DIGIT ; 01-12
d = 2007-00-01T00:00:00-00:00
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Day "5" instead of "05"; the leading zero is required.
with-milli = 1987-07-5T17:45:00.12Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Month "7" instead of "07"; the leading zero is required.
no-leads = 1987-7-05T17:45:00Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# No seconds in time.
no-secs = 1987-07-05T17:45Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# No "t" or "T" between the date and time.
no-t = 1987-07-0517:45:00Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# time-second = 2DIGIT ; 00-58, 00-59, 00-60 based on leap second
# ; rules
d = 2006-01-01T00:00:61-00:00
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Leading 0 is always required.
d = 01:32:0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Leading 0 is always required.
d = 1:32:00
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Date cannot end with trailing T
d = 2006-01-30T
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# There is a 0xda at after the quotes, and no EOL at the end of the file.
#
# This is a bit of an edge case: This indicates there should be two bytes
# (0b1101_1010) but there is no byte to follow because it's the end of the file.
x = """"""�
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# �
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# The following line contains an invalid UTF-8 sequence.
bad = "�"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bom-not-at-start ��
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bom-not-at-start= ��
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
double-point-1 = 0..1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
double-point-2 = 0.1.2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exp-double-e-1 = 1ee2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exp-double-e-2 = 1e2e3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exp-double-us = 1e__23
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exp-leading-us = 1e_23
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exp-point-1 = 1e2.3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exp-point-2 = 1.e2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exp-trailing-us = 1e_23_
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
leading-zero = 03.14
leading-zero-neg = -03.14
leading-zero-plus = +03.14

leading-point = .12345
leading-point-neg = -.12345
leading-point-plus = +.12345

trailing-point = 1.
trailing-point-min = -1.
trailing-point-plus = +1.

trailing-us = 1.2_
leading-us = _1.2
us-before-point = 1_.2
us-after-point = 1._2

double-point-1 = 0..1
double-point-2 = 0.1.2

exp-point-1 = 1e2.3
exp-point-2 = 1.e2

exp-double-e-1 = 1ee2
exp-double-e-2 = 1e2e3

exp-leading-us = 1e_23
exp-trailing-us = 1e_23_
exp-double-us = 1e__23

inf-incomplete-1 = in
inf-incomplete-2 = +in
inf-incomplete-3 = -in

nan-incomplete-1 = na
nan-incomplete-2 = +na
nan-incomplete-3 = -na

nan_underscore = na_n
inf_underscore = in_f
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inf-incomplete-1 = in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inf-incomplete-2 = +in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inf-incomplete-3 = -in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inf_underscore = in_f
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
leading-point-neg = -.12345
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
leading-point-plus = +.12345
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
leading-point = .12345
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
leading-us = _1.2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
leading-zero-neg = -03.14
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
leading-zero-plus = +03.14
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
leading-zero = 03.14
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nan-incomplete-1 = na
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nan-incomplete-2 = +na
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nan-incomplete-3 = -na
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nan_underscore = na_n
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trailing-point-min = -1.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trailing-point-plus = +1.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trailing-point = 1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# trailing underscore in integer part is not allowed
trailing-us-exp = 1_e2
# trailing underscore in float part is not allowed
trailing-us-exp2 = 1.2_e2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trailing-us = 1.2_
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
us-after-point = 1._2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
us-before-point = 1_.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a={}
# Inline tables are immutable and can't be extended
[a.b]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
t = {x=3,,y=4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Duplicate keys within an inline table are invalid
a={b=1, b=2}
Loading