summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-02-07 18:41:10 -0800
committerGitHub <noreply@github.com>2017-02-07 18:41:10 -0800
commitcedadf9c48099d831b898d5c90e2868f4d11743f (patch)
treeb24beefcf7e7f7e82a7636793f66efb4d947cd95
parent16cc5bfe1891e762c9e70fdd267b0e46bdb4330b (diff)
parentc4eb4b2e4ed933d00586a227915abae37acf8643 (diff)
Auto merge of #490 - manuel-woelker:master, r=fitzgen
ty: add tests for Type.is_invalid_named_type() (#460) I didn't add an extra test module, since I couldn't find any precedents in the project. Feedback welcome!
-rw-r--r--src/ir/ty.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index 5903430c..f1e43983 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -392,6 +392,51 @@ impl Type {
}
}
}
+#[test]
+fn is_invalid_named_type_valid() {
+ let ty = Type::new(Some("foo".into()), None, TypeKind::Named, false);
+ assert!(!ty.is_invalid_named_type())
+}
+
+#[test]
+fn is_invalid_named_type_valid_underscore_and_numbers() {
+ let ty =
+ Type::new(Some("_foo123456789_".into()), None, TypeKind::Named, false);
+ assert!(!ty.is_invalid_named_type())
+}
+
+#[test]
+fn is_invalid_named_type_valid_unnamed_kind() {
+ let ty = Type::new(Some("foo".into()), None, TypeKind::Void, false);
+ assert!(!ty.is_invalid_named_type())
+}
+
+#[test]
+fn is_invalid_named_type_invalid_start() {
+ let ty = Type::new(Some("1foo".into()), None, TypeKind::Named, false);
+ assert!(ty.is_invalid_named_type())
+}
+
+#[test]
+fn is_invalid_named_type_invalid_remaing() {
+ let ty = Type::new(Some("foo-".into()), None, TypeKind::Named, false);
+ assert!(ty.is_invalid_named_type())
+}
+
+#[test]
+#[should_panic]
+fn is_invalid_named_type_unnamed() {
+ let ty = Type::new(None, None, TypeKind::Named, false);
+ assert!(ty.is_invalid_named_type())
+}
+
+#[test]
+#[should_panic]
+fn is_invalid_named_type_empty_name() {
+ let ty = Type::new(Some("".into()), None, TypeKind::Named, false);
+ assert!(ty.is_invalid_named_type())
+}
+
impl CanDeriveDebug for Type {
type Extra = ();