Skip to content

Commit 8fdfa61

Browse files
Added derive for arbitrary
1 parent 3ac5670 commit 8fdfa61

19 files changed

+498
-0
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ recursive-protection = ["std", "recursive"]
4444
json_example = ["serde_json", "serde"]
4545
derive-dialect = ["sqlparser_derive"]
4646
visitor = ["sqlparser_derive"]
47+
arbitrary = ["dep:arbitrary"]
4748

4849
[dependencies]
4950
bigdecimal = { version = "0.4.1", features = ["serde"], optional = true }
@@ -56,6 +57,7 @@ serde = { version = "1.0", default-features = false, features = ["derive", "allo
5657
# https://github.com/rust-lang/cargo/issues/1596
5758
serde_json = { version = "1.0", optional = true }
5859
sqlparser_derive = { version = "0.4.0", path = "derive", optional = true }
60+
arbitrary = { version = "1.0", features = ["derive"], optional = true }
5961

6062
[dev-dependencies]
6163
simple_logger = "5.0"

src/ast/comments.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::tokenizer::{Location, Span};
2626

2727
/// An opaque container for comments from a parse SQL source code.
2828
#[derive(Default, Debug, Clone)]
29+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2930
pub struct Comments(Vec<CommentWithSpan>);
3031

3132
impl Comments {
@@ -152,6 +153,7 @@ impl From<Comments> for Vec<CommentWithSpan> {
152153

153154
/// A source code comment with information of its entire span.
154155
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
156+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
155157
pub struct CommentWithSpan {
156158
/// The source code comment iself
157159
pub comment: Comment,
@@ -169,6 +171,7 @@ impl Deref for CommentWithSpan {
169171

170172
/// A unified type of the different source code comment formats.
171173
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
174+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
172175
pub enum Comment {
173176
/// A single line comment, typically introduced with a prefix and spanning
174177
/// until end-of-line or end-of-file in the source code.

src/ast/data_type.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use super::{value::escape_single_quote_string, ColumnDef};
3333
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3434
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3535
/// A member of an ENUM type.
36+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
3637
pub enum EnumMember {
3738
/// Just a name.
3839
Name(String),
@@ -46,6 +47,7 @@ pub enum EnumMember {
4647
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4748
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4849
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
50+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
4951
pub enum DataType {
5052
/// Table type in [PostgreSQL], e.g. CREATE FUNCTION RETURNS TABLE(...).
5153
///
@@ -897,6 +899,7 @@ fn format_clickhouse_datetime_precision_and_timezone(
897899
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
898900
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
899901
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
902+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
900903
pub enum StructBracketKind {
901904
/// Example: `STRUCT(a INT, b STRING)`
902905
Parentheses,
@@ -911,6 +914,7 @@ pub enum StructBracketKind {
911914
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
912915
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
913916
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
917+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
914918
pub enum TimezoneInfo {
915919
/// No information about time zone, e.g. TIMESTAMP
916920
None,
@@ -958,6 +962,7 @@ impl fmt::Display for TimezoneInfo {
958962
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
959963
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
960964
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
965+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
961966
pub enum IntervalFields {
962967
/// `YEAR` field
963968
Year,
@@ -1014,6 +1019,7 @@ impl fmt::Display for IntervalFields {
10141019
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10151020
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10161021
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1022+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
10171023
pub enum ExactNumberInfo {
10181024
/// No additional information, e.g. `DECIMAL`.
10191025
None,
@@ -1045,6 +1051,7 @@ impl fmt::Display for ExactNumberInfo {
10451051
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10461052
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10471053
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1054+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
10481055
pub enum CharacterLength {
10491056
/// Integer length with optional unit (e.g. `CHAR(10)` or `VARCHAR(10 CHARACTERS)`).
10501057
IntegerLength {
@@ -1080,6 +1087,7 @@ impl fmt::Display for CharacterLength {
10801087
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10811088
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10821089
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1090+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
10831091
pub enum CharLengthUnits {
10841092
/// CHARACTERS unit
10851093
Characters,
@@ -1106,6 +1114,7 @@ impl fmt::Display for CharLengthUnits {
11061114
/// Information about [binary length][1], including length and possibly unit.
11071115
///
11081116
/// [1]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#binary-length
1117+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
11091118
pub enum BinaryLength {
11101119
/// Integer length for binary types (e.g. `VARBINARY(100)`).
11111120
IntegerLength {
@@ -1137,6 +1146,7 @@ impl fmt::Display for BinaryLength {
11371146
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11381147
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11391148
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1149+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
11401150
pub enum ArrayElemTypeDef {
11411151
/// Use `ARRAY` style without an explicit element type.
11421152
None,
@@ -1155,6 +1165,7 @@ pub enum ArrayElemTypeDef {
11551165
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
11561166
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11571167
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1168+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
11581169
pub enum GeometricTypeKind {
11591170
/// Point geometry
11601171
Point,

src/ast/dcl.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use crate::tokenizer::Span;
4141
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4242
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4343
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
44+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
4445
pub enum RoleOption {
4546
/// Enable or disable BYPASSRLS.
4647
BypassRLS(bool),
@@ -116,6 +117,7 @@ impl fmt::Display for RoleOption {
116117
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
117118
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
118119
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
120+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
119121
pub enum SetConfigValue {
120122
/// Use the default value.
121123
Default,
@@ -131,6 +133,7 @@ pub enum SetConfigValue {
131133
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
132134
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
133135
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
136+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
134137
pub enum ResetConfig {
135138
/// Reset all configuration parameters.
136139
ALL,
@@ -142,6 +145,7 @@ pub enum ResetConfig {
142145
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
143146
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
144147
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
148+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
145149
pub enum AlterRoleOperation {
146150
/// Generic
147151
RenameRole {
@@ -242,6 +246,7 @@ impl fmt::Display for AlterRoleOperation {
242246
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
243247
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
244248
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
249+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
245250
pub enum Use {
246251
/// Switch to the given catalog (e.g. `USE CATALOG ...`).
247252
Catalog(ObjectName),
@@ -284,6 +289,7 @@ impl fmt::Display for Use {
284289
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
285290
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
286291
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
292+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
287293
pub enum SecondaryRoles {
288294
/// Use all secondary roles.
289295
All,
@@ -308,6 +314,7 @@ impl fmt::Display for SecondaryRoles {
308314
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
309315
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
310316
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
317+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
311318
pub struct CreateRole {
312319
/// Role names to create.
313320
pub names: Vec<ObjectName>,
@@ -435,6 +442,7 @@ impl Spanned for CreateRole {
435442
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
436443
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
437444
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
445+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
438446
pub struct Grant {
439447
/// Privileges being granted.
440448
pub privileges: Privileges,
@@ -489,6 +497,7 @@ impl From<Grant> for crate::ast::Statement {
489497
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
490498
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
491499
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
500+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
492501
pub struct Revoke {
493502
/// Privileges to revoke.
494503
pub privileges: Privileges,

0 commit comments

Comments
 (0)