From 2c5b4a3ed6aac1be105fe7ac034b742fa5e0b405 Mon Sep 17 00:00:00 2001 From: Ruihang Xia Date: Fri, 30 Jun 2023 11:26:35 +0800 Subject: [PATCH 1/2] feat: display comment on result file Signed-off-by: Ruihang Xia --- .../interceptor-replace/simple/replace.result | 1 + sqlness/src/case.rs | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/sqlness/examples/interceptor-replace/simple/replace.result b/sqlness/examples/interceptor-replace/simple/replace.result index f527f56..60d17d6 100644 --- a/sqlness/examples/interceptor-replace/simple/replace.result +++ b/sqlness/examples/interceptor-replace/simple/replace.result @@ -13,6 +13,7 @@ SELECT 0; SELECT 1; +-- example of capture group replacement -- SQLNESS REPLACE (?P\d{4})-(?P\d{2})-(?P\d{2}) $m/$d/$y 2012-03-14, 2013-01-01 and 2014-07-05; diff --git a/sqlness/src/case.rs b/sqlness/src/case.rs index db5e659..d09ebd0 100644 --- a/sqlness/src/case.rs +++ b/sqlness/src/case.rs @@ -35,14 +35,20 @@ impl TestCase { let reader = BufReader::new(file); for line in reader.lines() { let line = line?; - // intercept command start with INTERCEPTOR_PREFIX - if line.starts_with(&cfg.interceptor_prefix) { - query.push_interceptor(&cfg.interceptor_prefix, line); + + // record comment + if line.starts_with(COMMENT_PREFIX) { + query.push_comment(line.clone()); + + // intercept command start with INTERCEPTOR_PREFIX + if line.starts_with(&cfg.interceptor_prefix) { + query.push_interceptor(&cfg.interceptor_prefix, line); + } continue; } - // ignore comment and empty line - if line.starts_with(COMMENT_PREFIX) || line.is_empty() { + // ignore empty line + if line.is_empty() { continue; } @@ -89,8 +95,8 @@ pub struct QueryContext { #[derive(Default)] struct Query { + comment_lines: Vec, query_lines: Vec, - interceptor_lines: Vec, interceptor_factories: Vec, interceptors: Vec, } @@ -112,7 +118,10 @@ impl Query { self.interceptors.push(interceptor); } } - self.interceptor_lines.push(interceptor_line); + } + + fn push_comment(&mut self, comment_line: String) { + self.comment_lines.push(comment_line); } fn append_query_line(&mut self, line: &str) { @@ -165,8 +174,8 @@ impl Query { where W: Write, { - for interceptor in &self.interceptor_lines { - writer.write_all(interceptor.as_bytes())?; + for comment in &self.comment_lines { + writer.write_all(comment.as_bytes())?; writer.write("\n".as_bytes())?; } for line in &self.query_lines { From 7c325cf7adf2a5e26cd8b32a6d5663c40fa0e401 Mon Sep 17 00:00:00 2001 From: Ruihang Xia Date: Fri, 30 Jun 2023 11:35:15 +0800 Subject: [PATCH 2/2] update mysql result Signed-off-by: Ruihang Xia --- sqlness-cli/tests/local/input.result | 1 + 1 file changed, 1 insertion(+) diff --git a/sqlness-cli/tests/local/input.result b/sqlness-cli/tests/local/input.result index 85cb44f..5f2547d 100644 --- a/sqlness-cli/tests/local/input.result +++ b/sqlness-cli/tests/local/input.result @@ -1,3 +1,4 @@ +-- https://dev.mysql.com/doc/refman/8.0/en/example-auto-increment.html DROP TABLE IF EXISTS animals; affected_rows: 0