1
1
/*
2
- * Copyright (C) 2023-2024 DiffPlug
2
+ * Copyright (C) 2023-2025 DiffPlug
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -46,42 +46,42 @@ class SnapshotValueReaderTest {
46
46
╔═ 05_notSureHowKotlinMultilineWorks ═╗
47
47
"""
48
48
.trimIndent())
49
- reader.peekKey () shouldBe " 00_empty"
50
- reader.peekKey () shouldBe " 00_empty"
49
+ reader.peekKeyRaw () shouldBe " 00_empty"
50
+ reader.peekKeyRaw () shouldBe " 00_empty"
51
51
reader.nextValue().valueString() shouldBe " "
52
- reader.peekKey () shouldBe " 01_singleLineString"
53
- reader.peekKey () shouldBe " 01_singleLineString"
52
+ reader.peekKeyRaw () shouldBe " 01_singleLineString"
53
+ reader.peekKeyRaw () shouldBe " 01_singleLineString"
54
54
reader.nextValue().valueString() shouldBe " this is one line"
55
- reader.peekKey () shouldBe " 01a_singleLineLeadingSpace"
55
+ reader.peekKeyRaw () shouldBe " 01a_singleLineLeadingSpace"
56
56
reader.nextValue().valueString() shouldBe " the leading space is significant"
57
- reader.peekKey () shouldBe " 01b_singleLineTrailingSpace"
57
+ reader.peekKeyRaw () shouldBe " 01b_singleLineTrailingSpace"
58
58
reader.nextValue().valueString() shouldBe " the trailing space is significant "
59
- reader.peekKey () shouldBe " 02_multiLineStringTrimmed"
59
+ reader.peekKeyRaw () shouldBe " 02_multiLineStringTrimmed"
60
60
reader.nextValue().valueString() shouldBe " Line 1\n Line 2"
61
61
// note that leading and trailing newlines in the snapshots are significant
62
62
// this is critical so that snapshots can accurately capture the exact number of newlines
63
- reader.peekKey () shouldBe " 03_multiLineStringTrailingNewline"
63
+ reader.peekKeyRaw () shouldBe " 03_multiLineStringTrailingNewline"
64
64
reader.nextValue().valueString() shouldBe " Line 1\n Line 2\n "
65
- reader.peekKey () shouldBe " 04_multiLineStringLeadingNewline"
65
+ reader.peekKeyRaw () shouldBe " 04_multiLineStringLeadingNewline"
66
66
reader.nextValue().valueString() shouldBe " \n Line 1\n Line 2"
67
- reader.peekKey () shouldBe " 05_notSureHowKotlinMultilineWorks"
67
+ reader.peekKeyRaw () shouldBe " 05_notSureHowKotlinMultilineWorks"
68
68
reader.nextValue().valueString() shouldBe " "
69
69
}
70
70
71
71
@Test
72
72
fun invalidNames () {
73
- shouldThrow<ParseException > { SnapshotValueReader .of(" ╔═name ═╗" ).peekKey () }
73
+ shouldThrow<ParseException > { SnapshotValueReader .of(" ╔═name ═╗" ).peekKeyRaw () }
74
74
.let { it.message shouldBe " L1:Expected to start with '╔═ '" }
75
- shouldThrow<ParseException > { SnapshotValueReader .of(" ╔═ name═╗" ).peekKey () }
75
+ shouldThrow<ParseException > { SnapshotValueReader .of(" ╔═ name═╗" ).peekKeyRaw () }
76
76
.let { it.message shouldBe " L1:Expected to contain ' ═╗'" }
77
- shouldThrow<ParseException > { SnapshotValueReader .of(" ╔═ name ═╗" ).peekKey () }
77
+ shouldThrow<ParseException > { SnapshotValueReader .of(" ╔═ name ═╗" ).peekKeyRaw () }
78
78
.let { it.message shouldBe " L1:Leading spaces are disallowed: ' name'" }
79
- shouldThrow<ParseException > { SnapshotValueReader .of(" ╔═ name ═╗" ).peekKey () }
79
+ shouldThrow<ParseException > { SnapshotValueReader .of(" ╔═ name ═╗" ).peekKeyRaw () }
80
80
.let { it.message shouldBe " L1:Trailing spaces are disallowed: 'name '" }
81
- SnapshotValueReader .of(" ╔═ name ═╗ comment okay" ).peekKey () shouldBe " name"
82
- SnapshotValueReader .of(" ╔═ name ═╗okay here too" ).peekKey () shouldBe " name"
81
+ SnapshotValueReader .of(" ╔═ name ═╗ comment okay" ).peekKeyRaw () shouldBe " name"
82
+ SnapshotValueReader .of(" ╔═ name ═╗okay here too" ).peekKeyRaw () shouldBe " name"
83
83
SnapshotValueReader .of(" ╔═ name ═╗ okay ╔═ ═╗ (it's the first ' ═╗' that counts)" )
84
- .peekKey () shouldBe " name"
84
+ .peekKeyRaw () shouldBe " name"
85
85
}
86
86
87
87
@Test
@@ -96,21 +96,15 @@ class SnapshotValueReaderTest {
96
96
╔═ test with \┌\─ ascii art \─\┐ in name ═╗
97
97
"""
98
98
.trimIndent())
99
- reader.peekKey () shouldBe " test with [ square brackets] in name"
99
+ reader.peekKeyRaw () shouldBe " test with \\ ( square brackets\\ ) in name"
100
100
reader.nextValue().valueString() shouldBe " "
101
- reader.peekKey () shouldBe """ test with \backslash\ in name"""
101
+ reader.peekKeyRaw () shouldBe """ test with \\ backslash\ \ in name"""
102
102
reader.nextValue().valueString() shouldBe " "
103
- reader.peekKey() shouldBe
104
- """
105
- test with
106
- newline
107
- in name
108
- """
109
- .trimIndent()
103
+ reader.peekKeyRaw() shouldBe " test with\\ nnewline\\ nin name"
110
104
reader.nextValue().valueString() shouldBe " "
111
- reader.peekKey () shouldBe " test with \t tab\t in name"
105
+ reader.peekKeyRaw () shouldBe " test with \\ ttab\ \ t in name"
112
106
reader.nextValue().valueString() shouldBe " "
113
- reader.peekKey () shouldBe " test with ╔═ ascii art ═╗ in name"
107
+ reader.peekKeyRaw () shouldBe " test with \\ ┌ \\ ─ ascii art \\ ─ \\ ┐ in name"
114
108
reader.nextValue().valueString() shouldBe " "
115
109
}
116
110
@@ -127,11 +121,11 @@ class SnapshotValueReaderTest {
127
121
𐝃𐝁𐝃𐝃 linear a is dead
128
122
"""
129
123
.trimIndent())
130
- reader.peekKey () shouldBe " ascii art okay"
124
+ reader.peekKeyRaw () shouldBe " ascii art okay"
131
125
reader.nextValue().valueString() shouldBe """ ╔══╗"""
132
- reader.peekKey () shouldBe " escaped iff on first line"
126
+ reader.peekKeyRaw () shouldBe " escaped iff on first line"
133
127
reader.nextValue().valueString() shouldBe """ ╔══╗"""
134
- reader.peekKey () shouldBe " body escape characters"
128
+ reader.peekKeyRaw () shouldBe " body escape characters"
135
129
reader.nextValue().valueString() shouldBe """ 𐝁𐝃 linear a is dead"""
136
130
}
137
131
@@ -154,12 +148,12 @@ class SnapshotValueReaderTest {
154
148
}
155
149
private fun assertKeyValueWithSkip (input : String , key : String , value : String ) {
156
150
val reader = SnapshotValueReader .of(input)
157
- while (reader.peekKey () != key) {
151
+ while (reader.peekKeyRaw () != key) {
158
152
reader.skipValue()
159
153
}
160
- reader.peekKey () shouldBe key
154
+ reader.peekKeyRaw () shouldBe key
161
155
reader.nextValue().valueString() shouldBe value
162
- while (reader.peekKey () != null ) {
156
+ while (reader.peekKeyRaw () != null ) {
163
157
reader.skipValue()
164
158
}
165
159
}
@@ -169,7 +163,7 @@ class SnapshotValueReaderTest {
169
163
val reader = SnapshotValueReader .of(""" ╔═ Apple ═╗ base64 length 3 bytes
170
164
c2Fk
171
165
""" )
172
- reader.peekKey () shouldBe " Apple"
166
+ reader.peekKeyRaw () shouldBe " Apple"
173
167
reader.nextValue().valueBinary() shouldBe " sad" .encodeToByteArray()
174
168
}
175
169
}
0 commit comments