-
Notifications
You must be signed in to change notification settings - Fork 24
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
Adding a test to validate line numbers and fix for multiline strings #217
Changes from 11 commits
b29e214
591aad5
005b53d
e316451
a45c851
a52b588
cfb14a8
cc2e1de
5d7a3c7
6999fd3
c92b3e0
ef6e3d9
43c4e9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.akuleshov7.ktoml.parsers | ||
|
||
import com.akuleshov7.ktoml.Toml | ||
import com.akuleshov7.ktoml.tree.nodes.TomlKeyValuePrimitive | ||
import kotlin.test.Test | ||
import kotlin.test.assertContentEquals | ||
import kotlin.test.assertEquals | ||
|
||
class SetLineNoTest { | ||
@Test | ||
fun checkingLineNumbers() { | ||
val string = """ | ||
|
||
# comment 1 | ||
|
||
[a] # comment 2 | ||
# comment 3 | ||
test = 1 # comment 4 | ||
|
||
# ==== | ||
|
||
[[a.b]] # comment 5 | ||
test = 1 | ||
|
||
mls = ''' | ||
1 | ||
2 | ||
3 | ||
''' | ||
|
||
mla = [ | ||
"a", | ||
"b", | ||
"c" | ||
orchestr7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
] | ||
""".trimIndent() | ||
val parsedToml = Toml.tomlParser.parseString(string) | ||
|
||
parsedToml.prettyPrint(true) | ||
assertEquals( | ||
""" | ||
| - TomlFile (rootNode)[line:0] | ||
| - TomlTablePrimitive ([a])[line:4] | ||
| - TomlKeyValuePrimitive (test=1)[line:6] | ||
| - TomlArrayOfTables ([[a.b]])[line:10] | ||
| - TomlArrayOfTablesElement (technical_node)[line:10] | ||
| - TomlKeyValuePrimitive (test=1)[line:11] | ||
| - TomlKeyValuePrimitive (mls=''' 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's a little bit weird, cause it looks like we forget to put a newline after multiline string delimiters There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @NightEule5 while we encode the string, I think it is necessary for the user to have a proper formatting of multiline strings. Now we have the following:
I think (even the TOML spec is confusing here) that we should add a newline there (it will be more convenient):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, true There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And of course I have forgotten to trim spaces before the quotes |
||
| 2 | ||
| 3 | ||
| ''')[line:13] | ||
| - TomlKeyValueArray (mla=[ "a", "b", "c" ])[line:18] | ||
| | ||
""".trimMargin(), | ||
parsedToml.prettyStr(true) | ||
) | ||
} | ||
} |
Check failure
Code scanning / ktlint
[STRING_TEMPLATE_CURLY_BRACES] string template has redundant curly braces: ${node}