@@ -94,4 +94,133 @@ class ImportParserSpec extends AnyWordSpec with Matchers {
94
94
}
95
95
}
96
96
97
+ " stop" when {
98
+ " the head path is the `import` keyword" in {
99
+ val root =
100
+ parseSoft(" import \" import" )
101
+
102
+ // both `import` statements are parsed as individual `import` ASTs
103
+ root.parts should have size 2
104
+
105
+ root shouldBe
106
+ SoftAST .RootBlock (
107
+ index = indexOf(" >>import \" import<<" ),
108
+ parts = Seq (
109
+ SoftAST .Import (
110
+ index = indexOf(" >>import \" <<import" ),
111
+ importToken = Import (" >>import<< \" import" ),
112
+ postImportSpace = Some (Space (" import>> <<\" import" )),
113
+ string = Some (
114
+ SoftAST .StringLiteral (
115
+ index = indexOf(" import >>\" <<import" ),
116
+ startQuote = Quote (" import >>\" <<import" ),
117
+ head = None ,
118
+ tail = Seq .empty,
119
+ endQuote = TokenExpected (" import \" >><<import" , Token .Quote )
120
+ )
121
+ )
122
+ ),
123
+ SoftAST .Import (
124
+ index = indexOf(" import \" >>import<<" ),
125
+ importToken = Import (" import \" >>import<<" ),
126
+ postImportSpace = None ,
127
+ string = None
128
+ )
129
+ )
130
+ )
131
+ }
132
+
133
+ " the second path is the `import` keyword" when {
134
+ " without closing quote" in {
135
+ val root =
136
+ parseSoft(" import \" nft/import" )
137
+
138
+ // both `import` statements are parsed as individual `import` ASTs
139
+ root.parts should have size 2
140
+
141
+ root shouldBe
142
+ SoftAST .RootBlock (
143
+ index = indexOf(" >>import \" nft/import<<" ),
144
+ parts = Seq (
145
+ SoftAST .Import (
146
+ index = indexOf(" >>import \" nft/<<import" ),
147
+ importToken = Import (" >>import<< \" nft/import" ),
148
+ postImportSpace = Some (Space (" import>> <<\" nft/import" )),
149
+ string = Some (
150
+ SoftAST .StringLiteral (
151
+ index = indexOf(" import >>\" nft/<<import" ),
152
+ startQuote = Quote (" import >>\" <<nft/import" ),
153
+ head = Some (CodeString (" import \" >>nft<</import" )),
154
+ tail = Seq (
155
+ SoftAST .Path (
156
+ index = indexOf(" import \" nft>>/<<import" ),
157
+ slash = ForwardSlash (" import \" nft>>/<<import" ),
158
+ text = CodeStringExpected (" import \" nft/>><<import" )
159
+ )
160
+ ),
161
+ endQuote = TokenExpected (" import \" nft/>><<import" , Token .Quote )
162
+ )
163
+ )
164
+ ),
165
+ SoftAST .Import (
166
+ index = indexOf(" import \" nft/>>import<<" ),
167
+ importToken = Import (" import \" nft/>>import<<" ),
168
+ postImportSpace = None ,
169
+ string = None
170
+ )
171
+ )
172
+ )
173
+ }
174
+
175
+ " with closing quote" in {
176
+ val root =
177
+ parseSoft(" import \" nft/import\" " )
178
+
179
+ // both `import` statements are parsed as individual `import` ASTs
180
+ root.parts should have size 2
181
+
182
+ root shouldBe
183
+ SoftAST .RootBlock (
184
+ index = indexOf(" >>import \" nft/import\" <<" ),
185
+ parts = Seq (
186
+ SoftAST .Import (
187
+ index = indexOf(" >>import \" nft/<<import\" " ),
188
+ importToken = Import (" >>import<< \" nft/import\" " ),
189
+ postImportSpace = Some (Space (" import>> <<\" nft/import\" " )),
190
+ string = Some (
191
+ SoftAST .StringLiteral (
192
+ index = indexOf(" import >>\" nft/<<import\" " ),
193
+ startQuote = Quote (" import >>\" <<nft/import\" " ),
194
+ head = Some (CodeString (" import \" >>nft<</import\" " )),
195
+ tail = Seq (
196
+ SoftAST .Path (
197
+ index = indexOf(" import \" nft>>/<<import\" " ),
198
+ slash = ForwardSlash (" import \" nft>>/<<import\" " ),
199
+ text = CodeStringExpected (" import \" nft/>><<import\" " )
200
+ )
201
+ ),
202
+ endQuote = TokenExpected (" import \" nft/>><<import\" " , Token .Quote )
203
+ )
204
+ )
205
+ ),
206
+ SoftAST .Import (
207
+ index = indexOf(" import \" nft/>>import\" <<" ),
208
+ importToken = Import (" import \" nft/>>import<<\" " ),
209
+ postImportSpace = None ,
210
+ string = Some (
211
+ SoftAST .StringLiteral (
212
+ index = indexOf(" import \" nft/import>>\" <<" ),
213
+ startQuote = Quote (" import \" nft/import>>\" <<" ),
214
+ head = None ,
215
+ tail = Seq .empty,
216
+ endQuote = TokenExpected (" import \" nft/import\" >><<" , Token .Quote )
217
+ )
218
+ )
219
+ )
220
+ )
221
+ )
222
+ }
223
+ }
224
+ }
225
+
97
226
}
0 commit comments