Skip to content

Commit 8c8b245

Browse files
shruti2522alamb
andauthored
Migrate user_defined tests to insta (#15255)
* migrate user_defined tests to insta * fix tests * test * fmt * update snaps * add snaps * add snaps * add inline snapshots * fix * remove snaps * Reuse batches_to_stirng --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent 9e1e32f commit 8c8b245

6 files changed

+514
-502
lines changed

datafusion/core/tests/user_defined/expr_planner.rs

+30-27
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
// under the License.
1717

1818
use arrow::array::RecordBatch;
19+
use datafusion::common::test_util::batches_to_string;
1920
use std::sync::Arc;
2021

21-
use datafusion::common::{assert_batches_eq, DFSchema};
22+
use datafusion::common::DFSchema;
2223
use datafusion::error::Result;
2324
use datafusion::execution::FunctionRegistry;
2425
use datafusion::logical_expr::Operator;
@@ -76,49 +77,51 @@ async fn plan_and_collect(sql: &str) -> Result<Vec<RecordBatch>> {
7677
#[tokio::test]
7778
async fn test_custom_operators_arrow() {
7879
let actual = plan_and_collect("select 'foo'->'bar';").await.unwrap();
79-
let expected = [
80-
"+----------------------------+",
81-
"| Utf8(\"foo\") || Utf8(\"bar\") |",
82-
"+----------------------------+",
83-
"| foobar |",
84-
"+----------------------------+",
85-
];
86-
assert_batches_eq!(&expected, &actual);
80+
insta::assert_snapshot!(batches_to_string(&actual), @r###"
81+
+----------------------------+
82+
| Utf8("foo") || Utf8("bar") |
83+
+----------------------------+
84+
| foobar |
85+
+----------------------------+
86+
"###);
8787
}
8888

8989
#[tokio::test]
9090
async fn test_custom_operators_long_arrow() {
9191
let actual = plan_and_collect("select 1->>2;").await.unwrap();
92-
let expected = [
93-
"+---------------------+",
94-
"| Int64(1) + Int64(2) |",
95-
"+---------------------+",
96-
"| 3 |",
97-
"+---------------------+",
98-
];
99-
assert_batches_eq!(&expected, &actual);
92+
insta::assert_snapshot!(batches_to_string(&actual), @r###"
93+
+---------------------+
94+
| Int64(1) + Int64(2) |
95+
+---------------------+
96+
| 3 |
97+
+---------------------+
98+
"###);
10099
}
101100

102101
#[tokio::test]
103102
async fn test_question_select() {
104103
let actual = plan_and_collect("select a ? 2 from (select 1 as a);")
105104
.await
106105
.unwrap();
107-
let expected = [
108-
"+--------------+",
109-
"| a ? Int64(2) |",
110-
"+--------------+",
111-
"| true |",
112-
"+--------------+",
113-
];
114-
assert_batches_eq!(&expected, &actual);
106+
insta::assert_snapshot!(batches_to_string(&actual), @r###"
107+
+--------------+
108+
| a ? Int64(2) |
109+
+--------------+
110+
| true |
111+
+--------------+
112+
"###);
115113
}
116114

117115
#[tokio::test]
118116
async fn test_question_filter() {
119117
let actual = plan_and_collect("select a from (select 1 as a) where a ? 2;")
120118
.await
121119
.unwrap();
122-
let expected = ["+---+", "| a |", "+---+", "| 1 |", "+---+"];
123-
assert_batches_eq!(&expected, &actual);
120+
insta::assert_snapshot!(batches_to_string(&actual), @r###"
121+
+---+
122+
| a |
123+
+---+
124+
| 1 |
125+
+---+
126+
"###);
124127
}

0 commit comments

Comments
 (0)