Skip to content

Commit 01c4737

Browse files
committed
enabling more tests and fixes
1 parent eaaf8a6 commit 01c4737

6 files changed

Lines changed: 87 additions & 80 deletions

File tree

crates/vim9-parser/src/lib.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ impl VarCommand {
12621262
let mut trim = false;
12631263
let mut eval = false;
12641264

1265-
let open: TokenMeta = {
1265+
let open: TokenOwned = {
12661266
let mut token: TokenOwned =
12671267
parser.expect_token(TokenKind::Identifier)?.into();
12681268

@@ -1284,10 +1284,7 @@ impl VarCommand {
12841284
}
12851285
}
12861286

1287-
TokenMeta {
1288-
kind: token.kind,
1289-
span: token.span,
1290-
}
1287+
token
12911288
};
12921289

12931290
parser.expect_eol()?;
@@ -1308,9 +1305,7 @@ impl VarCommand {
13081305
}
13091306

13101307
parser.next_token();
1311-
if line.len() == 1
1312-
/* && line[0].text.eq(open.text) */
1313-
{
1308+
if line.len() == 1 && line[0].text == open.text {
13141309
break line[0].clone();
13151310
}
13161311

@@ -1327,8 +1322,7 @@ impl VarCommand {
13271322
}
13281323

13291324
contents.push(line_contents);
1330-
}
1331-
.into();
1325+
};
13321326

