2024-12-03 20:26:05 +00:00
|
|
|
use dust_lang::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn divide_boolean_left() {
|
|
|
|
let source = "true / 1";
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2024-12-04 18:31:02 +00:00
|
|
|
Err(CreateReport::Compile {
|
2024-12-03 20:26:05 +00:00
|
|
|
error: CompileError::CannotDivideType {
|
|
|
|
argument_type: Type::Boolean,
|
|
|
|
position: Span(0, 4)
|
|
|
|
},
|
|
|
|
source,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn divide_boolean_right() {
|
|
|
|
let source = "1 / true";
|
2024-12-03 21:03:23 +00:00
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2024-12-04 18:31:02 +00:00
|
|
|
Err(CreateReport::Compile {
|
2024-12-03 21:03:23 +00:00
|
|
|
error: CompileError::CannotDivideType {
|
|
|
|
argument_type: Type::Boolean,
|
|
|
|
position: Span(4, 8)
|
|
|
|
},
|
|
|
|
source,
|
|
|
|
})
|
|
|
|
);
|
2024-12-03 20:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn divide_character_left() {
|
|
|
|
let source = "'a' / 1";
|
2024-12-03 21:03:23 +00:00
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2024-12-04 18:31:02 +00:00
|
|
|
Err(CreateReport::Compile {
|
2024-12-03 21:03:23 +00:00
|
|
|
error: CompileError::CannotDivideType {
|
|
|
|
argument_type: Type::Character,
|
|
|
|
position: Span(0, 3)
|
|
|
|
},
|
|
|
|
source,
|
|
|
|
})
|
|
|
|
);
|
2024-12-03 20:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn divide_character_right() {
|
|
|
|
let source = "1 / 'a'";
|
2024-12-03 21:03:23 +00:00
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2024-12-04 18:31:02 +00:00
|
|
|
Err(CreateReport::Compile {
|
2024-12-03 21:03:23 +00:00
|
|
|
error: CompileError::CannotDivideType {
|
|
|
|
argument_type: Type::Character,
|
|
|
|
position: Span(4, 7)
|
|
|
|
},
|
|
|
|
source,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn divide_float_and_character() {
|
|
|
|
let source = "1.0 / 'a'";
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2024-12-04 18:31:02 +00:00
|
|
|
Err(CreateReport::Compile {
|
2024-12-03 21:03:23 +00:00
|
|
|
error: CompileError::CannotDivideType {
|
|
|
|
argument_type: Type::Character,
|
|
|
|
position: Span(6, 9)
|
|
|
|
},
|
|
|
|
source,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn divide_float_and_integer() {
|
|
|
|
let source = "1.0 / 1";
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2024-12-04 18:31:02 +00:00
|
|
|
Err(CreateReport::Compile {
|
2024-12-03 21:03:23 +00:00
|
|
|
error: CompileError::CannotDivideArguments {
|
|
|
|
left_type: Type::Float,
|
|
|
|
right_type: Type::Integer,
|
|
|
|
position: Span(0, 7)
|
|
|
|
},
|
|
|
|
source,
|
|
|
|
})
|
|
|
|
);
|
2024-12-03 20:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn divide_function_left() {
|
|
|
|
let source = "fn(){} / 1";
|
2024-12-03 21:03:23 +00:00
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2024-12-04 18:31:02 +00:00
|
|
|
Err(CreateReport::Compile {
|
2024-12-03 21:03:23 +00:00
|
|
|
error: CompileError::CannotDivideType {
|
|
|
|
argument_type: Type::Function(FunctionType {
|
|
|
|
type_parameters: None,
|
|
|
|
value_parameters: None,
|
|
|
|
return_type: Box::new(Type::None)
|
|
|
|
}),
|
|
|
|
position: Span(0, 6)
|
|
|
|
},
|
|
|
|
source,
|
|
|
|
})
|
|
|
|
);
|
2024-12-03 20:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn divide_function_right() {
|
|
|
|
let source = "1 / fn(){}";
|
2024-12-03 21:03:23 +00:00
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2024-12-04 18:31:02 +00:00
|
|
|
Err(CreateReport::Compile {
|
2024-12-03 21:03:23 +00:00
|
|
|
error: CompileError::CannotDivideType {
|
|
|
|
argument_type: Type::Function(FunctionType {
|
|
|
|
type_parameters: None,
|
|
|
|
value_parameters: None,
|
|
|
|
return_type: Box::new(Type::None)
|
|
|
|
}),
|
|
|
|
position: Span(4, 10)
|
|
|
|
},
|
|
|
|
source,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn divide_integer_and_float() {
|
|
|
|
let source = "1 / 1.0";
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2024-12-04 18:31:02 +00:00
|
|
|
Err(CreateReport::Compile {
|
2024-12-03 21:03:23 +00:00
|
|
|
error: CompileError::CannotDivideArguments {
|
|
|
|
left_type: Type::Integer,
|
|
|
|
right_type: Type::Float,
|
|
|
|
position: Span(0, 7)
|
|
|
|
},
|
|
|
|
source,
|
|
|
|
})
|
|
|
|
);
|
2024-12-03 20:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn divide_list_left() {
|
|
|
|
let source = "[1, 2] / 1";
|
2024-12-03 21:03:23 +00:00
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2024-12-04 18:31:02 +00:00
|
|
|
Err(CreateReport::Compile {
|
2024-12-03 21:03:23 +00:00
|
|
|
error: CompileError::CannotDivideType {
|
|
|
|
argument_type: Type::List(Box::new(Type::Integer)),
|
|
|
|
position: Span(0, 6)
|
|
|
|
},
|
|
|
|
source,
|
|
|
|
})
|
|
|
|
);
|
2024-12-03 20:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn divide_list_right() {
|
|
|
|
let source = "1 / [1, 2]";
|
2024-12-03 21:03:23 +00:00
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2024-12-04 18:31:02 +00:00
|
|
|
Err(CreateReport::Compile {
|
2024-12-03 21:03:23 +00:00
|
|
|
error: CompileError::CannotDivideType {
|
|
|
|
argument_type: Type::List(Box::new(Type::Integer)),
|
|
|
|
position: Span(4, 10)
|
|
|
|
},
|
|
|
|
source,
|
|
|
|
})
|
|
|
|
);
|
2024-12-03 20:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// #[test]
|
|
|
|
// fn add_range_left() {
|
|
|
|
// todo!("Add ranges")
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #[test]
|
|
|
|
// fn add_range_right() {
|
|
|
|
// todo!("Add ranges")
|
|
|
|
// }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn divide_string_left() {
|
|
|
|
let source = "\"hello\" / 1";
|
2024-12-03 21:03:23 +00:00
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2024-12-04 18:31:02 +00:00
|
|
|
Err(CreateReport::Compile {
|
2024-12-03 21:03:23 +00:00
|
|
|
error: CompileError::CannotDivideType {
|
|
|
|
argument_type: Type::String,
|
|
|
|
position: Span(0, 7)
|
|
|
|
},
|
|
|
|
source,
|
|
|
|
})
|
|
|
|
);
|
2024-12-03 20:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn divide_string_right() {
|
|
|
|
let source = "1 / \"hello\"";
|
|
|
|
|
2024-12-03 21:03:23 +00:00
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2024-12-04 18:31:02 +00:00
|
|
|
Err(CreateReport::Compile {
|
2024-12-03 21:03:23 +00:00
|
|
|
error: CompileError::CannotDivideType {
|
|
|
|
argument_type: Type::String,
|
|
|
|
position: Span(4, 11)
|
|
|
|
},
|
|
|
|
source,
|
|
|
|
})
|
|
|
|
);
|
2024-12-03 20:26:05 +00:00
|
|
|
}
|