Skip to content

Commit 70916b6

Browse files
committed
switched to stable and removed all instances of unwrap()
1 parent c674cce commit 70916b6

File tree

7 files changed

+253
-270
lines changed

7 files changed

+253
-270
lines changed

rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "stable"
3+
components = ["clippy"]

rustfmt.toml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,4 @@ edition = "2024"
22
max_width = 100
33
use_small_heuristics = "Max"
44
reorder_imports = true
5-
group_imports = "StdExternalCrate"
6-
imports_granularity = "Crate"
75
reorder_modules = true
8-
wrap_comments = true
9-
format_code_in_doc_comments = true
10-
comment_width = 80
11-
normalize_comments = true
12-
normalize_doc_attributes = true
13-
force_multiline_blocks = true
14-
fn_single_line = false
15-
where_single_line = false
16-
format_strings = true
17-
reorder_impl_items = true

src/ast.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ mod tests {
9696
fn parsed_sql_file_parses_single_statement() {
9797
let base = env::temp_dir().join("parsed_sql_file_single_stmt_test");
9898
let _ = fs::remove_dir_all(&base);
99-
fs::create_dir_all(&base).unwrap();
99+
fs::create_dir_all(&base).unwrap_or_else(|e| panic!("panicked on {e}"));
100100
let file_path = base.join("one.sql");
101101
let sql = "CREATE TABLE users (id INTEGER PRIMARY KEY);";
102-
fs::write(&file_path, sql).unwrap();
103-
let sql_file = SqlFile::new(&file_path).unwrap();
104-
let parsed = ParsedSqlFile::parse(sql_file).unwrap();
102+
fs::write(&file_path, sql).unwrap_or_else(|e| panic!("panicked on {e}"));
103+
let sql_file = SqlFile::new(&file_path).unwrap_or_else(|e| panic!("panicked on {e}"));
104+
let parsed = ParsedSqlFile::parse(sql_file).unwrap_or_else(|e| panic!("panicked on {e}"));
105105
assert_eq!(parsed.path(), file_path.as_path());
106106
assert_eq!(parsed.content(), sql);
107107
assert_eq!(parsed.statements().len(), 1);
@@ -112,25 +112,26 @@ mod tests {
112112
fn parsed_sql_file_set_parses_multiple_files() {
113113
let base = env::temp_dir().join("parsed_sql_file_set_multi_test");
114114
let _ = fs::remove_dir_all(&base);
115-
fs::create_dir_all(&base).unwrap();
115+
fs::create_dir_all(&base).unwrap_or_else(|e| panic!("panicked on {e}"));
116116
let sub = base.join("subdir");
117-
fs::create_dir_all(&sub).unwrap();
117+
fs::create_dir_all(&sub).unwrap_or_else(|e| panic!("panicked on {e}"));
118118
let file1 = base.join("one.sql");
119119
let file2 = sub.join("two.sql");
120120
let sql1 = "CREATE TABLE users (id INTEGER PRIMARY KEY);";
121121
let sql2 = "CREATE TABLE posts (id INTEGER PRIMARY KEY);";
122-
fs::write(&file1, sql1).unwrap();
123-
fs::write(&file2, sql2).unwrap();
124-
let set = SqlFileSet::new(&base, None).unwrap();
125-
let parsed_set = ParsedSqlFileSet::parse_all(set).unwrap();
126-
let files = parsed_set.files();
127-
assert_eq!(files.len(), 2);
128-
for parsed in files {
122+
fs::write(&file1, sql1).unwrap_or_else(|e| panic!("panicked on {e}"));
123+
fs::write(&file2, sql2).unwrap_or_else(|e| panic!("panicked on {e}"));
124+
let set = SqlFileSet::new(&base, None).unwrap_or_else(|e| panic!("panicked on {e}"));
125+
let parsed_set =
126+
ParsedSqlFileSet::parse_all(set).unwrap_or_else(|e| panic!("panicked on {e}"));
127+
let existing_files = parsed_set.files();
128+
assert_eq!(existing_files.len(), 2);
129+
for parsed in existing_files {
129130
assert_eq!(parsed.statements().len(), 1);
130131
let stmt = &parsed.statements()[0];
131132
match stmt {
132133
Statement::CreateTable { .. } => {}
133-
other => panic!("expected CreateTable, got: {:?}", other),
134+
other => panic!("expected CreateTable, got: {other:?}"),
134135
}
135136
}
136137

src/comments.rs

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,7 @@ fn span_default_and_updates() {
380380
assert_eq!(default.start, Location::default());
381381
assert_eq!(default.end, Location::default());
382382

383-
let mut span = Span::default();
384-
span.end = Location::new(55, 100);
383+
let span = Span { end: Location::new(55, 100), ..Default::default() };
385384

386385
assert_eq!(span.start, Location::default());
387386
assert_eq!(span.end, Location { line: 55, column: 100 });
@@ -424,11 +423,13 @@ fn parse_comments() {
424423

425424
use crate::{ast::ParsedSqlFileSet, files::SqlFileSet};
426425
let path = Path::new("sql_files");
427-
let set = SqlFileSet::new(path, None).unwrap();
428-
let parsed_set = ParsedSqlFileSet::parse_all(set).unwrap();
429-
for file in parsed_set.files().iter() {
430-
let parsed_comments = Comments::parse_all_comments_from_file(file).unwrap();
431-
match file.file().path().to_str().unwrap() {
426+
let set = SqlFileSet::new(path, None).unwrap_or_else(|e| panic!("panicked on {e}"));
427+
let parsed_set = ParsedSqlFileSet::parse_all(set).unwrap_or_else(|e| panic!("panicked on {e}"));
428+
for file in parsed_set.files() {
429+
let parsed_comments = Comments::parse_all_comments_from_file(file)
430+
.unwrap_or_else(|e| panic!("panicked on {e}"));
431+
let file_path = file.file().path().to_str().map_or_else(|| panic!("panicked"), |val| val);
432+
match file_path {
432433
"sql_files/with_single_line_comments.sql" => {
433434
let expected = [
434435
"Users table stores user account information",
@@ -514,14 +515,22 @@ fn single_line_comment_spans_are_correct() {
514515

515516
use crate::{ast::ParsedSqlFileSet, files::SqlFileSet};
516517
let path = Path::new("sql_files");
517-
let set = SqlFileSet::new(path, None).unwrap();
518-
let parsed_set = ParsedSqlFileSet::parse_all(set).unwrap();
519-
let file = parsed_set
520-
.files()
521-
.iter()
522-
.find(|f| f.file().path().to_str().unwrap().ends_with("with_single_line_comments.sql"))
523-
.expect("with_single_line_comments.sql should be present");
524-
let comments = Comments::parse_all_comments_from_file(file).unwrap();
518+
let set = SqlFileSet::new(path, None).unwrap_or_else(|e| panic!("panicked on {e}"));
519+
let parsed_set = ParsedSqlFileSet::parse_all(set).unwrap_or_else(|e| panic!("panicked on {e}"));
520+
let file = {
521+
let Some(f) = parsed_set.files().iter().find(|f| {
522+
let Some(path) = f.file().path().to_str() else {
523+
return false;
524+
};
525+
path.ends_with("with_single_line_comments.sql")
526+
}) else {
527+
panic!("with_single_line_comments.sql should be present");
528+
};
529+
f
530+
};
531+
532+
let comments =
533+
Comments::parse_all_comments_from_file(file).unwrap_or_else(|e| panic!("panicked on {e}"));
525534
let comments = comments.comments();
526535
assert_eq!(comments.len(), 11);
527536
let first = &comments[0];
@@ -544,14 +553,21 @@ fn multiline_comment_spans_are_correct() {
544553

545554
use crate::{ast::ParsedSqlFileSet, files::SqlFileSet};
546555
let path = Path::new("sql_files");
547-
let set = SqlFileSet::new(path, None).unwrap();
548-
let parsed_set = ParsedSqlFileSet::parse_all(set).unwrap();
549-
let file = parsed_set
550-
.files()
551-
.iter()
552-
.find(|f| f.file().path().to_str().unwrap().ends_with("with_multiline_comments.sql"))
553-
.expect("with_multiline_comments.sql should be present");
554-
let comments = Comments::parse_all_comments_from_file(file).unwrap();
556+
let set = SqlFileSet::new(path, None).unwrap_or_else(|e| panic!("panicked on {e}"));
557+
let parsed_set = ParsedSqlFileSet::parse_all(set).unwrap_or_else(|e| panic!("panicked on {e}"));
558+
let file = {
559+
let Some(f) = parsed_set.files().iter().find(|f| {
560+
let Some(path) = f.file().path().to_str() else {
561+
return false;
562+
};
563+
path.ends_with("with_multiline_comments.sql")
564+
}) else {
565+
panic!("with_multiline_comments.sql should be present");
566+
};
567+
f
568+
};
569+
let comments =
570+
Comments::parse_all_comments_from_file(file).unwrap_or_else(|e| panic!("panicked on {e}"));
555571
let comments = comments.comments();
556572
assert_eq!(comments.len(), 11);
557573
let first = &comments[0];

0 commit comments

Comments
 (0)