Skip to content

Commit 42c9115

Browse files
committed
test(rs): init all grammar tests
1 parent 8c980fa commit 42c9115

18 files changed

Lines changed: 5882 additions & 0 deletions

chapi-ast-rust/src/test/kotlin/chapi/ast/rustast/RustAnalyserTest.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package chapi.ast.rustast
22

33
import org.junit.jupiter.api.Test
4+
import java.io.File
45

56
internal class RustAnalyserTest {
67

@@ -14,4 +15,14 @@ internal class RustAnalyserTest {
1415

1516
val codeContainer = RustAnalyser().analysis(str, "test.rs")
1617
}
18+
19+
@Test
20+
fun allGrammarUnderResources() {
21+
val content = this::class.java.getResource("/grammar")!!
22+
File(content.toURI()).walkTopDown().forEach {
23+
if (it.isFile && it.extension == "rs") {
24+
RustAnalyser().analysis(it.readText(), it.name)
25+
}
26+
}
27+
}
1728
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//! A doc comment that applies to the implicit anonymous module of this crate
2+
3+
pub mod outer_module {
4+
5+
//! - Inner line doc
6+
//!! - Still an inner line doc (but with a bang at the beginning)
7+
8+
/*! - Inner block doc */
9+
/*!! - Still an inner block doc (but with a bang at the beginning) */
10+
11+
// - Only a comment
12+
/// - Outer line doc (exactly 3 slashes)
13+
//// - Only a comment
14+
15+
/* - Only a comment */
16+
/** - Outer block doc (exactly) 2 asterisks */
17+
/*** - Only a comment */
18+
19+
pub mod inner_module {}
20+
21+
pub mod nested_comments {
22+
/* In Rust /* we can /* nest comments */ */ */
23+
24+
// All three types of block comments can contain or be nested inside
25+
// any other type:
26+
27+
/* /* */ /** */ /*! */ */
28+
/*! /* */ /** */ /*! */ */
29+
/** /* */ /** */ /*! */ */
30+
pub mod dummy_item {}
31+
}
32+
33+
pub mod degenerate_cases {
34+
// empty inner line doc
35+
//!
36+
37+
// empty inner block doc
38+
/*!*/
39+
40+
// empty line comment
41+
//
42+
43+
// empty outer line doc
44+
///
45+
46+
// empty block comment
47+
/**/
48+
49+
pub mod dummy_item {}
50+
51+
// empty 2-asterisk block isn't a doc block, it is a block comment
52+
/***/
53+
54+
}
55+
56+
/* The next one isn't allowed because outer doc comments
57+
require an item that will receive the doc */
58+
59+
/// Where is my item?
60+
}

0 commit comments

Comments
 (0)