Skip to content

Commit 29cb0a4

Browse files
committed
test: add test for definition
1 parent c39a56d commit 29cb0a4

10 files changed

+84
-10
lines changed

src/workspace/definition.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,29 @@ impl ProtoLanguageState {
1919

2020
#[cfg(test)]
2121
mod test {
22+
use insta::assert_yaml_snapshot;
23+
24+
use crate::state::ProtoLanguageState;
25+
2226
#[test]
23-
fn workspace_test_definition() {}
27+
fn workspace_test_definition() {
28+
let a_uri = "file://input/a.proto".parse().unwrap();
29+
let b_uri = "file://input/b.proto".parse().unwrap();
30+
let c_uri = "file://input/c.proto".parse().unwrap();
31+
32+
let a = include_str!("input/a.proto");
33+
let b = include_str!("input/b.proto");
34+
let c = include_str!("input/c.proto");
35+
36+
let mut state = ProtoLanguageState::new();
37+
state.upsert_file(&a_uri, a.to_owned());
38+
state.upsert_file(&b_uri, b.to_owned());
39+
state.upsert_file(&c_uri, c.to_owned());
40+
41+
assert_yaml_snapshot!(state.definition("com.library", "Author"));
42+
assert_yaml_snapshot!(state.definition("com.library", "Author.Address"));
43+
assert_yaml_snapshot!(state.definition("com.library", "com.utility.Foobar.Baz"));
44+
assert_yaml_snapshot!(state.definition("com.utility", "Baz"));
45+
46+
}
2447
}

src/workspace/hover.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ mod test {
2626

2727
#[test]
2828
fn workspace_test_hover() {
29-
let a_uri = "file://input/workspace_test_hover/a.proto".parse().unwrap();
30-
let b_uri = "file://input/workspace_test_hover/b.proto".parse().unwrap();
31-
let c_uri = "file://input/workspace_test_hover/c.proto".parse().unwrap();
29+
let a_uri = "file://input/a.proto".parse().unwrap();
30+
let b_uri = "file://input/b.proto".parse().unwrap();
31+
let c_uri = "file://input/c.proto".parse().unwrap();
3232

33-
let a = include_str!("input/workspace_test_hover/a.proto");
34-
let b = include_str!("input/workspace_test_hover/b.proto");
35-
let c = include_str!("input/workspace_test_hover/c.proto");
33+
let a = include_str!("input/a.proto");
34+
let b = include_str!("input/b.proto");
35+
let c = include_str!("input/c.proto");
3636

3737
let mut state = ProtoLanguageState::new();
3838
state.upsert_file(&a_uri, a.to_owned());
@@ -42,6 +42,6 @@ mod test {
4242
assert_yaml_snapshot!(state.hover("com.library", "Author"));
4343
assert_yaml_snapshot!(state.hover("com.library", "Author.Address"));
4444
assert_yaml_snapshot!(state.hover("com.library", "com.utility.Foobar.Baz"));
45-
assert_yaml_snapshot!(state.hover("com.utility", "com.library.Baz"));
45+
assert_yaml_snapshot!(state.hover("com.utility", "Baz"));
4646
}
4747
}

src/workspace/input/workspace_test_hover/a.proto renamed to src/workspace/input/a.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ message Book {
1010
Author.Address foo = 2;
1111
com.utility.FooBar.Baz z = 3;
1212
}
13+

src/workspace/input/workspace_test_hover/b.proto renamed to src/workspace/input/b.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ message Author {
1313

1414
Address foo = 2;
1515
}
16+

src/workspace/input/workspace_test_hover/c.proto renamed to src/workspace/input/c.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ message Foobar {
1313
Baz a = 2;
1414
}
1515

16+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: src/workspace/definition.rs
3+
expression: "state.definition(\"com.library\", \"Author.Address\")"
4+
---
5+
- uri: "file://input/b.proto"
6+
range:
7+
start:
8+
line: 9
9+
character: 11
10+
end:
11+
line: 9
12+
character: 18
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: src/workspace/definition.rs
3+
expression: "state.definition(\"com.library\", \"com.utility.Foobar.Baz\")"
4+
---
5+
- uri: "file://input/c.proto"
6+
range:
7+
start:
8+
line: 8
9+
character: 11
10+
end:
11+
line: 8
12+
character: 14
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: src/workspace/definition.rs
3+
expression: "state.definition(\"com.utility\", \"Baz\")"
4+
---
5+
- uri: "file://input/c.proto"
6+
range:
7+
start:
8+
line: 8
9+
character: 11
10+
end:
11+
line: 8
12+
character: 14
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: src/workspace/definition.rs
3+
expression: "state.definition(\"com.library\", \"Author\")"
4+
---
5+
- uri: "file://input/b.proto"
6+
range:
7+
start:
8+
line: 5
9+
character: 8
10+
end:
11+
line: 5
12+
character: 14
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
source: src/workspace/hover.rs
3-
expression: "state.hover(\"com.utility\", \"com.library.Baz\")"
3+
expression: "state.hover(\"com.utility\", \"Baz\")"
44
---
5-
[]
5+
- What is baz?

0 commit comments

Comments
 (0)