Skip to content

Commit

Permalink
Add FQCN typing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pieter12345 committed Mar 28, 2024
1 parent 0211c57 commit 7c6bdd8
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/test/java/com/laytonsmith/core/MethodScriptCompilerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
<!strict>
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 = """
<!strict>
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);
}
}

0 comments on commit 7c6bdd8

Please sign in to comment.