|
| 1 | +use crate::analysis_route::main::clickhouse_type_match::clickhouse_type_match; |
| 2 | +use crate::analysis_route::models::TypeMatch; |
| 3 | +use crate::analysis_route::tests::test_types::TypeMatchTestCase; |
| 4 | + |
| 5 | +#[test] |
| 6 | +fn given_clickhouse_column_types_when_matching_then_wrappers_are_stripped_and_nullability_compared_apart() |
| 7 | + { |
| 8 | + let test_cases = [ |
| 9 | + TypeMatchTestCase { |
| 10 | + description: "a nullable String flag matches DESCRIBE's Nullable(String)", |
| 11 | + declared: "Nullable(String)", |
| 12 | + inferred: "String", |
| 13 | + inferred_nullable: true, |
| 14 | + expected_match: TypeMatch { |
| 15 | + same_type: true, |
| 16 | + nullable_into_non_null: false, |
| 17 | + }, |
| 18 | + }, |
| 19 | + TypeMatchTestCase { |
| 20 | + description: "a declared LowCardinality(String) is a String", |
| 21 | + declared: "LowCardinality(String)", |
| 22 | + inferred: "String", |
| 23 | + inferred_nullable: false, |
| 24 | + expected_match: TypeMatch { |
| 25 | + same_type: true, |
| 26 | + nullable_into_non_null: false, |
| 27 | + }, |
| 28 | + }, |
| 29 | + TypeMatchTestCase { |
| 30 | + description: "LowCardinality around Nullable allows null", |
| 31 | + declared: "LowCardinality(Nullable(String))", |
| 32 | + inferred: "Nullable(String)", |
| 33 | + inferred_nullable: false, |
| 34 | + expected_match: TypeMatch { |
| 35 | + same_type: true, |
| 36 | + nullable_into_non_null: false, |
| 37 | + }, |
| 38 | + }, |
| 39 | + TypeMatchTestCase { |
| 40 | + description: "a nullable inference into a plain String declaration is a nullability conflict", |
| 41 | + declared: "String", |
| 42 | + inferred: "String", |
| 43 | + inferred_nullable: true, |
| 44 | + expected_match: TypeMatch { |
| 45 | + same_type: true, |
| 46 | + nullable_into_non_null: true, |
| 47 | + }, |
| 48 | + }, |
| 49 | + TypeMatchTestCase { |
| 50 | + description: "a non-null inference into a Nullable declaration is no conflict", |
| 51 | + declared: "Nullable(Int64)", |
| 52 | + inferred: "Int64", |
| 53 | + inferred_nullable: false, |
| 54 | + expected_match: TypeMatch { |
| 55 | + same_type: true, |
| 56 | + nullable_into_non_null: false, |
| 57 | + }, |
| 58 | + }, |
| 59 | + TypeMatchTestCase { |
| 60 | + description: "different base types differ whatever their wrappers", |
| 61 | + declared: "Nullable(Int32)", |
| 62 | + inferred: "Int64", |
| 63 | + inferred_nullable: true, |
| 64 | + expected_match: TypeMatch { |
| 65 | + same_type: false, |
| 66 | + nullable_into_non_null: false, |
| 67 | + }, |
| 68 | + }, |
| 69 | + TypeMatchTestCase { |
| 70 | + description: "a Nullable nested inside Array is part of the type, not stripped", |
| 71 | + declared: "Array(Nullable(String))", |
| 72 | + inferred: "Array(String)", |
| 73 | + inferred_nullable: false, |
| 74 | + expected_match: TypeMatch { |
| 75 | + same_type: false, |
| 76 | + nullable_into_non_null: false, |
| 77 | + }, |
| 78 | + }, |
| 79 | + ]; |
| 80 | + for test_case in test_cases { |
| 81 | + assert_eq!( |
| 82 | + clickhouse_type_match( |
| 83 | + test_case.declared, |
| 84 | + test_case.inferred, |
| 85 | + test_case.inferred_nullable |
| 86 | + ), |
| 87 | + test_case.expected_match, |
| 88 | + "{}", |
| 89 | + test_case.description |
| 90 | + ); |
| 91 | + } |
| 92 | +} |
0 commit comments