mirror of
https://github.com/RGBCube/cstree
synced 2025-07-27 09:07:44 +00:00
Add derive macro for Syntax
(used to be Language
) (#51)
This commit is contained in:
parent
2aa543036f
commit
c5279bae7d
70 changed files with 1459 additions and 899 deletions
16
test_suite/Cargo.toml
Normal file
16
test_suite/Cargo.toml
Normal file
|
@ -0,0 +1,16 @@
|
|||
[package]
|
||||
name = "cstree_test_suite"
|
||||
publish = false
|
||||
version = "0.0.0"
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
readme.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
cstree = { path = "../cstree", features = ["derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
trybuild = { version = "1.0.80", features = ["diff"] }
|
22
test_suite/tests/derive.rs
Normal file
22
test_suite/tests/derive.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use cstree::{RawSyntaxKind, Syntax};
|
||||
|
||||
#[test]
|
||||
fn basic() {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Syntax)]
|
||||
#[repr(u32)]
|
||||
pub enum SyntaxKind {
|
||||
A,
|
||||
#[static_text("b")]
|
||||
B,
|
||||
}
|
||||
pub type MySyntax = SyntaxKind;
|
||||
|
||||
assert_eq!(MySyntax::into_raw(SyntaxKind::A), RawSyntaxKind(0));
|
||||
assert_eq!(MySyntax::into_raw(SyntaxKind::B), RawSyntaxKind(1));
|
||||
|
||||
assert_eq!(MySyntax::from_raw(RawSyntaxKind(0)), SyntaxKind::A);
|
||||
assert_eq!(MySyntax::from_raw(RawSyntaxKind(1)), SyntaxKind::B);
|
||||
|
||||
assert!(MySyntax::static_text(SyntaxKind::A).is_none());
|
||||
assert_eq!(MySyntax::static_text(SyntaxKind::B), Some("b"));
|
||||
}
|
6
test_suite/tests/ui.rs
Normal file
6
test_suite/tests/ui.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
#[test]
|
||||
#[cfg_attr(miri, ignore)]
|
||||
fn ui() {
|
||||
let t = trybuild::TestCases::new();
|
||||
t.compile_fail("tests/ui/**/*.rs");
|
||||
}
|
10
test_suite/tests/ui/repr/missing_repr.rs
Normal file
10
test_suite/tests/ui/repr/missing_repr.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
use cstree::Syntax;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Syntax)]
|
||||
pub enum SyntaxKind {
|
||||
A,
|
||||
#[static_text("b")]
|
||||
B,
|
||||
}
|
||||
|
||||
fn main() {}
|
9
test_suite/tests/ui/repr/missing_repr.stderr
Normal file
9
test_suite/tests/ui/repr/missing_repr.stderr
Normal file
|
@ -0,0 +1,9 @@
|
|||
error: syntax kind definitions must be `#[repr(u32)]` to derive `Syntax`
|
||||
--> tests/ui/repr/missing_repr.rs:4:1
|
||||
|
|
||||
4 | / pub enum SyntaxKind {
|
||||
5 | | A,
|
||||
6 | | #[static_text("b")]
|
||||
7 | | B,
|
||||
8 | | }
|
||||
| |_^
|
11
test_suite/tests/ui/repr/wrong_repr_c.rs
Normal file
11
test_suite/tests/ui/repr/wrong_repr_c.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
use cstree::Syntax;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Syntax)]
|
||||
#[repr(C)]
|
||||
pub enum SyntaxKind {
|
||||
A,
|
||||
#[static_text("b")]
|
||||
B,
|
||||
}
|
||||
|
||||
fn main() {}
|
10
test_suite/tests/ui/repr/wrong_repr_c.stderr
Normal file
10
test_suite/tests/ui/repr/wrong_repr_c.stderr
Normal file
|
@ -0,0 +1,10 @@
|
|||
error: syntax kind definitions must be `#[repr(u32)]` to derive `Syntax`
|
||||
--> tests/ui/repr/wrong_repr_c.rs:4:1
|
||||
|
|
||||
4 | / #[repr(C)]
|
||||
5 | | pub enum SyntaxKind {
|
||||
6 | | A,
|
||||
7 | | #[static_text("b")]
|
||||
8 | | B,
|
||||
9 | | }
|
||||
| |_^
|
11
test_suite/tests/ui/repr/wrong_repr_u16.rs
Normal file
11
test_suite/tests/ui/repr/wrong_repr_u16.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
use cstree::Syntax;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Syntax)]
|
||||
#[repr(u16)]
|
||||
pub enum SyntaxKind {
|
||||
A,
|
||||
#[static_text("b")]
|
||||
B,
|
||||
}
|
||||
|
||||
fn main() {}
|
10
test_suite/tests/ui/repr/wrong_repr_u16.stderr
Normal file
10
test_suite/tests/ui/repr/wrong_repr_u16.stderr
Normal file
|
@ -0,0 +1,10 @@
|
|||
error: syntax kind definitions must be `#[repr(u32)]` to derive `Syntax`
|
||||
--> tests/ui/repr/wrong_repr_u16.rs:4:1
|
||||
|
|
||||
4 | / #[repr(u16)]
|
||||
5 | | pub enum SyntaxKind {
|
||||
6 | | A,
|
||||
7 | | #[static_text("b")]
|
||||
8 | | B,
|
||||
9 | | }
|
||||
| |_^
|
11
test_suite/tests/ui/static_text/empty_expr.rs
Normal file
11
test_suite/tests/ui/static_text/empty_expr.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
use cstree::Syntax;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Syntax)]
|
||||
#[repr(u32)]
|
||||
pub enum SyntaxKind {
|
||||
A,
|
||||
#[static_text()]
|
||||
B,
|
||||
}
|
||||
|
||||
fn main() {}
|
11
test_suite/tests/ui/static_text/empty_expr.stderr
Normal file
11
test_suite/tests/ui/static_text/empty_expr.stderr
Normal file
|
@ -0,0 +1,11 @@
|
|||
error: argument to `static_text` must be a string literal: `#[static_text("...")]`
|
||||
--> tests/ui/static_text/empty_expr.rs:7:7
|
||||
|
|
||||
7 | #[static_text()]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: unexpected end of input, expected string literal
|
||||
--> tests/ui/static_text/empty_expr.rs:7:19
|
||||
|
|
||||
7 | #[static_text()]
|
||||
| ^
|
11
test_suite/tests/ui/static_text/missing_text.rs
Normal file
11
test_suite/tests/ui/static_text/missing_text.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
use cstree::Syntax;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Syntax)]
|
||||
#[repr(u32)]
|
||||
pub enum SyntaxKind {
|
||||
A,
|
||||
#[static_text]
|
||||
B,
|
||||
}
|
||||
|
||||
fn main() {}
|
5
test_suite/tests/ui/static_text/missing_text.stderr
Normal file
5
test_suite/tests/ui/static_text/missing_text.stderr
Normal file
|
@ -0,0 +1,5 @@
|
|||
error: missing text for `static_text`: try `#[static_text("...")]`
|
||||
--> tests/ui/static_text/missing_text.rs:7:5
|
||||
|
|
||||
7 | #[static_text]
|
||||
| ^^^^^^^^^^^^^^
|
11
test_suite/tests/ui/static_text/non_expr.rs
Normal file
11
test_suite/tests/ui/static_text/non_expr.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
use cstree::Syntax;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Syntax)]
|
||||
#[repr(u32)]
|
||||
pub enum SyntaxKind {
|
||||
A,
|
||||
#[static_text(SyntaxKind)]
|
||||
B,
|
||||
}
|
||||
|
||||
fn main() {}
|
11
test_suite/tests/ui/static_text/non_expr.stderr
Normal file
11
test_suite/tests/ui/static_text/non_expr.stderr
Normal file
|
@ -0,0 +1,11 @@
|
|||
error: argument to `static_text` must be a string literal: `#[static_text("...")]`
|
||||
--> tests/ui/static_text/non_expr.rs:7:7
|
||||
|
|
||||
7 | #[static_text(SyntaxKind)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: expected string literal
|
||||
--> tests/ui/static_text/non_expr.rs:7:19
|
||||
|
|
||||
7 | #[static_text(SyntaxKind)]
|
||||
| ^^^^^^^^^^
|
11
test_suite/tests/ui/static_text/non_string_expr.rs
Normal file
11
test_suite/tests/ui/static_text/non_string_expr.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
use cstree::Syntax;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Syntax)]
|
||||
#[repr(u32)]
|
||||
pub enum SyntaxKind {
|
||||
A,
|
||||
#[static_text(foo + 3)]
|
||||
B,
|
||||
}
|
||||
|
||||
fn main() {}
|
11
test_suite/tests/ui/static_text/non_string_expr.stderr
Normal file
11
test_suite/tests/ui/static_text/non_string_expr.stderr
Normal file
|
@ -0,0 +1,11 @@
|
|||
error: argument to `static_text` must be a string literal: `#[static_text("...")]`
|
||||
--> tests/ui/static_text/non_string_expr.rs:7:7
|
||||
|
|
||||
7 | #[static_text(foo + 3)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: expected string literal
|
||||
--> tests/ui/static_text/non_string_expr.rs:7:19
|
||||
|
|
||||
7 | #[static_text(foo + 3)]
|
||||
| ^^^
|
11
test_suite/tests/ui/static_text/text_assigned.rs
Normal file
11
test_suite/tests/ui/static_text/text_assigned.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
use cstree::Syntax;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Syntax)]
|
||||
#[repr(u32)]
|
||||
pub enum SyntaxKind {
|
||||
A,
|
||||
#[static_text = "b"]
|
||||
B,
|
||||
}
|
||||
|
||||
fn main() {}
|
5
test_suite/tests/ui/static_text/text_assigned.stderr
Normal file
5
test_suite/tests/ui/static_text/text_assigned.stderr
Normal file
|
@ -0,0 +1,5 @@
|
|||
error: `static_text` takes the text as a function argument: `#[static_text("...")]`
|
||||
--> tests/ui/static_text/text_assigned.rs:7:5
|
||||
|
|
||||
7 | #[static_text = "b"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
Loading…
Add table
Add a link
Reference in a new issue