From 7c6bdd87813f4a6218453ddb9921ff5de0b2ff7e Mon Sep 17 00:00:00 2001
From: Pieter12345
Date: Thu, 28 Mar 2024 04:18:36 +0100
Subject: [PATCH] Add FQCN typing tests
---
.../core/MethodScriptCompilerTest.java | 52 +++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/src/test/java/com/laytonsmith/core/MethodScriptCompilerTest.java b/src/test/java/com/laytonsmith/core/MethodScriptCompilerTest.java
index 0cbac8bd7..3ba90f9ae 100644
--- a/src/test/java/com/laytonsmith/core/MethodScriptCompilerTest.java
+++ b/src/test/java/com/laytonsmith/core/MethodScriptCompilerTest.java
@@ -1378,4 +1378,56 @@ proc _d() {}
Collections.sort(names);
assertEquals(Arrays.asList("_a", "_b", "_c", "_d", "_e"), names);
}
+
+ @Test
+ public void testFQCNTypingCompiles() throws Exception {
+ String script = """
+ ms.lang.string @a = 'test';
+ ms.lang.array @b;
+ try {} catch (ms.lang.Exception @ex) {}
+ proc _a(ms.lang.int @c) {}
+ """;
+ Environment env = Static.GenerateStandaloneEnvironment();
+ StaticAnalysis sa = new StaticAnalysis(true);
+ sa.setLocalEnable(true);
+ MethodScriptCompiler.compile(MethodScriptCompiler.lex(script, env, null, true), env, env.getEnvClasses(), sa);
+ }
+
+ @Test
+ public void testFQCNTypingCompilesStrict() throws Exception {
+ String script = """
+
+ ms.lang.string @a = 'test';
+ ms.lang.array @b;
+ try {} catch (ms.lang.Exception @ex) {}
+ proc _a(ms.lang.int @c) {}
+ """;
+ Environment env = Static.GenerateStandaloneEnvironment();
+ StaticAnalysis sa = new StaticAnalysis(true);
+ sa.setLocalEnable(true);
+ MethodScriptCompiler.compile(MethodScriptCompiler.lex(script, env, null, true), env, env.getEnvClasses(), sa);
+ }
+
+ @Test(expected = ConfigCompileException.class)
+ public void testInvalidFQCNTypingCompileFails() throws Exception {
+ String script = """
+ ms.lang.invalidtype @a = null;
+ """;
+ Environment env = Static.GenerateStandaloneEnvironment();
+ StaticAnalysis sa = new StaticAnalysis(true);
+ sa.setLocalEnable(true);
+ MethodScriptCompiler.compile(MethodScriptCompiler.lex(script, env, null, true), env, env.getEnvClasses(), sa);
+ }
+
+ @Test(expected = ConfigCompileException.class)
+ public void testInvalidFQCNTypingCompileFailsStrict() throws Exception {
+ String script = """
+
+ ms.lang.invalidtype @a = null;
+ """;
+ Environment env = Static.GenerateStandaloneEnvironment();
+ StaticAnalysis sa = new StaticAnalysis(true);
+ sa.setLocalEnable(true);
+ MethodScriptCompiler.compile(MethodScriptCompiler.lex(script, env, null, true), env, env.getEnvClasses(), sa);
+ }
}