mod inheritance;
mod mode_compatibility;
mod operations;
use crate::test_helpers::*;
use slicec::diagnostics::{Diagnostic, Error};
use slicec::grammar::*;
#[test]
fn can_have_no_operations() {
let slice = "
module Test
interface I {}
";
let ast = parse_for_ast(slice);
let interface_def = ast.find_element::<Interface>("Test::I").unwrap();
assert_eq!(interface_def.identifier(), "I");
assert_eq!(interface_def.operations().len(), 0);
}
#[test]
fn can_have_one_operation() {
let slice = "
module Test
interface I {
op1()
}
";
let ast = parse_for_ast(slice);
let interface_def = ast.find_element::<Interface>("Test::I").unwrap();
assert_eq!(interface_def.operations().len(), 1);
}
#[test]
fn can_have_multiple_operation() {
let slice = "
module Test
interface I {
op1()
op2()
op3()
}
";
let ast = parse_for_ast(slice);
let interface_def = ast.find_element::<Interface>("Test::I").unwrap();
assert_eq!(interface_def.operations().len(), 3);
}
#[test]
fn cannot_redefine_operations() {
let slice = "
mode = Slice1
module Test
interface I {
op()
op()
}
";
let diagnostics = parse_for_diagnostics(slice);
let expected = Diagnostic::new(Error::Redefinition {
identifier: "op".to_owned(),
})
.add_note("'op' was previously defined here", None);
check_diagnostics(diagnostics, [expected]);
}