mod slice1 {
use crate::test_helpers::*;
use slicec::diagnostics::{Diagnostic, Error};
use slicec::grammar::CompilationMode;
use test_case::test_case;
#[test_case("int8"; "int8")]
#[test_case("uint16"; "uint16")]
#[test_case("uint32"; "uint32")]
#[test_case("varint32"; "varint32")]
#[test_case("varuint32"; "varuint32")]
#[test_case("uint64"; "uint64")]
#[test_case("varint62"; "varint62")]
#[test_case("varuint62"; "varuint62")]
fn unsupported_types_fail(value: &str) {
let slice = &format!(
"
mode = Slice1
module Test
compact struct S {{
v: {value}
}}
"
);
let diagnostics = parse_for_diagnostics(slice);
let expected = Diagnostic::new(Error::UnsupportedType {
kind: value.to_owned(),
mode: CompilationMode::Slice1,
});
check_diagnostics(diagnostics, [expected]);
}
#[test_case("bool"; "bool")]
#[test_case("uint8"; "uint8")]
#[test_case("int16"; "int16")]
#[test_case("int32"; "int32")]
#[test_case("int64"; "int64")]
#[test_case("float32"; "float32")]
#[test_case("float64"; "float64")]
#[test_case("string"; "string")]
#[test_case("AnyClass"; "AnyClass")]
fn supported_types_succeed(value: &str) {
let slice = &format!(
"
mode = Slice1
module Test
compact struct S {{
v: {value}
}}
"
);
assert_parses(slice);
}
}
mod slice2 {
use crate::test_helpers::*;
use slicec::diagnostics::{Diagnostic, Error};
use slicec::grammar::CompilationMode;
use test_case::test_case;
#[test]
fn unsupported_types_fail() {
let slice = "
module Test
compact struct S {
v: AnyClass
}
";
let diagnostics = parse_for_diagnostics(slice);
let expected = Diagnostic::new(Error::UnsupportedType {
kind: "AnyClass".to_owned(),
mode: CompilationMode::Slice2,
})
.add_note("this file's compilation mode is Slice2 by default", None);
check_diagnostics(diagnostics, [expected]);
}
#[test_case("bool"; "bool")]
#[test_case("int8"; "int8")]
#[test_case("uint8"; "uint8")]
#[test_case("int16"; "int16")]
#[test_case("uint16"; "uint16")]
#[test_case("int32"; "int32")]
#[test_case("uint32"; "uint32")]
#[test_case("varint32"; "varint32")]
#[test_case("varuint32"; "varuint32")]
#[test_case("int64"; "int64")]
#[test_case("uint64"; "uint64")]
#[test_case("varint62"; "varint62")]
#[test_case("varuint62"; "varuint62")]
#[test_case("float32"; "float32")]
#[test_case("float64"; "float64")]
#[test_case("string"; "string")]
fn supported_types_succeed(value: &str) {
let slice = format!(
"
module Test
compact struct S {{
v: {value}
}}"
);
assert_parses(slice);
}
}