Skip to content

Commit

Permalink
Lint: Use with_capacity (#27)
Browse files Browse the repository at this point in the history
* use with_capacity

* adds test
  • Loading branch information
Amogh-Bharadwaj authored Nov 21, 2023
1 parent db7b94f commit d7c5248
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ impl<'a> Tokenizer<'a> {
pub fn tokenize(&mut self) -> Result<Vec<Token>, TokenizerError> {
let twl = self.tokenize_with_location()?;

let mut tokens: Vec<Token> = vec![];
tokens.reserve(twl.len());
let mut tokens: Vec<Token> = Vec::with_capacity(twl.len());
for token_with_location in twl {
tokens.push(token_with_location.token);
}
Expand Down
43 changes: 43 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3440,6 +3440,49 @@ fn parse_create_eventhub_group_peer() {
}
}

#[test]
fn parse_create_s3_peer() {
match pg().verified_stmt(
"CREATE PEER s3_1 FROM S3 WITH \
(url = 's3://bucket_name/prefix_name', \
access_key_id = 'access_key_id', \
secret_access_key = 'secret_access_key')",
) {
Statement::CreatePeer {
if_not_exists: _,
peer_name: _,
peer_type,
with_options,
} => {
assert_eq!(peer_type, PeerType::S3);
assert_eq!(
with_options,
vec![
SqlOption {
name: Ident::new("url"),
value: sqlparser::ast::Value::SingleQuotedString(String::from(
"s3://bucket_name/prefix_name"
))
},
SqlOption {
name: Ident::new("access_key_id"),
value: sqlparser::ast::Value::SingleQuotedString(String::from(
"access_key_id"
))
},
SqlOption {
name: Ident::new("secret_access_key"),
value: sqlparser::ast::Value::SingleQuotedString(String::from(
"secret_access_key"
))
}
]
);
}
_ => unreachable!(),
}
}

#[test]
fn parse_create_single_mirror() {
match pg().verified_stmt("CREATE MIRROR IF NOT EXISTS test_mirror FROM p1 TO p2 WITH TABLE MAPPING ({from : s1.t1, to : s2.t2}) WITH (key1 = 'value1')") {
Expand Down

0 comments on commit d7c5248

Please sign in to comment.