13331327
Ok(ExCommand::Heredoc(Heredoc {
13341328
var,
@@ -1337,9 +1331,9 @@ impl VarCommand {
13371331
op,
13381332
trim,
13391333
eval,
1340-
open,
1334+
open: open.into(),
13411335
contents,
1342-
close,
1336+
close: close.into(),
13431337
}))
13441338
}
13451339
TokenKind::Equal => Ok(ExCommand::Var(VarCommand {
@@ -2539,18 +2533,16 @@ mod test {
25392533
snap!(test_echo, "../testdata/snapshots/echo.vim");
25402534
snap!(test_execute, "../testdata/snapshots/execute.vim");
25412535
snap!(test_scopes, "../testdata/snapshots/scopes.vim");
2542-
// snap!(test_autocmd, "../testdata/snapshots/autocmd.vim");
25432536
snap!(test_array, "../testdata/snapshots/array.vim");
25442537
snap!(test_dict, "../testdata/snapshots/dict.vim");
25452538
snap!(test_if, "../testdata/snapshots/if.vim");
25462539
snap!(test_call, "../testdata/snapshots/call.vim");
25472540
snap!(test_concat, "../testdata/snapshots/concat.vim");
2548-
snap!(test_unpack, "../testdata/snapshots/unpack.vim");
2549-
// snap!(test_assign, "../testdata/snapshots/assign.vim");
2550-
// snap!(test_vimvar, "../testdata/snapshots/vimvar.vim");
2551-
// snap!(test_busted, "../testdata/snapshots/busted.vim");
2552-
// snap!(test_heredoc, "../testdata/snapshots/heredoc.vim");
2553-
// snap!(test_typed_params, "../testdata/snapshots/typed_params.vim");
2541+
snap!(test_assign, "../testdata/snapshots/assign.vim");
2542+
snap!(test_vimvar, "../testdata/snapshots/vimvar.vim");
2543+
snap!(test_busted, "../testdata/snapshots/busted.vim");
2544+
snap!(test_heredoc, "../testdata/snapshots/heredoc.vim");
2545+
snap!(test_typed_params, "../testdata/snapshots/typed_params.vim");
25542546
// snap!(test_index, "../testdata/snapshots/index.vim");
25552547
// snap!(test_adv_index, "../testdata/snapshots/adv_index.vim");
25562548
// snap!(test_multiline, "../testdata/snapshots/multiline.vim");
@@ -2561,6 +2553,8 @@ mod test {
25612553
// snap!(test_eval, "../testdata/snapshots/eval.vim");
25622554
// snap!(test_export, "../testdata/snapshots/export.vim");
25632555
// snap!(test_import, "../testdata/snapshots/import.vim");
2556+
// snap!(test_autocmd, "../testdata/snapshots/autocmd.vim");
2557+
// snap!(test_unpack, "../testdata/snapshots/unpack.vim");
25642558

25652559
// https://github.com/yegappan/lsp test suite
25662560
// snap!(test_handlers, "../../shared/snapshots/lsp_handlers.vim");

crates/vim9-parser/testdata/output/vim9_parser__test__assign.snap

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
---
2-
source: crates/vim9-parser/src/test.rs
3-
assertion_line: 36
2+
source: crates/vim9-parser/src/lib.rs
3+
assertion_line: 2549
44
expression: snapshot_parsing(contents)
55
---
66
[
77
Vim9Script(
88
Vim9ScriptCommand {
99
noclear: false,
10-
eol: Token(EndOfLine, "\n", (0,10)->(0,10)),
10+
eol: Token(EndOfLine, (0,10)->(0,10)),
1111
},
1212
),
13+
NoOp(
14+
Token(EndOfLine, "\n", (1,0)->(1,0)),
15+
),
1316
Var(
1417
VarCommand {
15-
var: Token(Identifier, "var", (2,0)->(2,3)),
18+
var: Token(Identifier, (2,0)->(2,3)),
1619
ty: None,
1720
name: Raw(i),
18-
equal: Token(Equal, "=", (2,6)->(2,7)),
21+
equal: Token(Equal, (2,6)->(2,7)),
1922
expr: Call(
2023
f: Identifier(Raw(index)) arg: [
2124
Identifier(
@@ -26,7 +29,7 @@ expression: snapshot_parsing(contents)
2629
),
2730
],
2831
),
29-
eol: Token(EndOfLine, "\n", (2,23)->(2,23)),
32+
eol: Token(EndOfLine, (2,23)->(2,23)),
3033
},
3134
),
3235
Statement(
@@ -35,7 +38,7 @@ expression: snapshot_parsing(contents)
3538
left: Identifier(
3639
Raw(i),
3740
),
38-
equals: Token(Equal, "=", (3,2)->(3,3)),
41+
equals: Token(Equal, (3,2)->(3,3)),
3942
right: Call(
4043
f: Identifier(Raw(index)) arg: [
4144
Identifier(
@@ -46,7 +49,7 @@ expression: snapshot_parsing(contents)
4649
),
4750
],
4851
),
49-
eol: Token(EndOfLine, "\n", (3,19)->(3,19)),
52+
eol: Token(EndOfLine, (3,19)->(3,19)),
5053
},
5154
),
5255
),
Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
11
---
2-
source: crates/vim9-parser/src/test.rs
3-
assertion_line: 38
2+
source: crates/vim9-parser/src/lib.rs
3+
assertion_line: 2549
44
expression: snapshot_parsing(contents)
55
---
66
[
77
Vim9Script(
88
Vim9ScriptCommand {
99
noclear: false,
10-
eol: Token(EndOfLine, "\n", (0,10)->(0,10)),
10+
eol: Token(EndOfLine, (0,10)->(0,10)),
1111
},
1212
),
13+
NoOp(
14+
Token(EndOfLine, "\n", (1,0)->(1,0)),
15+
),
1316
Def(
1417
DefCommand {
15-
def: Token(Identifier, "def", (2,0)->(2,3)),
18+
def: Token(Identifier, (2,0)->(2,3)),
1619
name: Raw(Test_assignment_one),
1720
args: Signature {
18-
open: Token(LeftParen, "(", (2,23)->(2,24)),
21+
open: Token(LeftParen, (2,23)->(2,24)),
1922
params: [],
20-
close: Token(RightParen, ")", (2,24)->(2,25)),
23+
close: Token(RightParen, (2,24)->(2,25)),
2124
},
2225
ret: None,
23-
def_eol: Token(EndOfLine, "\n", (2,25)->(2,25)),
26+
def_eol: Token(EndOfLine, (2,25)->(2,25)),
2427
body: Body {
2528
commands: [
2629
Var(
2730
VarCommand {
28-
var: Token(Identifier, "var", (3,2)->(3,5)),
31+
var: Token(Identifier, (3,2)->(3,5)),
2932
ty: Some(
3033
Type {
31-
colon: Token(SpacedColon, ": ", (3,11)->(3,13)),
34+
colon: Token(SpacedColon, (3,11)->(3,13)),
3235
inner: Bool,
3336
},
3437
),
3538
name: Raw(bool1),
36-
equal: Token(Equal, "=", (3,18)->(3,19)),
39+
equal: Token(Equal, (3,18)->(3,19)),
3740
expr: Boolean(
3841
VimBoolean {
39-
token: Token(True, "true", (3,20)->(3,24)),
4042
value: true,
4143
},
4244
),
43-
eol: Token(EndOfLine, "\n", (3,24)->(3,24)),
45+
eol: Token(EndOfLine, (3,24)->(3,24)),
4446
},
4547
),
4648
Call(
@@ -49,23 +51,23 @@ expression: snapshot_parsing(contents)
4951
expr: Identifier(
5052
Raw(assert_equal),
5153
),
52-
open: Token(LeftParen, "(", (4,14)->(4,15)),
54+
open: Token(LeftParen, (4,14)->(4,15)),
5355
args: [
5456
Identifier(
55-
Scope(ScopedIdentifier { scope: VimVar, colon: Token(Colon, ":", (4,16)->(4,17)), accessor: Raw(true) }),
57+
Scope(ScopedIdentifier { scope: VimVar, colon: Token(Colon, (4,16)->(4,17)), accessor: Raw(true) }),
5658
),
5759
Identifier(
5860
Raw(bool1),
5961
),
6062
],
61-
close: Token(RightParen, ")", (4,28)->(4,29)),
62-
eol: Token(EndOfLine, "\n", (4,29)->(4,29)),
63+
close: Token(RightParen, (4,28)->(4,29)),
64+
eol: Token(EndOfLine, (4,29)->(4,29)),
6365
},
6466
),
6567
],
6668
},
67-
enddef: Token(Identifier, "enddef", (5,0)->(5,6)),
68-
end_eol: Token(EndOfLine, "\n", (5,6)->(5,6)),
69+
enddef: Token(Identifier, (5,0)->(5,6)),
70+
end_eol: Token(EndOfLine, (5,6)->(5,6)),
6971
},
7072
),
7173
]
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,52 @@
11
---
22
source: crates/vim9-parser/src/lib.rs
3-
assertion_line: 1919
3+
assertion_line: 2544
44
expression: snapshot_parsing(contents)
55
---
66
[
77
Vim9Script(
88
Vim9ScriptCommand {
99
noclear: false,
10-
eol: Token(EndOfLine, "\n", (0,10)->(0,10)),
10+
eol: Token(EndOfLine, (0,10)->(0,10)),
1111
},
1212
),
13+
NoOp(
14+
Token(EndOfLine, "\n", (1,0)->(1,0)),
15+
),
1316
Heredoc(
1417
Heredoc {
15-
var: Token(Identifier, "var", (2,0)->(2,3)),
18+
var: Token(Identifier, (2,0)->(2,3)),
1619
ty: None,
1720
name: Raw(x),
18-
op: Token(HeredocOperator, "=<<", (2,6)->(2,9)),
21+
op: Token(HeredocOperator, (2,6)->(2,9)),
1922
trim: false,
2023
eval: false,
21-
open: Token(Identifier, "END", (2,10)->(2,13)),
24+
open: Token(Identifier, (2,10)->(2,13)),
2225
contents: [
2326
" hello this",
2427
" world that",
2528
" this other",
2629
],
27-
close: Token(Identifier, "END", (6,0)->(6,3)),
30+
close: Token(Identifier, (6,0)->(6,3)),
2831
},
2932
),
3033
NoOp(
3134
Token(EndOfLine, "\n", (7,0)->(7,0)),
3235
),
3336
Heredoc(
3437
Heredoc {
35-
var: Token(Identifier, "var", (8,0)->(8,3)),
38+
var: Token(Identifier, (8,0)->(8,3)),
3639
ty: None,
3740
name: Raw(y),
38-
op: Token(HeredocOperator, "=<<", (8,6)->(8,9)),
41+
op: Token(HeredocOperator, (8,6)->(8,9)),
3942
trim: true,
4043
eval: false,
41-
open: Token(Identifier, "END", (8,15)->(8,18)),
44+
open: Token(Identifier, (8,15)->(8,18)),
4245
contents: [
4346
" hello",
4447
" world",
4548
],
46-
close: Token(Identifier, "END", (11,0)->(11,3)),
49+
close: Token(Identifier, (11,0)->(11,3)),
4750
},
4851
),
4952
]
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
---
22
source: crates/vim9-parser/src/lib.rs
3-
assertion_line: 1954
3+
assertion_line: 2545
44
expression: snapshot_parsing(contents)
55
---
66
[
77
Vim9Script(
88
Vim9ScriptCommand {
99
noclear: false,
10-
eol: Token(EndOfLine, "\n", (0,10)->(0,10)),
10+
eol: Token(EndOfLine, (0,10)->(0,10)),
1111
},
1212
),
13+
NoOp(
14+
Token(EndOfLine, "\n", (1,0)->(1,0)),
15+
),
1316
Def(
1417
DefCommand {
15-
def: Token(Identifier, "def", (2,0)->(2,3)),
18+
def: Token(Identifier, (2,0)->(2,3)),
1619
name: Raw(ParamTest),
1720
args: Signature {
18-
open: Token(LeftParen, "(", (2,13)->(2,14)),
21+
open: Token(LeftParen, (2,13)->(2,14)),
1922
params: [
2023
Parameter {
2124
name: Raw(qf),
2225
ty: Some(
2326
Type {
24-
colon: Token(SpacedColon, ": ", (2,16)->(2,18)),
27+
colon: Token(SpacedColon, (2,16)->(2,18)),
2528
inner: Bool,
2629
},
2730
),
@@ -32,7 +35,7 @@ expression: snapshot_parsing(contents)
3235
name: Raw(searchpat),
3336
ty: None,
3437
equal: Some(
35-
Token(Equal, "=", (2,34)->(2,35)),
38+
Token(Equal, (2,34)->(2,35)),
3639
),
3740
default_val: Some(
3841
String(
@@ -46,12 +49,12 @@ expression: snapshot_parsing(contents)
4649
name: Raw(bang),
4750
ty: Some(
4851
Type {
49-
colon: Token(SpacedColon, ": ", (2,49)->(2,51)),
52+
colon: Token(SpacedColon, (2,49)->(2,51)),
5053
inner: String,
5154
},
5255
),
5356
equal: Some(
54-
Token(Equal, "=", (2,58)->(2,59)),
57+
Token(Equal, (2,58)->(2,59)),
5558
),
5659
default_val: Some(
5760
String(
@@ -62,15 +65,15 @@ expression: snapshot_parsing(contents)
6265
),
6366
},
6467
],
65-
close: Token(RightParen, ")", (2,67)->(2,68)),
68+
close: Token(RightParen, (2,67)->(2,68)),
6669
},
6770
ret: None,
68-
def_eol: Token(EndOfLine, "\n", (2,68)->(2,68)),
71+
def_eol: Token(EndOfLine, (2,68)->(2,68)),
6972
body: Body {
7073
commands: [],
7174
},
72-
enddef: Token(Identifier, "enddef", (3,0)->(3,6)),
73-
end_eol: Token(EndOfLine, "\n", (3,6)->(3,6)),
75+
enddef: Token(Identifier, (3,0)->(3,6)),
76+
end_eol: Token(EndOfLine, (3,6)->(3,6)),
7477
},
7578
),
7679
]

0 commit comments

Comments
 (0)