Fix tests and comment some out

This commit is contained in:
Jeff 2024-06-18 22:03:41 -04:00
parent 7dc62bfd5f
commit ccdcc7c791
2 changed files with 117 additions and 116 deletions

View File

@ -1,120 +1,121 @@
use dust_lang::{ // Reuse these tests when structures are reimplemented
abstract_tree::{Type, WithPos}, // use dust_lang::{
error::{DustError, TypeConflict, ValidationError}, // abstract_tree::{Type, WithPos},
identifier::Identifier, // error::{DustError, TypeConflict, ValidationError},
interpret, Value, // identifier::Identifier,
}; // interpret, Value,
// };
#[test] // #[test]
fn simple_structure() { // fn simple_structure() {
assert_eq!( // assert_eq!(
interpret( // interpret(
"test", // "test",
" // "
struct Foo { // struct Foo {
bar : int, // bar : int,
baz : str, // baz : str,
} // }
Foo { // Foo {
bar = 42, // bar = 42,
baz = 'hiya', // baz = 'hiya',
} // }
" // "
), // ),
Ok(Some(Value::structure( // Ok(Some(Value::structure(
Identifier::new("Foo").with_position((127, 130)), // Identifier::new("Foo").with_position((127, 130)),
vec![ // vec![
(Identifier::new("bar"), Value::integer(42)), // (Identifier::new("bar"), Value::integer(42)),
(Identifier::new("baz"), Value::string("hiya".to_string())), // (Identifier::new("baz"), Value::string("hiya".to_string())),
] // ]
))) // )))
) // )
} // }
#[test] // #[test]
fn field_type_error() { // fn field_type_error() {
assert_eq!( // assert_eq!(
interpret( // interpret(
"test", // "test",
" // "
struct Foo { // struct Foo {
bar : int, // bar : int,
} // }
Foo { // Foo {
bar = 'hiya', // bar = 'hiya',
} // }
" // "
) // )
.unwrap_err() // .unwrap_err()
.errors(), // .errors(),
&vec![DustError::Validation { // &vec![DustError::Validation {
error: ValidationError::TypeCheck { // error: ValidationError::TypeCheck {
conflict: TypeConflict { // conflict: TypeConflict {
actual: Type::String, // actual: Type::String,
expected: Type::Integer // expected: Type::Integer
}, // },
actual_position: (128, 134).into(), // actual_position: (128, 134).into(),
expected_position: Some((56, 59).into()), // expected_position: Some((56, 59).into()),
}, // },
position: (96, 153).into() // position: (96, 153).into()
}] // }]
) // )
} // }
#[test] // #[test]
fn nested_structure() { // fn nested_structure() {
assert_eq!( // assert_eq!(
interpret( // interpret(
"test", // "test",
" // "
struct Bar { // struct Bar {
baz : int // baz : int
} // }
struct Foo { // struct Foo {
bar : Bar // bar : Bar
} // }
Foo { // Foo {
bar = Bar { // bar = Bar {
baz = 42 // baz = 42
} // }
} // }
" // "
), // ),
Ok(Some(Value::structure( // Ok(Some(Value::structure(
Identifier::new("Foo").with_position((172, 175)), // Identifier::new("Foo").with_position((172, 175)),
vec![( // vec![(
Identifier::new("bar"), // Identifier::new("bar"),
Value::structure( // Value::structure(
Identifier::new("Bar").with_position((204, 207)), // Identifier::new("Bar").with_position((204, 207)),
vec![(Identifier::new("baz"), Value::integer(42))] // vec![(Identifier::new("baz"), Value::integer(42))]
) // )
),] // ),]
))) // )))
) // )
} // }
#[test] // #[test]
fn undefined_struct() { // fn undefined_struct() {
assert_eq!( // assert_eq!(
interpret( // interpret(
"test", // "test",
" // "
Foo { // Foo {
bar = 42 // bar = 42
} // }
" // "
) // )
.unwrap_err() // .unwrap_err()
.errors(), // .errors(),
&vec![DustError::Validation { // &vec![DustError::Validation {
error: ValidationError::VariableNotFound { // error: ValidationError::VariableNotFound {
identifier: Identifier::new("Foo"), // identifier: Identifier::new("Foo"),
position: (17, 20).into() // position: (17, 20).into()
}, // },
position: (17, 69).into() // position: (17, 69).into()
}] // }]
) // )
} // }

View File

@ -44,13 +44,13 @@ fn set_variable_with_type_error() {
#[test] #[test]
fn function_variable() { fn function_variable() {
assert_eq!( assert_eq!(
interpret("test", "foobar = fn (x: int) int { x }; foobar"), interpret("test", "foobar = fn (x: int) -> int { x }; foobar"),
Ok(Some(Value::function( Ok(Some(Value::function(
Some(Vec::with_capacity(0)), None,
vec![(Identifier::new("x"), Type::Integer)], vec![(Identifier::new("x"), Type::Integer)],
Type::Integer, Type::Integer,
Block::new(vec![Statement::Expression(Expression::Identifier( Block::new(vec![Statement::Expression(Expression::Identifier(
Identifier::new("x").with_position((27, 28)) Identifier::new("x").with_position((30, 31))
))]) ))])
))) )))
); );