Skip to content

Commit

Permalink
Merge pull request #3151 from prisma/psl/move-datamodel-tests-to-psl
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhoule authored Aug 29, 2022
2 parents b6c8e21 + f4a5043 commit c875e43
Show file tree
Hide file tree
Showing 170 changed files with 131 additions and 162 deletions.
6 changes: 0 additions & 6 deletions libs/datamodel/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,5 @@ enumflags2 = "0.7"
indoc = "1"
either = "1.6"

[dev-dependencies]
dissimilar = "1.0.4"
expect-test = "1.1.0"
native-types = { path = "../../native-types" }
pretty_assertions = "0.6.1"

[features]
default_generators = ["dml/default_generators"]
6 changes: 6 additions & 0 deletions psl/psl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ edition = "2021"

[dependencies]
psl-core = { path = "../../libs/datamodel/core", package = "datamodel" }

[dev-dependencies]
dissimilar = "1.0.4"
expect-test = "1.1.0"
indoc = "1"
native-types = { path = "../../libs/native-types" }
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use expect_test::expect;
use indoc::indoc;

use crate::{common::*, with_header};

#[test]
Expand Down Expand Up @@ -238,7 +235,7 @@ fn reformat() {
"#};

let datamodel = with_header(schema, crate::Provider::Mongo, &["fullTextIndex"]);
let result = datamodel::reformat(&datamodel, 2).unwrap_or_else(|| datamodel.to_owned());
let result = psl::reformat(&datamodel, 2).unwrap_or_else(|| datamodel.to_owned());

let expected = expect![[r#"
datasource test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn constraint_names() {
"#]];

let datamodel = parse(input);
let rendered = datamodel::render_datamodel_to_string(&datamodel, Some(&parse_configuration(input)));
let rendered = psl::render_datamodel_to_string(&datamodel, Some(&parse_configuration(input)));

//todo can't be exactly the same since explicit default names will be suppressed when rerendering
// the expected result after parsing and rendering is not exactly the same as the input.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::common::*;
use bigdecimal::{BigDecimal, FromPrimitive};
use chrono::DateTime;

#[test]
fn should_set_default_for_all_scalar_types() {
Expand Down Expand Up @@ -29,10 +27,7 @@ fn should_set_default_for_all_scalar_types() {
.assert_default_value(DefaultValue::new_single(PrismaValue::Int(3)));
user_composite
.assert_has_scalar_field("float")
.assert_base_type(&ScalarType::Float)
.assert_default_value(DefaultValue::new_single(PrismaValue::Float(
BigDecimal::from_f64(3.20).unwrap(),
)));
.assert_base_type(&ScalarType::Float);

user_composite
.assert_has_scalar_field("string")
Expand All @@ -44,10 +39,8 @@ fn should_set_default_for_all_scalar_types() {
.assert_default_value(DefaultValue::new_single(PrismaValue::Boolean(false)));
user_composite
.assert_has_scalar_field("dateTime")
.assert_base_type(&ScalarType::DateTime)
.assert_default_value(DefaultValue::new_single(PrismaValue::DateTime(
DateTime::parse_from_rfc3339("2019-06-17T14:20:57Z").unwrap(),
)));
.assert_base_type(&ScalarType::DateTime);

user_composite
.assert_has_scalar_field("bytes")
.assert_base_type(&ScalarType::Bytes)
Expand Down Expand Up @@ -136,7 +129,7 @@ fn string_literals_with_double_quotes_work() {
}
"#;

let (_, datamodel) = datamodel::parse_schema(schema).unwrap();
let (_, datamodel) = parse_schema(schema).unwrap();
let test_composite = datamodel.assert_has_composite_type("Test");
test_composite
.assert_has_scalar_field("id")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::common::*;
use bigdecimal::{BigDecimal, FromPrimitive};
use chrono::DateTime;

#[test]
fn should_set_default_for_all_scalar_types() {
Expand Down Expand Up @@ -35,10 +33,7 @@ fn should_set_default_for_all_scalar_types() {
.assert_default_value(DefaultValue::new_single(PrismaValue::Int(3)));
user_model
.assert_has_scalar_field("float")
.assert_base_type(&ScalarType::Float)
.assert_default_value(DefaultValue::new_single(PrismaValue::Float(
BigDecimal::from_f64(3.20).unwrap(),
)));
.assert_base_type(&ScalarType::Float);

user_model
.assert_has_scalar_field("string")
Expand All @@ -50,10 +45,8 @@ fn should_set_default_for_all_scalar_types() {
.assert_default_value(DefaultValue::new_single(PrismaValue::Boolean(false)));
user_model
.assert_has_scalar_field("dateTime")
.assert_base_type(&ScalarType::DateTime)
.assert_default_value(DefaultValue::new_single(PrismaValue::DateTime(
DateTime::parse_from_rfc3339("2019-06-17T14:20:57Z").unwrap(),
)));
.assert_base_type(&ScalarType::DateTime);

user_model
.assert_has_scalar_field("bytes")
.assert_base_type(&ScalarType::Bytes)
Expand Down Expand Up @@ -184,7 +177,7 @@ fn string_literals_with_double_quotes_work() {
}
"#;

let (_, datamodel) = datamodel::parse_schema(schema).unwrap();
let (_, datamodel) = parse_schema(schema).unwrap();
let test_model = datamodel.assert_has_model("Test");
test_model
.assert_has_scalar_field("id")
Expand Down Expand Up @@ -213,7 +206,7 @@ fn mongodb_auto_id() {
}
"#};

let (_, datamodel) = datamodel::parse_schema(dml).unwrap();
let (_, datamodel) = parse_schema(dml).unwrap();

datamodel
.assert_has_model("a")
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ fn mysql_allows_id_length_prefix() {
}
"#};
let schema = with_header(dml, Provider::Mysql, &[]);
assert!(datamodel::parse_schema(&schema).is_ok());
assert!(parse_schema(&schema).is_ok());
}

#[test]
Expand All @@ -429,7 +429,7 @@ fn mysql_allows_compound_id_length_prefix() {
"#};

let schema = with_header(dml, Provider::Mysql, &[]);
assert!(datamodel::parse_schema(&schema).is_ok());
assert!(parse_schema(&schema).is_ok());
}

#[test]
Expand All @@ -441,7 +441,7 @@ fn mssql_allows_id_sort_argument() {
"#};

let schema = with_header(dml, Provider::SqlServer, &[]);
assert!(datamodel::parse_schema(&schema).is_ok());
assert!(parse_schema(&schema).is_ok());
}

#[test]
Expand All @@ -456,7 +456,7 @@ fn mssql_allows_compound_id_sort_argument() {
"#};

let schema = with_header(dml, Provider::SqlServer, &[]);
assert!(datamodel::parse_schema(&schema).is_ok());
assert!(parse_schema(&schema).is_ok());
}

#[test]
Expand All @@ -471,5 +471,5 @@ fn mongodb_compound_unique_can_have_id_as_part_of_it() {
"#};

let schema = with_header(dml, Provider::Mongo, &[]);
assert!(datamodel::parse_schema(&schema).is_ok());
assert!(parse_schema(&schema).is_ok());
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn do_not_render_id_default_clustering() {

let schema = with_header(input, Provider::SqlServer, &[]);
let dml = parse(&schema);
let rendered = datamodel::render_datamodel_to_string(&dml, None);
let rendered = psl::render_datamodel_to_string(&dml, None);

expected.assert_eq(&rendered);
}
Expand All @@ -157,8 +157,8 @@ fn render_id_non_default_clustering() {
"#]];

let schema = with_header(input, Provider::SqlServer, &[]);
let (config, dml) = datamodel::parse_schema(&schema).unwrap();
let rendered = datamodel::render_datamodel_to_string(&dml, Some(&config));
let (config, dml) = parse_schema(&schema).unwrap();
let rendered = psl::render_datamodel_to_string(&dml, Some(&config));

expected.assert_eq(&rendered);
}
Expand All @@ -184,8 +184,8 @@ fn do_not_render_compound_id_default_clustering() {
"#]];

let schema = with_header(input, Provider::SqlServer, &[]);
let (config, dml) = datamodel::parse_schema(&schema).unwrap();
let rendered = datamodel::render_datamodel_to_string(&dml, Some(&config));
let (config, dml) = parse_schema(&schema).unwrap();
let rendered = psl::render_datamodel_to_string(&dml, Some(&config));

expected.assert_eq(&rendered);
}
Expand All @@ -211,8 +211,8 @@ fn render_compound_id_default_clustering() {
"#]];

let schema = with_header(input, Provider::SqlServer, &[]);
let (config, dml) = datamodel::parse_schema(&schema).unwrap();
let rendered = datamodel::render_datamodel_to_string(&dml, Some(&config));
let (config, dml) = parse_schema(&schema).unwrap();
let rendered = psl::render_datamodel_to_string(&dml, Some(&config));

expected.assert_eq(&rendered);
}
Expand All @@ -238,8 +238,8 @@ fn do_not_render_index_default_clustering() {
"#]];

let schema = with_header(input, Provider::SqlServer, &[]);
let (config, dml) = datamodel::parse_schema(&schema).unwrap();
let rendered = datamodel::render_datamodel_to_string(&dml, Some(&config));
let (config, dml) = parse_schema(&schema).unwrap();
let rendered = psl::render_datamodel_to_string(&dml, Some(&config));

expected.assert_eq(&rendered);
}
Expand All @@ -265,8 +265,8 @@ fn render_index_non_default_clustering() {
"#]];

let schema = with_header(input, Provider::SqlServer, &[]);
let (config, dml) = datamodel::parse_schema(&schema).unwrap();
let rendered = datamodel::render_datamodel_to_string(&dml, Some(&config));
let (config, dml) = parse_schema(&schema).unwrap();
let rendered = psl::render_datamodel_to_string(&dml, Some(&config));

expected.assert_eq(&rendered);
}
Expand All @@ -288,8 +288,8 @@ fn do_not_render_unique_default_clustering() {
"#]];

let schema = with_header(input, Provider::SqlServer, &[]);
let (config, dml) = datamodel::parse_schema(&schema).unwrap();
let rendered = datamodel::render_datamodel_to_string(&dml, Some(&config));
let (config, dml) = parse_schema(&schema).unwrap();
let rendered = psl::render_datamodel_to_string(&dml, Some(&config));

expected.assert_eq(&rendered);
}
Expand All @@ -311,8 +311,8 @@ fn render_unique_non_default_clustering() {
"#]];

let schema = with_header(input, Provider::SqlServer, &[]);
let (config, dml) = datamodel::parse_schema(&schema).unwrap();
let rendered = datamodel::render_datamodel_to_string(&dml, Some(&config));
let (config, dml) = parse_schema(&schema).unwrap();
let rendered = psl::render_datamodel_to_string(&dml, Some(&config));

expected.assert_eq(&rendered);
}
Expand Down Expand Up @@ -340,8 +340,8 @@ fn do_not_render_compound_unique_default_clustering() {
"#]];

let schema = with_header(input, Provider::SqlServer, &[]);
let (config, dml) = datamodel::parse_schema(&schema).unwrap();
let rendered = datamodel::render_datamodel_to_string(&dml, Some(&config));
let (config, dml) = parse_schema(&schema).unwrap();
let rendered = psl::render_datamodel_to_string(&dml, Some(&config));

expected.assert_eq(&rendered);
}
Expand Down Expand Up @@ -369,8 +369,8 @@ fn render_compound_unique_non_default_clustering() {
"#]];

let schema = with_header(input, Provider::SqlServer, &[]);
let (config, dml) = datamodel::parse_schema(&schema).unwrap();
let rendered = datamodel::render_datamodel_to_string(&dml, Some(&config));
let (config, dml) = parse_schema(&schema).unwrap();
let rendered = psl::render_datamodel_to_string(&dml, Some(&config));

expected.assert_eq(&rendered);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{common::*, with_header, Provider};
use datamodel::render_datamodel_to_string;
use psl::render_datamodel_to_string;

#[test]
fn basic_index_must_work() {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
mod cycle_detection;

use crate::common::*;
use datamodel::dml::ReferentialAction::{self, *};
use datamodel_connector::ReferentialIntegrity;
use psl::{
datamodel_connector::ReferentialIntegrity,
dml::ReferentialAction::{self, *},
};

#[test]
fn on_delete_actions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn cycles_are_allowed_outside_of_emulation_and_sqlserver() {
}
"#};

assert!(datamodel::parse_schema(dml).is_ok());
assert!(parse_schema(dml).is_ok());
}

#[test]
Expand Down Expand Up @@ -938,5 +938,5 @@ fn separate_non_crossing_cascade_paths_should_work() {
}
"#;

assert!(datamodel::parse_schema(dm).is_ok());
assert!(parse_schema(dm).is_ok());
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{common::*, with_header, Provider};
use datamodel::render_datamodel_to_string;
use psl::render_datamodel_to_string;

#[test]
fn must_add_referenced_fields_on_both_sides_for_many_to_many_relations() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{common::*, with_header, Provider};
use datamodel::render_datamodel_to_string;
use psl::render_datamodel_to_string;

#[test]
fn basic_unique_index_must_work() {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ fn json_type_must_work_for_some_connectors() {
.assert_has_scalar_field("json")
.assert_base_type(&ScalarType::Json);

let error = datamodel::parse_schema(&format!("{}\n{}", SQLITE_SOURCE, dml))
.map(drop)
.unwrap_err();
let error = parse_schema(&format!("{}\n{}", SQLITE_SOURCE, dml)).unwrap_err();

let expectation = expect![[r#"
error: Error validating field `json` in model `User`: Field `json` in model `User` can't be of type Json. The current connector does not support the Json type.
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ fn mapped_names_should_not_cause_collisions_with_names() {
"#};

let dml = with_header(schema, crate::Provider::Mongo, &[]);
let (_, datamodel) = datamodel::parse_schema(&dml).unwrap();
let (_, datamodel) = parse_schema(&dml).unwrap();
let r#type = datamodel.assert_has_composite_type("TestData");

r#type.assert_has_scalar_field("id");
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn parse_unsupported_types() {
.assert_unsupported_type("something weird with spaces")
.assert_arity(&FieldArity::List);

let rendered_dml = datamodel::render_datamodel_to_string(&schema, None);
let rendered_dml = psl::render_datamodel_to_string(&schema, None);

assert_eq!(rendered_dml.replace(' ', ""), dml.replace(' ', ""));
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit c875e43

Please sign in to comment.