mod test_helpers;
use crate::test_helpers::*;
use slicec::diagnostics::{Diagnostic, Error};
use slicec::grammar::{CustomType, Interface, Struct};
#[test]
fn escaped_keywords() {
let slice = r#"
module \module
interface \interface {}
struct \struct {}
custom \custom
"#;
let ast = parse_for_ast(slice);
assert!(ast.find_element::<Interface>("module::interface").is_ok());
assert!(ast.find_element::<Struct>("module::struct").is_ok());
assert!(ast.find_element::<CustomType>("module::custom").is_ok());
}
#[test]
fn escaped_identifiers() {
let slice = r#"
module \MyModule
interface \MyInterface {}
struct \MyStruct {}
custom \MyCustom
"#;
let ast = parse_for_ast(slice);
assert!(ast.find_element::<Interface>("MyModule::MyInterface").is_ok());
assert!(ast.find_element::<Struct>("MyModule::MyStruct").is_ok());
assert!(ast.find_element::<CustomType>("MyModule::MyCustom").is_ok());
}
#[test]
fn must_start_with_a_letter() {
let slice = "module _foo";
let diagnostics = parse_for_diagnostics(slice);
let expected = Diagnostic::new(Error::Syntax {
message: "unknown symbol '_'".to_owned(),
});
check_diagnostics(diagnostics, [expected]);
}
#[test]
fn escaped_scoped_identifiers_containing_keywords() {
let slice = r#"
module Foo
struct \module {}
struct BarStruct {
s: Foo::\module
}
"#;
let ast = parse_for_ast(slice);
assert!(ast.find_element::<Struct>("Foo::module").is_ok());
}
#[test]
fn must_be_ascii_alphanumeric_characters() {
let slice = "module ð’…‹";
let diagnostics = parse_for_diagnostics(slice);
let expected = Diagnostic::new(Error::Syntax {
message: "unknown symbol 'ð’…‹'".to_owned(),
});
check_diagnostics(diagnostics, [expected]);
}