parent
2dddbfe588
commit
9711d6b62a
|
@ -11,7 +11,9 @@
|
||||||
|
|
||||||
##### Bug Fixes
|
##### Bug Fixes
|
||||||
|
|
||||||
* None.
|
* Fix parse quoted values as strings.
|
||||||
|
[Norio Nomura](https://github.com/norio-nomura)
|
||||||
|
[#116](https://github.com/jpsim/Yams/issues/116)
|
||||||
|
|
||||||
## 0.6.0
|
## 0.6.0
|
||||||
|
|
||||||
|
|
|
@ -287,9 +287,8 @@ private class Event {
|
||||||
return Node.Scalar.Style(rawValue: event.data.scalar.style.rawValue)!
|
return Node.Scalar.Style(rawValue: event.data.scalar.style.rawValue)!
|
||||||
}
|
}
|
||||||
var scalarTag: String? {
|
var scalarTag: String? {
|
||||||
guard event.data.scalar.plain_implicit == 0,
|
if event.data.scalar.quoted_implicit == 1 {
|
||||||
event.data.scalar.quoted_implicit == 0 else {
|
return Tag.Name.str.rawValue
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
return string(from: event.data.scalar.tag)
|
return string(from: event.data.scalar.tag)
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,6 +287,67 @@ class ConstructorTests: XCTestCase { // swiftlint:disable:this type_body_length
|
||||||
YamsAssertEqual(objects, expected)
|
YamsAssertEqual(objects, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testQuotationMark() throws {
|
||||||
|
// swiftlint:disable line_length
|
||||||
|
// ```terminal.sh-session
|
||||||
|
// $ python
|
||||||
|
// Python 3.6.4 (default, Mar 16 2018, 17:10:15)
|
||||||
|
// [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.37.1)] on darwin
|
||||||
|
// Type "help", "copyright", "credits" or "license" for more information.
|
||||||
|
// >>> import yaml
|
||||||
|
// >>> yaml.load(r"""plain: 10.10
|
||||||
|
// ... single quote: '10.10'
|
||||||
|
// ... double quote: "10.10"
|
||||||
|
// ... literal: |
|
||||||
|
// ... 10.10
|
||||||
|
// ... literal single quote: |
|
||||||
|
// ... '10.10'
|
||||||
|
// ... literal double quote: |
|
||||||
|
// ... "10.10"
|
||||||
|
// ... folded: >
|
||||||
|
// ... 10.10
|
||||||
|
// ... folded single quote: >
|
||||||
|
// ... '10.10'
|
||||||
|
// ... folded double quote: >
|
||||||
|
// ... "10.10"
|
||||||
|
// ... """)
|
||||||
|
// {'plain': 10.1, 'single quote': '10.10', 'double quote': '10.10', 'literal': '10.10\n', 'literal single quote': "'10.10'\n", 'literal double quote': '"10.10"\n', 'folded': '10.10\n', 'folded single quote': "'10.10'\n", 'folded double quote': '"10.10"\n'}
|
||||||
|
// >>>
|
||||||
|
// ```
|
||||||
|
// swiftlint:enable line_length
|
||||||
|
let example = """
|
||||||
|
plain: 10.10
|
||||||
|
single quote: '10.10'
|
||||||
|
double quote: "10.10"
|
||||||
|
literal: |
|
||||||
|
10.10
|
||||||
|
literal single quote: |
|
||||||
|
'10.10'
|
||||||
|
literal double quote: |
|
||||||
|
"10.10"
|
||||||
|
folded: >
|
||||||
|
10.10
|
||||||
|
folded single quote: >
|
||||||
|
'10.10'
|
||||||
|
folded double quote: >
|
||||||
|
"10.10"
|
||||||
|
|
||||||
|
"""
|
||||||
|
let objects = try Yams.load(yaml: example)
|
||||||
|
let expected: [String: Any] = [
|
||||||
|
"plain": 10.10,
|
||||||
|
"single quote": "10.10",
|
||||||
|
"double quote": "10.10",
|
||||||
|
"literal": "10.10\n",
|
||||||
|
"literal single quote": "'10.10'\n",
|
||||||
|
"literal double quote": "\"10.10\"\n",
|
||||||
|
"folded": "10.10\n",
|
||||||
|
"folded single quote": "'10.10'\n",
|
||||||
|
"folded double quote": "\"10.10\"\n"
|
||||||
|
]
|
||||||
|
YamsAssertEqual(objects, expected)
|
||||||
|
}
|
||||||
|
|
||||||
func testSet() throws {
|
func testSet() throws {
|
||||||
let example = """
|
let example = """
|
||||||
# Explicitly typed set.
|
# Explicitly typed set.
|
||||||
|
@ -429,6 +490,7 @@ extension ConstructorTests {
|
||||||
("testNull", testNull),
|
("testNull", testNull),
|
||||||
("testOmap", testOmap),
|
("testOmap", testOmap),
|
||||||
("testPairs", testPairs),
|
("testPairs", testPairs),
|
||||||
|
("testQuotationMark", testQuotationMark),
|
||||||
("testSet", testSet),
|
("testSet", testSet),
|
||||||
("testSeq", testSeq),
|
("testSeq", testSeq),
|
||||||
("testTimestamp", testTimestamp),
|
("testTimestamp", testTimestamp),
|
||||||
|
|
|
@ -65,7 +65,7 @@ class YamlErrorTests: XCTestCase {
|
||||||
|
|
||||||
let parser = try Parser(yaml: invalidYAML)
|
let parser = try Parser(yaml: invalidYAML)
|
||||||
// first iteration returns scalar
|
// first iteration returns scalar
|
||||||
XCTAssertEqual(try parser.nextRoot(), Node("", Tag(.null), .literal))
|
XCTAssertEqual(try parser.nextRoot(), Node("", Tag(.str), .literal))
|
||||||
// second iteration throws error
|
// second iteration throws error
|
||||||
XCTAssertThrowsError(try parser.nextRoot()) { error in
|
XCTAssertThrowsError(try parser.nextRoot()) { error in
|
||||||
XCTAssertTrue(error is YamlError)
|
XCTAssertTrue(error is YamlError)
|
||||||
|
|
Loading…
Reference in New Issue